mirror of
https://github.com/BigBodyCobain/Shadowbroker.git
synced 2026-12-05 17:13:45 +01:00
Merge pull request #1 from esmaeelE/mr/osm-interactive
feat(osm): add OSM basemap style to map style cycle
This commit is contained in:
6 files changed
+79
-10
No files matched your search
@@ -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() {
|
||||
<ErrorBoundary name="Map">
|
||||
<MaplibreViewer
|
||||
activeLayers={firstPaintActiveLayers}
|
||||
activeStyle={activeStyle}
|
||||
activeFilters={activeFilters}
|
||||
effects={memoizedEffects}
|
||||
onEntityClick={setSelectedEntity}
|
||||
|
||||
@@ -20,8 +20,12 @@ import {
|
||||
CARTO_ATTRIBUTION_HTML,
|
||||
OPENFREEMAP_ATTRIBUTION_HTML,
|
||||
OSM_ATTRIBUTION_HTML,
|
||||
darkStyle,
|
||||
lightStyle,
|
||||
osmTiles,
|
||||
} from '@/components/map/styles/mapStyles';
|
||||
import { useBasemapConfig } from '@/hooks/useBasemapConfig';
|
||||
|
||||
import maplibregl from 'maplibre-gl';
|
||||
import { AlertTriangle, Radio, Activity, Play, Satellite, ExternalLink, Info } from 'lucide-react';
|
||||
import WikiImage from '@/components/WikiImage';
|
||||
@@ -388,6 +392,7 @@ function buildPolymarketUrl(prediction: { slug?: string; title?: string } | null
|
||||
|
||||
const MaplibreViewer = ({
|
||||
activeLayers,
|
||||
activeStyle,
|
||||
activeFilters,
|
||||
onEntityClick,
|
||||
flyToLocation,
|
||||
@@ -437,8 +442,8 @@ const MaplibreViewer = ({
|
||||
const { theme } = useTheme();
|
||||
const { cartoApiKey, loaded: basemapConfigLoaded } = useBasemapConfig();
|
||||
const mapThemeStyle = useMemo<maplibregl.StyleSpecification | string>(
|
||||
() => buildBasemapStyle(theme === 'light' ? 'light' : 'dark', cartoApiKey),
|
||||
[theme, cartoApiKey],
|
||||
() => buildBasemapStyle(theme === 'light' ? 'light' : 'dark', cartoApiKey, activeStyle),
|
||||
[theme, cartoApiKey, activeStyle],
|
||||
);
|
||||
|
||||
const initialViewState = useMemo<ViewState>(
|
||||
@@ -2058,6 +2063,27 @@ const MaplibreViewer = ({
|
||||
</Source>
|
||||
)}
|
||||
|
||||
{/* OpenStreetMap standard raster tiles — selectable basemap */}
|
||||
{false && (
|
||||
<Source
|
||||
id="osm-standard"
|
||||
type="raster"
|
||||
tiles={osmTiles.tiles}
|
||||
tileSize={osmTiles.tileSize}
|
||||
maxzoom={osmTiles.maxzoom}
|
||||
attribution={osmTiles.attribution}
|
||||
>
|
||||
<Layer
|
||||
id="osm-standard-layer"
|
||||
type="raster"
|
||||
paint={{
|
||||
'raster-opacity': 1,
|
||||
'raster-fade-duration': 300,
|
||||
}}
|
||||
/>
|
||||
</Source>
|
||||
)}
|
||||
|
||||
{/* NASA GIBS MODIS Terra — daily satellite imagery overlay */}
|
||||
{activeLayers.gibs_imagery && gibsDate && (
|
||||
<Source
|
||||
|
||||
@@ -43,6 +43,7 @@ import {
|
||||
Droplets,
|
||||
Radar,
|
||||
MapPin,
|
||||
Map,
|
||||
Truck,
|
||||
RefreshCw,
|
||||
} from 'lucide-react';
|
||||
@@ -700,6 +701,7 @@ function SdrTracker({
|
||||
const TOGGLE_ALL_EXCLUDED_LAYERS = new Set<string>([
|
||||
'gibs_imagery',
|
||||
'highres_satellite',
|
||||
'osm_basemap',
|
||||
'sentinel_hub',
|
||||
'viirs_nightlights',
|
||||
'road_corridor_trends',
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
@@ -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,
|
||||
|
||||
@@ -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<string, string[]>;
|
||||
effects?: MapEffects;
|
||||
onEntityClick: (entity: SelectedEntity | null) => void;
|
||||
|
||||
Reference in new issue
Block a user