From f8656bcff4e66bd35e79fe93741333cc0c40e4a2 Mon Sep 17 00:00:00 2001 From: maltaesousa Date: Mon, 7 Oct 2024 15:48:48 +0200 Subject: [PATCH] make it possible to customize openlayers --- .gitignore | 1 - README.md | 4 ---- api/admin.py | 9 +++------ api/models.py | 2 +- api/templates/gis/admin/custom.html | 2 -- default_settings.py | 26 ++++++++++++++++++++++++-- pyproject.toml | 1 + 7 files changed, 29 insertions(+), 16 deletions(-) delete mode 100644 api/templates/gis/admin/custom.html diff --git a/.gitignore b/.gitignore index e3ce1dc4..259eada3 100644 --- a/.gitignore +++ b/.gitignore @@ -96,7 +96,6 @@ venv # customized project files settings.py -api/templates/gis/admin/custom.js # collected static files static/* diff --git a/README.md b/README.md index 952167c1..6e55704f 100644 --- a/README.md +++ b/README.md @@ -87,10 +87,6 @@ python manage.py runserver python manage.py test ``` -## Customize - -custom.js in `api/templates/gis/admin` - # OIDC authentication ## Glossary diff --git a/api/admin.py b/api/admin.py index 51aa2512..4dd29c7a 100644 --- a/api/admin.py +++ b/api/admin.py @@ -9,6 +9,7 @@ from django.contrib.gis import admin from django.http import HttpResponseRedirect from django.utils.translation import gettext_lazy as _ +from django_extended_ol.forms.widgets import WMTSWidget from .helpers import send_geoshop_email from .models import ( @@ -40,13 +41,9 @@ class Media: class CustomGeoModelAdmin(CustomModelAdmin): """ - Custom widget for the admin if a custom js is provided - TODO: deprecated in 5.0 + Custom widget for the admin """ - current_dir = os.path.dirname(os.path.realpath(__file__)) - if Path(f'{current_dir}/templates/gis/admin/custom.js').is_file(): - map_template = 'gis/admin/custom.html' - map_srid = 2056 + gis_widget = WMTSWidget class DocumentAdmin(CustomModelAdmin): diff --git a/api/models.py b/api/models.py index d8880c70..80a4f1f8 100644 --- a/api/models.py +++ b/api/models.py @@ -482,7 +482,7 @@ class ProductStatus(models.TextChoices): default=settings.DEFAULT_PRODUCT_THUMBNAIL_URL, ) ts = SearchVectorField(null=True) - bbox = settings.SWISS_EXTENT + bbox = settings.DEFAULT_EXTENT geom = models.MultiPolygonField( _("geom"), srid=settings.DEFAULT_SRID, diff --git a/api/templates/gis/admin/custom.html b/api/templates/gis/admin/custom.html deleted file mode 100644 index 27e8cff8..00000000 --- a/api/templates/gis/admin/custom.html +++ /dev/null @@ -1,2 +0,0 @@ -{% extends "gis/admin/openlayers.html" %} -{% block openlayers %}{% include "gis/admin/custom.js" %}{% endblock %} \ No newline at end of file diff --git a/default_settings.py b/default_settings.py index 62f85aa7..ac275884 100644 --- a/default_settings.py +++ b/default_settings.py @@ -58,6 +58,7 @@ 'health_check', 'health_check.db', 'health_check.contrib.migrations', + 'django_extended_ol', ] MIDDLEWARE = [ @@ -266,9 +267,8 @@ # FIXME: Does this work with another SRID? DEFAULT_SRID = int(os.environ.get('DEFAULT_SRID', '2056')) -# Default Extent # default extent is set to the BBOX of switzerland -SWISS_EXTENT = (2828694.200665463,1075126.8548189853,2484749.5514877755,1299777.3195268118) +DEFAULT_EXTENT = (2828694.200665463,1075126.8548189853,2484749.5514877755,1299777.3195268118) # Controls values of metadata accessibility field that will turn the metadata public METADATA_PUBLIC_ACCESSIBILITIES = ['PUBLIC', 'APPROVAL_NEEDED'] @@ -345,3 +345,25 @@ def check_oidc() -> bool: LOGIN_REDIRECT_URL = os.environ.get("OIDC_REDIRECT_BASE_URL") + "/oidc/callback" LOGOUT_REDIRECT_URL = os.environ.get("OIDC_REDIRECT_BASE_URL") + "/" LOGIN_URL = os.environ.get("OIDC_REDIRECT_BASE_URL") + "/oidc/authenticate" + +# Customize openlayers widget used in admin interface +OLWIDGET = { + "globals": { + "srid": DEFAULT_SRID, + "extent": [2420000, 130000, 2900000, 1350000], + "resolutions": [ + 4000, 3750, 3500, 3250, 3000, 2750, 2500, 2250, 2000, 1750, 1500, 1250, + 1000, 750, 650, 500, 250, 100, 50, 20, 10, 5, 2.5, 2, 1.5, 1, 0.5 + ], + }, + "wmts": { + "layer_name": 'ch.kantone.cadastralwebmap-farbe', + "style": 'default', + "matrix_set": '2056', + "attributions": 'swisstopo', # optional + "url_template": 'https://wmts10.geo.admin.ch/1.0.0/{Layer}/default/current/2056/{TileMatrix}/{TileCol}/{TileRow}.png', + "request_encoding": 'REST', # optional + "format": 'image/png' # optional + } +} \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index f4e7aff8..4e19da15 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,6 +52,7 @@ whitenoise = "^6.7.0" Django = "^5.1" mozilla-django-oidc = "^4.0.1" Authlib = "^1.3.2" +django-extended-ol = "1.0.0" [build-system] requires = ["poetry-core>=1.6.0"]