Skip to content

Commit

Permalink
add titiler in map attributions (#1030)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago authored Nov 14, 2024
1 parent 7a4b688 commit 5e0287c
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 26 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
38 changes: 19 additions & 19 deletions src/titiler/application/titiler/application/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))


###############################################################################
Expand All @@ -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,
)

###############################################################################
Expand Down

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/titiler/core/titiler/core/templates/map.html
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<a href="https://leafletjs.com" target="_blank">Leaflet</a> | <a href="https://developmentseed.org/titiler" target="_blank">Titiler</a>'}).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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<a href="http://www.openstreetmap.org/copyright">© OpenStreetMap</a>'
attribution: '<a href="https://developmentseed.org/titiler" target="_blank">Titiler</a> | <a href="http://www.openstreetmap.org/copyright">© OpenStreetMap</a>'
}
},
layers: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<a href="http://www.openstreetmap.org/copyright">© OpenStreetMap</a>'
attribution: '<a href="https://developmentseed.org/titiler" target="_blank">Titiler</a> | <a href="http://www.openstreetmap.org/copyright">© OpenStreetMap</a>'
}
},
layers: [
Expand Down

0 comments on commit 5e0287c

Please sign in to comment.