Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 42 additions & 5 deletions python/fusion_engine_client/analysis/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,22 @@ def _data_to_table(col_titles: List[str], values: List[List[Any]], row_major: bo
return table_html.replace('\n', '')


def _build_map_style(mapbox_token: Optional[str]):
def _build_map_style(mapbox_token: Optional[str]) -> dict:
"""!
@brief Build a `layout.map.style` value for a MapLibre-based Scattermap figure.

If a Mapbox access token is available, pull Mapbox's rendered `satellite-streets-v12` tiles (imagery with street
labels composited on top) via a custom raster style spec, the mechanism MapLibre-based maps use in place of the
old `layout.mapbox.accesstoken` field, which no longer exists. Otherwise, fall back to Plotly's built-in
token-free `satellite-streets` style, which serves ESRI World Imagery aerial tiles (max zoom 16, lower resolution
than Mapbox) with OpenMapTiles street labels drawn on top.
old `layout.mapbox.accesstoken` field, which no longer exists. Otherwise, fall back to token-free ESRI World
Imagery tiles (lower resolution than Mapbox), with ESRI's transportation (street names) and boundaries and places
reference layers drawn on top.

@param mapbox_token The Mapbox access token, or `None` if none is available.

@return The MapLibre style spec.
"""
if not mapbox_token:
return 'satellite-streets'
return _build_esri_map_style()

return {
'version': 8,
Expand All @@ -133,6 +137,39 @@ def _build_map_style(mapbox_token: Optional[str]):
}



def _build_esri_map_style() -> dict:
"""!
@brief Build the token-free ESRI satellite map style used when no Mapbox access token is available.

Each source's `maxzoom` is the highest zoom level that ESRI reliably serves (in the US, at least). Past that
level, MapLibre scales up the last available tiles instead of requesting new ones, so the map stays visible at
any zoom.

@return The MapLibre style spec.
"""
services = [
('esri-imagery', 'World_Imagery'),
('esri-transportation', 'Reference/World_Transportation'),
('esri-places', 'Reference/World_Boundaries_and_Places'),
]
return {
'version': 8,
'sources': {
name: {
'type': 'raster',
'tiles': [
f'https://server.arcgisonline.com/ArcGIS/rest/services/{service}/MapServer/tile/{{z}}/{{y}}/{{x}}'
],
'tileSize': 256,
'maxzoom': 19,
'attribution': '© Esri',
}
for name, service in services
},
'layers': [{'id': f'{name}-layer', 'type': 'raster', 'source': name} for name, _ in services],
}

_page_template = '''\
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
Expand Down
Loading