Skip to content

Commit

Permalink
make it possible to customize openlayers
Browse files Browse the repository at this point in the history
  • Loading branch information
maltaesousa committed Oct 7, 2024
1 parent bed1757 commit f8656bc
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 16 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ venv

# customized project files
settings.py
api/templates/gis/admin/custom.js

# collected static files
static/*
Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ python manage.py runserver
python manage.py test
```

## Customize

custom.js in `api/templates/gis/admin`

# OIDC authentication

## Glossary
Expand Down
9 changes: 3 additions & 6 deletions api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions api/templates/gis/admin/custom.html

This file was deleted.

26 changes: 24 additions & 2 deletions default_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
'health_check',
'health_check.db',
'health_check.contrib.migrations',
'django_extended_ol',
]

MIDDLEWARE = [
Expand Down Expand Up @@ -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']
Expand Down Expand Up @@ -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": '<a target="new" href="https://www.swisstopo.admin.ch/internet/swisstopo/en/home.html"'
+ '>swisstopo</a>', # 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
}
}
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit f8656bc

Please sign in to comment.