From 5e0287c41ae202125067b12f93ad3966317f0533 Mon Sep 17 00:00:00 2001 From: Vincent Sarago Date: Thu, 14 Nov 2024 14:21:09 +0100 Subject: [PATCH] add titiler in map attributions (#1030) --- CHANGES.md | 4 ++ .../application/titiler/application/main.py | 38 +++++++++---------- .../titiler/application/templates/index.html | 5 ++- .../core/titiler/core/templates/map.html | 5 ++- .../extensions/templates/cog_viewer.html | 4 +- .../extensions/templates/stac_viewer.html | 4 +- 6 files changed, 34 insertions(+), 26 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index a07f429e8..ddf5729b4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # Release Notes +## 0.19.1 (2024-11-14) + +* Add `titiler` links in Map attributions + ## 0.19.0 (2024-11-07) ### Misc diff --git a/src/titiler/application/titiler/application/main.py b/src/titiler/application/titiler/application/main.py index 03bafbe79..0d3690d16 100644 --- a/src/titiler/application/titiler/application/main.py +++ b/src/titiler/application/titiler/application/main.py @@ -50,27 +50,27 @@ api_settings = ApiSettings() -############################################################################### -# Setup a global API access key, if configured -api_key_query = APIKeyQuery(name="access_token", auto_error=False) - +app_dependencies = [] +if api_settings.global_access_token: + ############################################################################### + # Setup a global API access key, if configured + api_key_query = APIKeyQuery(name="access_token", auto_error=False) + + def validate_access_token(access_token: str = Security(api_key_query)): + """Validates API key access token, set as the `api_settings.global_access_token` value. + Returns True if no access token is required, or if the access token is valid. + Raises an HTTPException (401) if the access token is required but invalid/missing. + """ + if not access_token: + raise HTTPException(status_code=401, detail="Missing `access_token`") + + # if access_token == `token` then OK + if access_token != api_settings.global_access_token: + raise HTTPException(status_code=401, detail="Invalid `access_token`") -def validate_access_token(access_token: str = Security(api_key_query)): - """Validates API key access token, set as the `api_settings.global_access_token` value. - Returns True if no access token is required, or if the access token is valid. - Raises an HTTPException (401) if the access token is required but invalid/missing. - """ - if api_settings.global_access_token is None: return True - if not access_token: - raise HTTPException(status_code=401, detail="Missing `access_token`") - - # if access_token == `token` then OK - if access_token != api_settings.global_access_token: - raise HTTPException(status_code=401, detail="Invalid `access_token`") - - return True + app_dependencies.append(Depends(validate_access_token)) ############################################################################### @@ -91,7 +91,7 @@ def validate_access_token(access_token: str = Security(api_key_query)): """, version=titiler_version, root_path=api_settings.root_path, - dependencies=[Depends(validate_access_token)], + dependencies=app_dependencies, ) ############################################################################### diff --git a/src/titiler/application/titiler/application/templates/index.html b/src/titiler/application/titiler/application/templates/index.html index d6c013a30..185a57389 100644 --- a/src/titiler/application/titiler/application/templates/index.html +++ b/src/titiler/application/titiler/application/templates/index.html @@ -82,10 +82,11 @@

Links

-
+
Created by +
- Development Seed
diff --git a/src/titiler/core/titiler/core/templates/map.html b/src/titiler/core/titiler/core/templates/map.html index 4a361f98c..8fd5d6e30 100644 --- a/src/titiler/core/titiler/core/templates/map.html +++ b/src/titiler/core/titiler/core/templates/map.html @@ -61,9 +61,12 @@ var map = L.map('map', { crs: crs, minZoom: {{ tms.minzoom }}, - maxZoom: {{ tms.maxzoom }} + maxZoom: {{ tms.maxzoom }}, + attributionControl: false }); +L.control.attribution({prefix: 'Leaflet | Titiler'}).addTo(map) + const nullIsland = L.marker([0, 0]).addTo(map); const madrid = L.marker([40, -3]).addTo(map); const london = L.marker([51.50722, -0.1275]).addTo(map) diff --git a/src/titiler/extensions/titiler/extensions/templates/cog_viewer.html b/src/titiler/extensions/titiler/extensions/templates/cog_viewer.html index e782d5326..04d37554b 100644 --- a/src/titiler/extensions/titiler/extensions/templates/cog_viewer.html +++ b/src/titiler/extensions/titiler/extensions/templates/cog_viewer.html @@ -387,10 +387,10 @@ 'basemap': { type: 'raster', tiles: [ - 'https://tile.openstreetmap.org/{z}/{x}/{y}.png' + 'https://tile.openstreetmap.org/{z}/{x}/{y}.png' ], tileSize: 256, - attribution: '© OpenStreetMap' + attribution: 'Titiler | © OpenStreetMap' } }, layers: [ diff --git a/src/titiler/extensions/titiler/extensions/templates/stac_viewer.html b/src/titiler/extensions/titiler/extensions/templates/stac_viewer.html index e31b9b5c9..d52e8049f 100644 --- a/src/titiler/extensions/titiler/extensions/templates/stac_viewer.html +++ b/src/titiler/extensions/titiler/extensions/templates/stac_viewer.html @@ -362,10 +362,10 @@ 'basemap': { type: 'raster', tiles: [ - 'https://tile.openstreetmap.org/{z}/{x}/{y}.png' + 'https://tile.openstreetmap.org/{z}/{x}/{y}.png' ], tileSize: 256, - attribution: '© OpenStreetMap' + attribution: 'Titiler | © OpenStreetMap' } }, layers: [