From 8b9fae491ed4443861c3762ca9df3c644b82041d Mon Sep 17 00:00:00 2001 From: Adam Shapiro Date: Tue, 1 Dec 2026 11:34:25 -0500 Subject: [PATCH] Use ESRI imagery with street labels and overzoom for the token-free map. Plotly's built-in `satellite-streets` style hides the ESRI layer at zoom 16 and above, and draws its labels from Catalonia-only ICGC tiles. Co-Authored-By: Claude Opus 5.5 --- .../fusion_engine_client/analysis/analyzer.py | 47 +++++++++++++++++-- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/python/fusion_engine_client/analysis/analyzer.py b/python/fusion_engine_client/analysis/analyzer.py index 65b26d03..2a8474ff 100755 --- a/python/fusion_engine_client/analysis/analyzer.py +++ b/python/fusion_engine_client/analysis/analyzer.py @@ -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, @@ -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 = '''\