From 048fe7ad5caf375d1d018a12f01220d6f8cb1155 Mon Sep 17 00:00:00 2001 From: esmaeelE Date: Mon, 2 Nov 2026 11:53:06 +0330 Subject: [PATCH] feat(osm): add OSM basemap style to map style cycle --- frontend/src/app/page.tsx | 16 +++++---- frontend/src/components/MaplibreViewer.tsx | 30 ++++++++++++++-- .../src/components/WorldviewLeftPanel.tsx | 2 ++ .../src/components/map/styles/mapStyles.ts | 36 ++++++++++++++++++- frontend/src/lib/layerPreferences.ts | 3 +- frontend/src/types/dashboard.ts | 2 ++ 6 files changed, 79 insertions(+), 10 deletions(-) diff --git a/frontend/src/app/page.tsx b/frontend/src/app/page.tsx index 5bac2d2e..ea3d05d0 100644 --- a/frontend/src/app/page.tsx +++ b/frontend/src/app/page.tsx @@ -486,14 +486,16 @@ export default function Dashboard() { [], ); - const stylesList = ['DEFAULT', 'SATELLITE']; - const cycleStyle = () => { setActiveStyle((prev) => { - const idx = stylesList.indexOf(prev); - const next = stylesList[(idx + 1) % stylesList.length] as MapStyle; - // Auto-toggle High-Res Satellite layer with SATELLITE style - setActiveLayers((l) => ({ ...l, highres_satellite: next === 'SATELLITE' })); + const order: MapStyle[] = ['DEFAULT', 'SATELLITE', 'OSM']; + const idx = order.indexOf(prev); + const next = order[(idx + 1) % order.length]; + setActiveLayers((l) => ({ + ...l, + highres_satellite: next === 'SATELLITE', + osm_basemap: next === 'OSM', + })); return next; }); }; @@ -508,6 +510,7 @@ export default function Dashboard() { sar: false, gibs_imagery: false, highres_satellite: false, + osm_basemap: false, sentinel_hub: false, viirs_nightlights: false, road_corridor_trends: false, @@ -542,6 +545,7 @@ export default function Dashboard() { ( - () => buildBasemapStyle(theme === 'light' ? 'light' : 'dark', cartoApiKey), - [theme, cartoApiKey], + () => buildBasemapStyle(theme === 'light' ? 'light' : 'dark', cartoApiKey, activeStyle), + [theme, cartoApiKey, activeStyle], ); const initialViewState = useMemo( @@ -2058,6 +2063,27 @@ const MaplibreViewer = ({ )} + {/* OpenStreetMap standard raster tiles — selectable basemap */} + {false && ( + + + + )} + {/* NASA GIBS MODIS Terra — daily satellite imagery overlay */} {activeLayers.gibs_imagery && gibsDate && ( ([ 'gibs_imagery', 'highres_satellite', + 'osm_basemap', 'sentinel_hub', 'viirs_nightlights', 'road_corridor_trends', diff --git a/frontend/src/components/map/styles/mapStyles.ts b/frontend/src/components/map/styles/mapStyles.ts index 56601195..7027361f 100644 --- a/frontend/src/components/map/styles/mapStyles.ts +++ b/frontend/src/components/map/styles/mapStyles.ts @@ -33,7 +33,7 @@ export function cartoTileUrls(theme: BasemapTheme, cartoApiKey: string): string[ const key = cartoApiKey.trim(); return CARTO_SUBDOMAINS.map( (s) => - `https://${s}.basemaps.cartocdn.com/rastertiles/${style}/{z}/{x}/{y}@2x.png?key=${encodeURIComponent(key)}`, + `https://` + s + `.basemaps.cartocdn.com/rastertiles/${style}/{z}/{x}/{y}@2x.png?key=${encodeURIComponent(key)}`, ); } @@ -44,7 +44,32 @@ export function cartoTileUrls(theme: BasemapTheme, cartoApiKey: string): string[ export function buildBasemapStyle( theme: BasemapTheme, cartoApiKey?: string | null, + mapStyle?: string, ): string | StyleSpecification { + if (mapStyle === 'OSM') { + return { + version: 8, + sources: { + osm: { + type: 'raster', + tiles: ['/api/osm-tile/{z}/{x}/{y}.png'], + tileSize: 256, + maxzoom: 19, + attribution: OSM_ATTRIBUTION_HTML, + }, + }, + layers: [ + { + id: 'osm-base', + type: 'raster', + source: 'osm', + minzoom: 0, + maxzoom: 22, + }, + ], + }; + } + const key = (cartoApiKey || '').trim(); if (!key) return OPENFREEMAP_STYLE_URLS[theme]; @@ -65,3 +90,12 @@ export function buildBasemapStyle( export const darkStyle = buildBasemapStyle('dark'); export const lightStyle = buildBasemapStyle('light'); + +/** Standard OpenStreetMap raster tiles — selectable basemap (no API key). + * Proxied through backend to satisfy OSM tile usage policy (Referer header). */ +export const osmTiles = { + tiles: ['/api/osm-tile/{z}/{x}/{y}.png'], + tileSize: 256, + maxzoom: 19, + attribution: OSM_ATTRIBUTION_HTML, +}; diff --git a/frontend/src/lib/layerPreferences.ts b/frontend/src/lib/layerPreferences.ts index 71a3a613..3ab851a3 100644 --- a/frontend/src/lib/layerPreferences.ts +++ b/frontend/src/lib/layerPreferences.ts @@ -6,7 +6,7 @@ export const DASHBOARD_PREFS_STORAGE_KEY = 'sb_dashboard_prefs_v1'; export const DASHBOARD_PREFS_VERSION = 1; export const LAYER_PREFERENCES_CHANGED_EVENT = 'sb:layer-preferences-changed'; -export const MAP_STYLES = ['DEFAULT', 'SATELLITE'] as const; +export const MAP_STYLES = ['DEFAULT', 'SATELLITE', 'OSM'] as const; export type MapStyle = (typeof MAP_STYLES)[number]; export const LAYER_SECTION_IDS = [ @@ -50,6 +50,7 @@ export function getDefaultActiveLayers(): ActiveLayers { satellites: true, gibs_imagery: false, highres_satellite: false, + osm_basemap: false, sentinel_hub: false, viirs_nightlights: false, road_corridor_trends: false, diff --git a/frontend/src/types/dashboard.ts b/frontend/src/types/dashboard.ts index 552250f3..2fbc0135 100644 --- a/frontend/src/types/dashboard.ts +++ b/frontend/src/types/dashboard.ts @@ -1271,6 +1271,7 @@ export interface ActiveLayers { gps_jamming: boolean; gibs_imagery: boolean; highres_satellite: boolean; + osm_basemap: boolean; kiwisdr: boolean; psk_reporter: boolean; satnogs: boolean; @@ -1331,6 +1332,7 @@ export interface MapEffects { export interface MaplibreViewerProps { data: DashboardData; activeLayers: ActiveLayers; + activeStyle?: string; activeFilters?: Record; effects?: MapEffects; onEntityClick: (entity: SelectedEntity | null) => void;