@collabdt/core 0.8.1 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/components/viewers/map/MapViewer.d.ts.map +1 -1
- package/dist/core/components/viewers/map/MapViewer.js +2 -0
- package/dist/core/components/viewers/map/MapViewer.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/index.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/index.js +5 -2
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/index.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/CountryLayer/index.d.ts +5 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/CountryLayer/index.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/CountryLayer/index.js +20 -8
- package/dist/core/components/viewers/map/src/MapLayers/src/CountryLayer/index.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapTilerKeyNotice.d.ts +9 -0
- package/dist/core/components/viewers/map/src/MapTilerKeyNotice.d.ts.map +1 -0
- package/dist/core/components/viewers/map/src/MapTilerKeyNotice.js +53 -0
- package/dist/core/components/viewers/map/src/MapTilerKeyNotice.js.map +1 -0
- package/dist/core/components/viewers/map/utils/mapStyleSpec.d.ts +7 -0
- package/dist/core/components/viewers/map/utils/mapStyleSpec.d.ts.map +1 -1
- package/dist/core/components/viewers/map/utils/mapStyleSpec.js +12 -0
- package/dist/core/components/viewers/map/utils/mapStyleSpec.js.map +1 -1
- package/dist/core/i18n/messages/en.json +2070 -2062
- package/dist/core/i18n/messages/es.json +2067 -2059
- package/dist/core/i18n/messages/fr.json +2067 -2059
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapViewer.d.ts","sourceRoot":"","sources":["../../../../../src/core/components/viewers/map/MapViewer.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"MapViewer.d.ts","sourceRoot":"","sources":["../../../../../src/core/components/viewers/map/MapViewer.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,MAAM,OAAO,CAAA;AAyBzB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAY1D,UAAU,KAAK;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,YAAY,CAAA;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,wBAAgB,SAAS,CAAC,EAAE,KAAc,EAAE,MAAe,EAAE,YAAY,EAAE,WAAW,EAAE,EAAE,KAAK,qBA+L9F"}
|
|
@@ -13,6 +13,7 @@ import SettingsButton from "../../ui/SettingsButton";
|
|
|
13
13
|
import { StatsOverlay } from "../../ui/stats";
|
|
14
14
|
import DatasetManagerMenu from "./datasets/DatasetManager";
|
|
15
15
|
import { MapLayers } from "./src/MapLayers";
|
|
16
|
+
import { MapTilerKeyNotice } from "./src/MapTilerKeyNotice";
|
|
16
17
|
import { MapClickManager } from "./utils/MapEventManager/MapClickManager";
|
|
17
18
|
import { MapHoverManager } from "./utils/MapEventManager/MapHoverManager";
|
|
18
19
|
import { DEFAULT_MAP_STYLE } from "./utils/mapStyleCatalog";
|
|
@@ -152,6 +153,7 @@ function MapViewer({ width = "100%", height = "100%", organization, maptilerKey
|
|
|
152
153
|
/* @__PURE__ */ jsx(MapLayers, { organization, maptilerKey }),
|
|
153
154
|
/* @__PURE__ */ jsxs("div", { className: "absolute bottom-20 md:bottom-[10px] left-3 z-10 flex max-w-[calc(100vw-1.5rem)] flex-col gap-2 pointer-events-none", children: [
|
|
154
155
|
/* @__PURE__ */ jsx("div", { id: "wms-time-slot", style: { display: "contents" } }),
|
|
156
|
+
/* @__PURE__ */ jsx(MapTilerKeyNotice, { maptilerKey }),
|
|
155
157
|
/* @__PURE__ */ jsx(SensorLegend, {}),
|
|
156
158
|
/* @__PURE__ */ jsx(ViewerLegendHost, { viewer: ViewerNames.map }),
|
|
157
159
|
/* @__PURE__ */ jsx(DatasetManagerMenu, {})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/core/components/viewers/map/MapViewer.tsx"],"sourcesContent":["'use client'\r\n\r\n// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport maplibregl from 'maplibre-gl'\r\nimport { useSearchParams } from 'next/navigation'\r\nimport React from 'react'\r\nimport Map, { NavigationControl } from 'react-map-gl/maplibre'\r\n\r\n\r\nimport { PluginMapLayerHost } from '../../../plugins/host/PluginMapLayerHost'\r\nimport { ViewerNames } from '../../../types/dbTypes'\r\nimport { ViewerLegendHost } from '../shared/legends/ViewerLegendHost'\r\nimport { MapContext } from '../../../store'\r\nimport { SensorLegend } from '../../ui/Sensors/SensorLegend'\r\nimport SettingsButton from '../../ui/SettingsButton'\r\nimport { StatsOverlay } from '../../ui/stats'\r\n\r\nimport DatasetManagerMenu from './datasets/DatasetManager'\r\n\r\nimport { MapLayers } from './src/MapLayers'\r\nimport { MapClickManager } from './utils/MapEventManager/MapClickManager'\r\nimport { MapHoverManager } from './utils/MapEventManager/MapHoverManager'\r\nimport { DEFAULT_MAP_STYLE } from './utils/mapStyleCatalog'\r\nimport { resolveStyleSpec } from './utils/mapStyleSpec'\r\nimport { resolveBounds } from './utils/validateBounds'\r\n\r\n\r\n\r\n\r\nimport type { Organization } from '../../../types/dbTypes'\r\nimport type { CurrentLocation } from '../../../types/map'\r\nimport type { MapRef} from 'react-map-gl/maplibre';\r\n\r\nconst CANADA_DEFAULTS = {\r\n zoom: 3,\r\n lat: 56.415,\r\n long: -98.74,\r\n} as const\r\n\r\nconst MAX_GLOBE_ZOOM = 5\r\n\r\ninterface Props {\r\n width?: string\r\n height?: string\r\n organization: Organization\r\n maptilerKey?: string\r\n}\r\n\r\nexport function MapViewer({ width = '100%', height = '100%', organization, maptilerKey }: Props) {\r\n\r\n const searchParams = useSearchParams()\r\n\r\n // Add state to track if map is loaded\r\n const [isMapLoaded, setIsMapLoaded] = React.useState(false)\r\n\r\n const viewState = React.useMemo(() => {\r\n return searchParams.size === 0\r\n ? {\r\n zoom: organization.zoom ?? CANADA_DEFAULTS.zoom,\r\n bearing: organization.bearing ?? 0,\r\n pitch: organization.pitch ?? 0,\r\n longitude: organization.long ?? CANADA_DEFAULTS.long,\r\n latitude: organization.lat ?? CANADA_DEFAULTS.lat,\r\n }\r\n : {\r\n latitude: searchParams.has('lat') ? Number.parseFloat(searchParams.get('lat')) : organization.lat ?? CANADA_DEFAULTS.lat,\r\n longitude: searchParams.has('lng') ? Number.parseFloat(searchParams.get('lng')) : organization.long ?? CANADA_DEFAULTS.long,\r\n bearing: searchParams.has('bearing') ? Number.parseFloat(searchParams.get('bearing')) : organization.bearing ?? 0,\r\n pitch: searchParams.has('pitch') ? Number.parseFloat(searchParams.get('pitch')) : organization.pitch ?? 0,\r\n zoom: searchParams.has('zoom') ? Number.parseFloat(searchParams.get('zoom')) : organization.zoom ?? CANADA_DEFAULTS.zoom,\r\n }\r\n }, [searchParams, organization])\r\n\r\n const initialProjection = viewState.zoom > MAX_GLOBE_ZOOM ? 'mercator' : 'globe'\r\n\r\n // Memoize the inline style object that gets passed to <Map> for a stable prop identity.\r\n const mapContainerStyle = React.useMemo(\r\n () => ({ width, height, backgroundColor: 'black' }),\r\n [width, height],\r\n )\r\n\r\n // Adaptive pixel ratio. A hardcoded 2 doubled fragment-shader cost on 1× DPR\r\n // desktops for zero visual gain; capping at 2 keeps phones (DPR 3-4) effective.\r\n const pixelRatio = React.useMemo(\r\n () => Math.min(typeof window !== 'undefined' ? window.devicePixelRatio : 1, 2),\r\n [],\r\n )\r\n\r\n const mapRef = React.useRef<MapRef>(null)\r\n const { dispatch: mapDispatch, state: mapState } = React.useContext(MapContext)\r\n\r\n // Keep the projection in sync with zoom at all times — not only while the\r\n // map-settings sidebar is mounted. The globe projection degrades past\r\n // MAX_GLOBE_ZOOM, so we force mercator regardless of which panels are open.\r\n const activeMap = mapState?.map?.map\r\n\r\n React.useEffect(() => {\r\n if (!activeMap) return\r\n\r\n const enforceProjectionForZoom = () => {\r\n if (activeMap.getZoom() <= MAX_GLOBE_ZOOM) return\r\n\r\n const projection = activeMap.getProjection()\r\n const currentType =\r\n typeof projection === 'string'\r\n ? projection\r\n : (projection as { type?: string; name?: string })?.type ?? (projection as { type?: string; name?: string })?.name\r\n\r\n if (currentType !== 'mercator') {\r\n activeMap.setProjection({ type: 'mercator' })\r\n }\r\n }\r\n\r\n enforceProjectionForZoom()\r\n activeMap.on('zoom', enforceProjectionForZoom)\r\n\r\n return () => {\r\n activeMap.off('zoom', enforceProjectionForZoom)\r\n }\r\n }, [activeMap])\r\n\r\n const handleMapLoad = () => {\r\n const map = mapRef.current.getMap()\r\n\r\n if (map.getZoom() > MAX_GLOBE_ZOOM) {\r\n map.setProjection({ type: 'mercator' })\r\n }\r\n\r\n // Only dispatch SET_MAP after map is fully loaded\r\n if (mapRef.current) {\r\n mapDispatch({\r\n type: 'SET_MAP',\r\n payload: { map },\r\n })\r\n }\r\n // initilize a new click manager\r\n const mapClickManager = new MapClickManager(map)\r\n mapDispatch({\r\n type: 'ADD_MAP_CLICK_MANAGER',\r\n payload: { mapClickManager },\r\n })\r\n\r\n const mapHoverManager = new MapHoverManager(map)\r\n mapDispatch({\r\n type: 'ADD_MAP_HOVER_MANAGER',\r\n payload: { mapHoverManager },\r\n })\r\n\r\n // update current Location with URL params or fallback to theme location\r\n const updatedLocation: CurrentLocation = {\r\n // Then override with URL params (this ensures URL params take precedence)\r\n lat: searchParams.has('lat') ? Number.parseFloat(searchParams.get('lat')) : organization.lat ?? CANADA_DEFAULTS.lat,\r\n lng: searchParams.has('lng') ? Number.parseFloat(searchParams.get('lng')) : organization.long ?? CANADA_DEFAULTS.long,\r\n bearing: searchParams.has('bearing') ? Number.parseFloat(searchParams.get('bearing')) : organization.bearing ?? 0,\r\n pitch: searchParams.has('pitch') ? Number.parseFloat(searchParams.get('pitch')) : organization.pitch ?? 0,\r\n zoom: searchParams.has('zoom') ? Number.parseFloat(searchParams.get('zoom')) : organization.zoom ?? CANADA_DEFAULTS.zoom,\r\n // Add location details from URL params if available\r\n countrySubdivision: searchParams.has('countrySubdivision') ? searchParams.get('countrySubdivision') : (organization.countrySubdivision ?? ''),\r\n municipality: searchParams.has('municipality') ? searchParams.get('municipality') : (organization.municipality ?? ''),\r\n address: searchParams.has('address') ? searchParams.get('address') : '', // organization.address,\r\n site: searchParams.has('site') ? searchParams.get('site') : String(organization.locationSiteId ?? ''),\r\n id: String(organization.id),\r\n }\r\n\r\n mapDispatch({\r\n type: 'UPDATE_LOCATION',\r\n payload: { currentLocation: updatedLocation },\r\n })\r\n\r\n // Set map as loaded after all dispatches are complete\r\n setIsMapLoaded(true)\r\n }\r\n\r\n // Enable the perf HUD by appending ?debug=1 to the URL. Never reaches\r\n // production users unless they explicitly opt in.\r\n const isDebug = searchParams.get('debug') === '1'\r\n\r\n // useCallback so the onDblClick prop identity is stable across renders of\r\n // MapViewer; a new function each render caused react-map-gl to detach/re-attach\r\n // the listener. The console.log is intentional dev-only coordinate debugging.\r\n const onDblClick = React.useCallback((e) => {\r\n if (process.env.NODE_ENV === 'production') return\r\n const { lng, lat } = e.lngLat\r\n const elevation = mapRef.current?.queryTerrainElevation([lng, lat]) || 0\r\n const coordinates = { lng, lat, elevation, zoom: mapRef.current?.getZoom() }\r\n // eslint-disable-next-line no-console -- intentional dev-mode coordinate logging\r\n console.log('📍 Map coordinates:', coordinates)\r\n }, [])\r\n\r\n const mapStyle = mapState?.map.mapStyle ?? DEFAULT_MAP_STYLE;\r\n const mapStyleSpec = React.useMemo(() => resolveStyleSpec(mapStyle, maptilerKey), [mapStyle, maptilerKey]);\r\n\r\n return (\r\n <>\r\n <Map\r\n id=\"map-component\"\r\n mapStyle={mapStyleSpec}\r\n mapLib={maplibregl}\r\n onLoad={handleMapLoad}\r\n ref={mapRef}\r\n style={mapContainerStyle}\r\n initialViewState={viewState}\r\n maxPitch={60}\r\n minZoom={organization?.minZoom ?? CANADA_DEFAULTS.zoom}\r\n maxBounds={resolveBounds(organization?.maxBounds)}\r\n projection={initialProjection}\r\n doubleClickZoom={false}\r\n onDblClick={onDblClick}\r\n pixelRatio={pixelRatio}\r\n >\r\n <NavigationControl visualizePitch />\r\n <SettingsButton />\r\n {isMapLoaded\r\n && (\r\n <>\r\n <MapLayers organization={organization} maptilerKey={maptilerKey} />\r\n {/* Bottom-left stack: legend above the layers/styling card, gap auto-managed by flex.\r\n Lifted clear of the toolbar below the md breakpoint: the toolbar is centred and\r\n on a phone that centre reaches all the way to this corner. */}\r\n <div className=\"absolute bottom-20 md:bottom-[10px] left-3 z-10 flex max-w-[calc(100vw-1.5rem)] flex-col gap-2 pointer-events-none\">\r\n {/* Portal slot for on-map WMS time controls; display:contents so an\r\n empty slot adds no flex item / gap, but a mounted control stacks\r\n above the legend + dataset-manager cards. */}\r\n <div id=\"wms-time-slot\" style={{ display: 'contents' }} />\r\n <SensorLegend />\r\n <ViewerLegendHost viewer={ViewerNames.map} />\r\n <DatasetManagerMenu />\r\n </div>\r\n </>\r\n )}\r\n </Map>\r\n <StatsOverlay mapRef={mapRef} enabled={isDebug} />\r\n {/* Renders nothing itself. Outside <Map> and unconditional, so a plugin's layer\r\n outlives the toolbar panel that created it and survives a viewer switch. */}\r\n <PluginMapLayerHost />\r\n </>\r\n\r\n )\r\n}\r\n"],"mappings":";AAoNQ,SAII,UAJJ,KASM,YATN;AA/MR,OAAO,gBAAgB;AACvB,SAAS,uBAAuB;AAChC,OAAO,WAAW;AAClB,OAAO,OAAO,yBAAyB;AAGvC,SAAS,0BAA0B;AACnC,SAAS,mBAAmB;AAC5B,SAAS,wBAAwB;AACjC,SAAS,kBAAkB;AAC3B,SAAS,oBAAoB;AAC7B,OAAO,oBAAoB;AAC3B,SAAS,oBAAoB;AA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A,8BAAC,qBAAkB,gBAAc,MAAC;AAAA,UAClC,oBAAC,kBAAe;AAAA,UACf,eAEG,iCACE;AAAA,gCAAC,aAAU,cAA4B,aAA0B;AAAA,YAIjE,qBAAC,SAAI,WAAU,sHAIb;AAAA,kCAAC,SAAI,IAAG,iBAAgB,OAAO,EAAE,SAAS,WAAW,GAAG;AAAA,cACxD,oBAAC,gBAAa;AAAA,cACd,oBAAC,oBAAiB,QAAQ,YAAY,KAAK;AAAA,cAC3C,oBAAC,sBAAmB;AAAA,eACtB;AAAA,aACF;AAAA;AAAA;AAAA,IAEN;AAAA,IACA,oBAAC,gBAAa,QAAgB,SAAS,SAAS;AAAA,IAGhD,oBAAC,sBAAmB;AAAA,KACtB;AAGJ;","names":["_a","_b","_c"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/core/components/viewers/map/MapViewer.tsx"],"sourcesContent":["'use client'\n\n// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport maplibregl from 'maplibre-gl'\nimport { useSearchParams } from 'next/navigation'\nimport React from 'react'\nimport Map, { NavigationControl } from 'react-map-gl/maplibre'\n\n\nimport { PluginMapLayerHost } from '../../../plugins/host/PluginMapLayerHost'\nimport { ViewerNames } from '../../../types/dbTypes'\nimport { ViewerLegendHost } from '../shared/legends/ViewerLegendHost'\nimport { MapContext } from '../../../store'\nimport { SensorLegend } from '../../ui/Sensors/SensorLegend'\nimport SettingsButton from '../../ui/SettingsButton'\nimport { StatsOverlay } from '../../ui/stats'\n\nimport DatasetManagerMenu from './datasets/DatasetManager'\n\nimport { MapLayers } from './src/MapLayers'\nimport { MapTilerKeyNotice } from './src/MapTilerKeyNotice'\nimport { MapClickManager } from './utils/MapEventManager/MapClickManager'\nimport { MapHoverManager } from './utils/MapEventManager/MapHoverManager'\nimport { DEFAULT_MAP_STYLE } from './utils/mapStyleCatalog'\nimport { resolveStyleSpec } from './utils/mapStyleSpec'\nimport { resolveBounds } from './utils/validateBounds'\n\n\n\n\nimport type { Organization } from '../../../types/dbTypes'\nimport type { CurrentLocation } from '../../../types/map'\nimport type { MapRef} from 'react-map-gl/maplibre';\n\nconst CANADA_DEFAULTS = {\n zoom: 3,\n lat: 56.415,\n long: -98.74,\n} as const\n\nconst MAX_GLOBE_ZOOM = 5\n\ninterface Props {\n width?: string\n height?: string\n organization: Organization\n maptilerKey?: string\n}\n\nexport function MapViewer({ width = '100%', height = '100%', organization, maptilerKey }: Props) {\n\n const searchParams = useSearchParams()\n\n // Add state to track if map is loaded\n const [isMapLoaded, setIsMapLoaded] = React.useState(false)\n\n const viewState = React.useMemo(() => {\n return searchParams.size === 0\n ? {\n zoom: organization.zoom ?? CANADA_DEFAULTS.zoom,\n bearing: organization.bearing ?? 0,\n pitch: organization.pitch ?? 0,\n longitude: organization.long ?? CANADA_DEFAULTS.long,\n latitude: organization.lat ?? CANADA_DEFAULTS.lat,\n }\n : {\n latitude: searchParams.has('lat') ? Number.parseFloat(searchParams.get('lat')) : organization.lat ?? CANADA_DEFAULTS.lat,\n longitude: searchParams.has('lng') ? Number.parseFloat(searchParams.get('lng')) : organization.long ?? CANADA_DEFAULTS.long,\n bearing: searchParams.has('bearing') ? Number.parseFloat(searchParams.get('bearing')) : organization.bearing ?? 0,\n pitch: searchParams.has('pitch') ? Number.parseFloat(searchParams.get('pitch')) : organization.pitch ?? 0,\n zoom: searchParams.has('zoom') ? Number.parseFloat(searchParams.get('zoom')) : organization.zoom ?? CANADA_DEFAULTS.zoom,\n }\n }, [searchParams, organization])\n\n const initialProjection = viewState.zoom > MAX_GLOBE_ZOOM ? 'mercator' : 'globe'\n\n // Memoize the inline style object that gets passed to <Map> for a stable prop identity.\n const mapContainerStyle = React.useMemo(\n () => ({ width, height, backgroundColor: 'black' }),\n [width, height],\n )\n\n // Adaptive pixel ratio. A hardcoded 2 doubled fragment-shader cost on 1× DPR\n // desktops for zero visual gain; capping at 2 keeps phones (DPR 3-4) effective.\n const pixelRatio = React.useMemo(\n () => Math.min(typeof window !== 'undefined' ? window.devicePixelRatio : 1, 2),\n [],\n )\n\n const mapRef = React.useRef<MapRef>(null)\n const { dispatch: mapDispatch, state: mapState } = React.useContext(MapContext)\n\n // Keep the projection in sync with zoom at all times — not only while the\n // map-settings sidebar is mounted. The globe projection degrades past\n // MAX_GLOBE_ZOOM, so we force mercator regardless of which panels are open.\n const activeMap = mapState?.map?.map\n\n React.useEffect(() => {\n if (!activeMap) return\n\n const enforceProjectionForZoom = () => {\n if (activeMap.getZoom() <= MAX_GLOBE_ZOOM) return\n\n const projection = activeMap.getProjection()\n const currentType =\n typeof projection === 'string'\n ? projection\n : (projection as { type?: string; name?: string })?.type ?? (projection as { type?: string; name?: string })?.name\n\n if (currentType !== 'mercator') {\n activeMap.setProjection({ type: 'mercator' })\n }\n }\n\n enforceProjectionForZoom()\n activeMap.on('zoom', enforceProjectionForZoom)\n\n return () => {\n activeMap.off('zoom', enforceProjectionForZoom)\n }\n }, [activeMap])\n\n const handleMapLoad = () => {\n const map = mapRef.current.getMap()\n\n if (map.getZoom() > MAX_GLOBE_ZOOM) {\n map.setProjection({ type: 'mercator' })\n }\n\n // Only dispatch SET_MAP after map is fully loaded\n if (mapRef.current) {\n mapDispatch({\n type: 'SET_MAP',\n payload: { map },\n })\n }\n // initilize a new click manager\n const mapClickManager = new MapClickManager(map)\n mapDispatch({\n type: 'ADD_MAP_CLICK_MANAGER',\n payload: { mapClickManager },\n })\n\n const mapHoverManager = new MapHoverManager(map)\n mapDispatch({\n type: 'ADD_MAP_HOVER_MANAGER',\n payload: { mapHoverManager },\n })\n\n // update current Location with URL params or fallback to theme location\n const updatedLocation: CurrentLocation = {\n // Then override with URL params (this ensures URL params take precedence)\n lat: searchParams.has('lat') ? Number.parseFloat(searchParams.get('lat')) : organization.lat ?? CANADA_DEFAULTS.lat,\n lng: searchParams.has('lng') ? Number.parseFloat(searchParams.get('lng')) : organization.long ?? CANADA_DEFAULTS.long,\n bearing: searchParams.has('bearing') ? Number.parseFloat(searchParams.get('bearing')) : organization.bearing ?? 0,\n pitch: searchParams.has('pitch') ? Number.parseFloat(searchParams.get('pitch')) : organization.pitch ?? 0,\n zoom: searchParams.has('zoom') ? Number.parseFloat(searchParams.get('zoom')) : organization.zoom ?? CANADA_DEFAULTS.zoom,\n // Add location details from URL params if available\n countrySubdivision: searchParams.has('countrySubdivision') ? searchParams.get('countrySubdivision') : (organization.countrySubdivision ?? ''),\n municipality: searchParams.has('municipality') ? searchParams.get('municipality') : (organization.municipality ?? ''),\n address: searchParams.has('address') ? searchParams.get('address') : '', // organization.address,\n site: searchParams.has('site') ? searchParams.get('site') : String(organization.locationSiteId ?? ''),\n id: String(organization.id),\n }\n\n mapDispatch({\n type: 'UPDATE_LOCATION',\n payload: { currentLocation: updatedLocation },\n })\n\n // Set map as loaded after all dispatches are complete\n setIsMapLoaded(true)\n }\n\n // Enable the perf HUD by appending ?debug=1 to the URL. Never reaches\n // production users unless they explicitly opt in.\n const isDebug = searchParams.get('debug') === '1'\n\n // useCallback so the onDblClick prop identity is stable across renders of\n // MapViewer; a new function each render caused react-map-gl to detach/re-attach\n // the listener. The console.log is intentional dev-only coordinate debugging.\n const onDblClick = React.useCallback((e) => {\n if (process.env.NODE_ENV === 'production') return\n const { lng, lat } = e.lngLat\n const elevation = mapRef.current?.queryTerrainElevation([lng, lat]) || 0\n const coordinates = { lng, lat, elevation, zoom: mapRef.current?.getZoom() }\n // eslint-disable-next-line no-console -- intentional dev-mode coordinate logging\n console.log('📍 Map coordinates:', coordinates)\n }, [])\n\n const mapStyle = mapState?.map.mapStyle ?? DEFAULT_MAP_STYLE;\n const mapStyleSpec = React.useMemo(() => resolveStyleSpec(mapStyle, maptilerKey), [mapStyle, maptilerKey]);\n\n return (\n <>\n <Map\n id=\"map-component\"\n mapStyle={mapStyleSpec}\n mapLib={maplibregl}\n onLoad={handleMapLoad}\n ref={mapRef}\n style={mapContainerStyle}\n initialViewState={viewState}\n maxPitch={60}\n minZoom={organization?.minZoom ?? CANADA_DEFAULTS.zoom}\n maxBounds={resolveBounds(organization?.maxBounds)}\n projection={initialProjection}\n doubleClickZoom={false}\n onDblClick={onDblClick}\n pixelRatio={pixelRatio}\n >\n <NavigationControl visualizePitch />\n <SettingsButton />\n {isMapLoaded\n && (\n <>\n <MapLayers organization={organization} maptilerKey={maptilerKey} />\n {/* Bottom-left stack: legend above the layers/styling card, gap auto-managed by flex.\n Lifted clear of the toolbar below the md breakpoint: the toolbar is centred and\n on a phone that centre reaches all the way to this corner. */}\n <div className=\"absolute bottom-20 md:bottom-[10px] left-3 z-10 flex max-w-[calc(100vw-1.5rem)] flex-col gap-2 pointer-events-none\">\n {/* Portal slot for on-map WMS time controls; display:contents so an\n empty slot adds no flex item / gap, but a mounted control stacks\n above the legend + dataset-manager cards. */}\n <div id=\"wms-time-slot\" style={{ display: 'contents' }} />\n <MapTilerKeyNotice maptilerKey={maptilerKey} />\n <SensorLegend />\n <ViewerLegendHost viewer={ViewerNames.map} />\n <DatasetManagerMenu />\n </div>\n </>\n )}\n </Map>\n <StatsOverlay mapRef={mapRef} enabled={isDebug} />\n {/* Renders nothing itself. Outside <Map> and unconditional, so a plugin's layer\n outlives the toolbar panel that created it and survives a viewer switch. */}\n <PluginMapLayerHost />\n </>\n\n )\n}\n"],"mappings":";AAqNQ,SAII,UAJJ,KASM,YATN;AAhNR,OAAO,gBAAgB;AACvB,SAAS,uBAAuB;AAChC,OAAO,WAAW;AAClB,OAAO,OAAO,yBAAyB;AAGvC,SAAS,0BAA0B;AACnC,SAAS,mBAAmB;AAC5B,SAAS,wBAAwB;AACjC,SAAS,kBAAkB;AAC3B,SAAS,oBAAoB;AAC7B,OAAO,oBAAoB;AAC3B,SAAS,oBAAoB;AAE7B,OAAO,wBAAwB;AAE/B,SAAS,iBAAiB;AAC1B,SAAS,yBAAyB;AAClC,SAAS,uBAAuB;AAChC,SAAS,uBAAuB;AAChC,SAAS,yBAAyB;AAClC,SAAS,wBAAwB;AACjC,SAAS,qBAAq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WAAU,sHAIb;AAAA,kCAAC,SAAI,IAAG,iBAAgB,OAAO,EAAE,SAAS,WAAW,GAAG;AAAA,cACxD,oBAAC,qBAAkB,aAA0B;AAAA,cAC7C,oBAAC,gBAAa;AAAA,cACd,oBAAC,oBAAiB,QAAQ,YAAY,KAAK;AAAA,cAC3C,oBAAC,sBAAmB;AAAA,eACtB;AAAA,aACF;AAAA;AAAA;AAAA,IAEN;AAAA,IACA,oBAAC,gBAAa,QAAgB,SAAS,SAAS;AAAA,IAGhD,oBAAC,sBAAmB;AAAA,KACtB;AAGJ;","names":["_a","_b","_c"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/BuildingLayers/index.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/BuildingLayers/index.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAwG/B,wBAAgB,aAAa,CAAC,EAAE,WAAW,EAAE,EAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,qBAuNtE"}
|
|
@@ -28,7 +28,7 @@ import { MapContext } from "../../../../../../../store/Map/context";
|
|
|
28
28
|
import { ViewerNames } from "../../../../../../../types/dbTypes";
|
|
29
29
|
import { useBuildingSensorColours } from "../../../../../../ui/Sensors/useBuildingSensorColours";
|
|
30
30
|
import { MapLayerClickPriority } from "../../../../utils/MapEventManager/MapClickManager";
|
|
31
|
-
import {
|
|
31
|
+
import { maptilerKeyForRequest } from "../../../../utils/mapStyleSpec";
|
|
32
32
|
import MapFeaturePopoverMenu from "../../../MapFeaturePopoverMenu";
|
|
33
33
|
import {
|
|
34
34
|
buildingColourExpression,
|
|
@@ -61,7 +61,9 @@ function buildHeightExpression(hiddenBimOsmIds) {
|
|
|
61
61
|
function resolveBuildingSource(map, maptilerKey) {
|
|
62
62
|
if (maptilerKey == null ? void 0 : maptilerKey.trim()) return addOwnBuildingSource(map, maptilerKey);
|
|
63
63
|
const reusable = REUSABLE_SOURCE_IDS.find((id) => map.getSource(id));
|
|
64
|
-
|
|
64
|
+
if (reusable) return reusable;
|
|
65
|
+
const key = maptilerKeyForRequest(maptilerKey);
|
|
66
|
+
return key ? addOwnBuildingSource(map, key) : null;
|
|
65
67
|
}
|
|
66
68
|
function addOwnBuildingSource(map, key) {
|
|
67
69
|
if (!map.getSource(OWN_SOURCE_ID)) {
|
|
@@ -76,6 +78,7 @@ function addBuildingLayer(map, hiddenBimOsmIds, colourExpr, maptilerKey) {
|
|
|
76
78
|
try {
|
|
77
79
|
if (map.getLayer(LAYER_ID)) return;
|
|
78
80
|
const sourceId = resolveBuildingSource(map, maptilerKey);
|
|
81
|
+
if (!sourceId) return;
|
|
79
82
|
const beforeId = map.getLayer("road_label") ? "road_label" : void 0;
|
|
80
83
|
map.addLayer({
|
|
81
84
|
id: LAYER_ID,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/BuildingLayers/index.tsx"],"sourcesContent":["\"use client\"\r\n\r\n// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\n\r\nimport * as React from \"react\";\r\nimport { Popup } from \"react-map-gl/maplibre\";\r\n\r\nimport { useBuildings } from \"../../../../../../../hooks/buildings/buildings\";\r\nimport { useBuildingsContext } from \"../../../../../../../store\";\r\nimport { useBimContext } from \"../../../../../../../store/BIM/context\";\r\nimport { MapContext } from \"../../../../../../../store/Map/context\";\r\nimport { ViewerNames } from \"../../../../../../../types/dbTypes\";\r\nimport { useBuildingSensorColours } from \"../../../../../../ui/Sensors/useBuildingSensorColours\";\r\nimport { MapLayerClickPriority } from \"../../../../utils/MapEventManager/MapClickManager\";\r\nimport { maptilerKeyOrPlaceholder } from \"../../../../utils/mapStyleSpec\";\r\nimport MapFeaturePopoverMenu from \"../../../MapFeaturePopoverMenu\";\r\n\r\nimport {\r\n buildingColourExpression,\r\n DEFAULT_COLOUR_EXPRESSION,\r\n osmColourEntries,\r\n type PaintExpression,\r\n} from \"./buildingColourExpression\";\r\nimport { BuildingSensorMarkers } from \"./src/BuildingSensorMarkers\";\r\n\r\nimport type { MapMouseEvent } from \"maplibre-gl\";\r\n\r\nconst LAYER_ID = \"maptiler-3d-buildings\";\r\nconst OWN_SOURCE_ID = \"cdt-buildings\";\r\nconst REUSABLE_SOURCE_IDS = [\"openmaptiles\", \"maptiler_planet\", \"carto\"] as const;\r\n\r\nfunction buildLayerFilter() {\r\n return [\r\n \"all\",\r\n [\"!=\", [\"get\", \"hide_3d\"], true],\r\n [\"!=\", [\"get\", \"hide_3d\"], \"true\"],\r\n ];\r\n}\r\n\r\nfunction buildHeightExpression(hiddenBimOsmIds: string[]) {\r\n return [\r\n \"case\",\r\n [\r\n \"any\",\r\n [\"in\", [\"to-string\", [\"id\"]], [\"literal\", hiddenBimOsmIds]],\r\n [\"in\", [\"to-string\", [\"coalesce\", [\"get\", \"osm_id\"], \"\"]], [\"literal\", hiddenBimOsmIds]],\r\n ],\r\n 0.1,\r\n [\"coalesce\", [\"get\", \"height\"], 5],\r\n ];\r\n}\r\n\r\nfunction resolveBuildingSource(map: any, maptilerKey?: string): string {\r\n if (maptilerKey?.trim()) return addOwnBuildingSource(map, maptilerKey);\r\n\r\n const reusable = REUSABLE_SOURCE_IDS.find((id) => map.getSource(id));\r\n return reusable ?? addOwnBuildingSource(map, maptilerKeyOrPlaceholder(maptilerKey));\r\n}\r\n\r\nfunction addOwnBuildingSource(map: any, key: string): string {\r\n if (!map.getSource(OWN_SOURCE_ID)) {\r\n map.addSource(OWN_SOURCE_ID, {\r\n type: \"vector\",\r\n url: `https://api.maptiler.com/tiles/buildings/tiles.json?key=${key}`,\r\n });\r\n }\r\n return OWN_SOURCE_ID;\r\n}\r\n\r\nfunction addBuildingLayer(map: any, hiddenBimOsmIds: string[], colourExpr: PaintExpression, maptilerKey?: string) {\r\n try {\r\n if (map.getLayer(LAYER_ID)) return;\r\n\r\n const sourceId = resolveBuildingSource(map, maptilerKey);\r\n\r\n // Insert below road labels so buildings don't cover text\r\n const beforeId = map.getLayer(\"road_label\") ? \"road_label\" : undefined;\r\n\r\n map.addLayer({\r\n id: LAYER_ID,\r\n type: \"fill-extrusion\",\r\n source: sourceId,\r\n \"source-layer\": \"building\",\r\n minzoom: 14,\r\n filter: buildLayerFilter(),\r\n paint: {\r\n // Seeded rather than hardcoded: `styledata` re-adds this layer after any setStyle, and\r\n // the paint effect below will not re-run for it, so the colours would be lost.\r\n \"fill-extrusion-color\": colourExpr,\r\n \"fill-extrusion-height\": buildHeightExpression(hiddenBimOsmIds),\r\n \"fill-extrusion-base\": [\"coalesce\", [\"get\", \"render_min_height\"], 0],\r\n \"fill-extrusion-opacity\": [\r\n \"interpolate\", [\"linear\"], [\"zoom\"],\r\n 14, 0.6,\r\n 16, 0.8,\r\n ],\r\n },\r\n }, beforeId);\r\n } catch {\r\n // Map style may be in a transitional state during layer addition\r\n }\r\n}\r\n\r\nexport function BuildingLayer({ maptilerKey }: { maptilerKey?: string }) {\r\n const { state: mapState } = React.useContext(MapContext);\r\n const { map, mapClickManager } = mapState.map;\r\n const { setCompareItems } = useBuildingsContext();\r\n const { buildings } = useBuildings();\r\n const { state: bimState } = useBimContext();\r\n const { bimModelsAddedToMap } = bimState.bim;\r\n\r\n const [hoveredFeature, setHoveredFeature] = React.useState<string | number | null>(null);\r\n const [clickedFeature, setClickedFeature] = React.useState<any>(null);\r\n const [buildingByOsmId, setBuildingByOsmId] = React.useState<Record<string, { id: number }>>({});\r\n\r\n // Footprints are tinted by the average reading of the legend's sensor type. Nothing is polled\r\n // and nothing changes colour until a type is pinned in the legend and switched on.\r\n const sensorColours = useBuildingSensorColours(ViewerNames.map);\r\n const { averages, colourKey } = sensorColours;\r\n\r\n const osmColours = React.useMemo(\r\n () => osmColourEntries(averages, buildings ?? []),\r\n [averages, buildings],\r\n );\r\n\r\n const colourExpr = React.useMemo(\r\n () => buildingColourExpression({\r\n osmColours,\r\n clickedKey: clickedFeature?.id ?? null,\r\n hoveredKey: hoveredFeature,\r\n }),\r\n [osmColours, clickedFeature, hoveredFeature],\r\n );\r\n\r\n // Read by the add-layer effect, which must not re-run when only the colours change.\r\n const colourExprRef = React.useRef<PaintExpression>(DEFAULT_COLOUR_EXPRESSION);\r\n colourExprRef.current = colourExpr;\r\n\r\n const hiddenBimOsmIds = React.useMemo(\r\n () => Array.from(new Set(\r\n (bimModelsAddedToMap || [])\r\n .map((model: any) => model?.building?.buildingOsmId)\r\n .filter((value: unknown): value is string | number => value !== null && value !== undefined)\r\n .map((value) => String(value))\r\n )),\r\n [bimModelsAddedToMap],\r\n );\r\n\r\n React.useEffect(() => {\r\n if (!buildings || !Array.isArray(buildings) || buildings.length === 0) {\r\n setBuildingByOsmId({});\r\n return;\r\n }\r\n\r\n const mapping: Record<string, { id: number }> = {};\r\n buildings.forEach((building: any) => {\r\n if (building.buildingOsmId != null) {\r\n mapping[String(building.buildingOsmId)] = { id: building.id };\r\n }\r\n });\r\n\r\n setBuildingByOsmId((prevMapping) => {\r\n const newKeys = Object.keys(mapping);\r\n const prevKeys = Object.keys(prevMapping);\r\n\r\n if (newKeys.length !== prevKeys.length) {\r\n return mapping;\r\n }\r\n\r\n const hasChanges = newKeys.some((key) => mapping[key]?.id !== prevMapping[key]?.id);\r\n return hasChanges ? mapping : prevMapping;\r\n });\r\n }, [buildings]);\r\n\r\n // Add the layer imperatively\r\n React.useEffect(() => {\r\n if (!map) return;\r\n\r\n if (map.isStyleLoaded()) {\r\n addBuildingLayer(map, hiddenBimOsmIds, colourExprRef.current, maptilerKey);\r\n }\r\n\r\n const onStyleLoad = () => addBuildingLayer(map, hiddenBimOsmIds, colourExprRef.current, maptilerKey);\r\n map.on(\"styledata\", onStyleLoad);\r\n\r\n return () => {\r\n try {\r\n map.off(\"styledata\", onStyleLoad);\r\n if (map.getLayer(LAYER_ID)) {\r\n map.removeLayer(LAYER_ID);\r\n }\r\n if (map.getSource(OWN_SOURCE_ID)) {\r\n map.removeSource(OWN_SOURCE_ID);\r\n }\r\n } catch {\r\n // Map may have been destroyed before cleanup runs\r\n }\r\n };\r\n }, [map, hiddenBimOsmIds, maptilerKey]);\r\n\r\n React.useEffect(() => {\r\n if (!map || !map.getLayer(LAYER_ID)) return;\r\n\r\n map.setFilter(LAYER_ID, buildLayerFilter() as any);\r\n map.setPaintProperty(LAYER_ID, \"fill-extrusion-height\", buildHeightExpression(hiddenBimOsmIds) as any);\r\n }, [map, hiddenBimOsmIds]);\r\n\r\n // Register click, hover, and mouse leave handlers\r\n React.useEffect(() => {\r\n if (!map || !mapClickManager) return;\r\n\r\n const handleClick = (e: MapMouseEvent) => {\r\n if (!map.getLayer(LAYER_ID)) return;\r\n const clicked = map.queryRenderedFeatures(e.point, { layers: [LAYER_ID] });\r\n const feature = clicked?.[0];\r\n if (!feature) {\r\n setClickedFeature(null);\r\n return;\r\n }\r\n\r\n const properties = feature.properties || {};\r\n const lng = e.lngLat.lng;\r\n const lat = e.lngLat.lat;\r\n const coordinates = [lng, lat];\r\n\r\n // Use MVT feature.id (OSM ID) or fall back to properties\r\n const featureId = feature.id || properties.osm_id || `temp-${Date.now()}`;\r\n const normalizedOsmId = String(featureId);\r\n const dbId = buildingByOsmId[normalizedOsmId]?.id || null;\r\n const _name = Object.entries(properties).find(\r\n ([key]) => key.toLowerCase().includes(\"name\")\r\n )?.[1] || undefined;\r\n\r\n const featureClone: any = {\r\n ...feature,\r\n id: featureId,\r\n properties: {\r\n ...properties,\r\n coordinates,\r\n _name,\r\n osm_id: normalizedOsmId,\r\n isBuilding: true,\r\n isDbBuilding: Boolean(dbId),\r\n dbId,\r\n _popupNonce: Date.now(),\r\n },\r\n };\r\n\r\n setClickedFeature(featureClone);\r\n };\r\n\r\n const handleHover = (e: MapMouseEvent) => {\r\n if (!map.getLayer(LAYER_ID)) return;\r\n const hovered = map.queryRenderedFeatures(e.point, { layers: [LAYER_ID] });\r\n\r\n if (hovered[0]) {\r\n map.getCanvas().style.cursor = \"pointer\";\r\n const hoveredId = hovered[0].id || hovered[0].properties?.osm_id || null;\r\n setHoveredFeature(hoveredId);\r\n } else {\r\n map.getCanvas().style.cursor = \"\";\r\n setHoveredFeature(null);\r\n }\r\n };\r\n\r\n const handleMouseLeave = () => {\r\n map.getCanvas().style.cursor = \"\";\r\n setHoveredFeature(null);\r\n };\r\n\r\n mapClickManager.register(\r\n LAYER_ID,\r\n MapLayerClickPriority.BuildingLayersClickPriority,\r\n handleClick\r\n );\r\n map.on(\"mousemove\", LAYER_ID, handleHover);\r\n map.on(\"mouseleave\", LAYER_ID, handleMouseLeave);\r\n\r\n return () => {\r\n mapClickManager.unregister(LAYER_ID);\r\n map.off(\"mousemove\", LAYER_ID, handleHover);\r\n map.off(\"mouseleave\", LAYER_ID, handleMouseLeave);\r\n };\r\n }, [map, mapClickManager, buildingByOsmId, hiddenBimOsmIds]);\r\n\r\n // Single writer for fill-extrusion-color: hover, click and sensor colours are merged into one\r\n // expression upstream, so there is no second effect to race with. `colourExpr` only changes\r\n // when a highlight moves or a sensor colour actually differs, not on every 15s poll.\r\n React.useEffect(() => {\r\n if (!map || !map.getLayer(LAYER_ID)) return;\r\n map.setPaintProperty(LAYER_ID, \"fill-extrusion-color\", colourExpr);\r\n }, [map, colourExpr]);\r\n\r\n return (\r\n <>\r\n <BuildingSensorMarkers buildings={buildings ?? []} sensorColours={sensorColours} />\r\n {clickedFeature && clickedFeature.properties?.coordinates && (\r\n <Popup\r\n anchor=\"bottom\"\r\n closeButton={true}\r\n closeOnClick={false}\r\n focusAfterOpen={true}\r\n key={`maptiler-${clickedFeature.id}-${clickedFeature.properties._popupNonce}`}\r\n latitude={clickedFeature.properties.coordinates[1]}\r\n longitude={clickedFeature.properties.coordinates[0]}\r\n onClose={() => setClickedFeature(null)}\r\n >\r\n <MapFeaturePopoverMenu\r\n feature={clickedFeature}\r\n onCloseAction={() => {\r\n setClickedFeature(null);\r\n setCompareItems([]);\r\n }}\r\n />\r\n </Popup>\r\n )}\r\n </>\r\n );\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAwSI,mBACE,KADF;AAlSJ,YAAY,WAAW;AACvB,SAAS,aAAa;AAEtB,SAAS,oBAAoB;AAC7B,SAAS,2BAA2B;AACpC,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAC3B,SAAS,mBAAmB;AAC5B,SAAS,gCAAgC;AACzC,SAAS,6BAA6B;AACtC,SAAS,gCAAgC;AACzC,OAAO,2BAA2B;AAElC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,6BAA6B;AAItC,MAAM,WAAW;AACjB,MAAM,gBAAgB;AACtB,MAAM,sBAAsB,CAAC,gBAAgB,mBAAmB,OAAO;AAEvE,SAAS,mBAAmB;AAC1B,SAAO;AAAA,IACL;AAAA,IACA,CAAC,MAAM,CAAC,OAAO,SAAS,GAAG,IAAI;AAAA,IAC/B,CAAC,MAAM,CAAC,OAAO,SAAS,GAAG,MAAM;AAAA,EACnC;AACF;AAEA,SAAS,sBAAsB,iBAA2B;AACxD,SAAO;AAAA,IACL;AAAA,IACA;AAAA,MACE;AAAA,MACA,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,eAAe,CAAC;AAAA,MAC1D,CAAC,MAAM,CAAC,aAAa,CAAC,YAAY,CAAC,OAAO,QAAQ,GAAG,EAAE,CAAC,GAAG,CAAC,WAAW,eAAe,CAAC;AAAA,IACzF;AAAA,IACA;AAAA,IACA,CAAC,YAAY,CAAC,OAAO,QAAQ,GAAG,CAAC;AAAA,EACnC;AACF;AAEA,SAAS,sBAAsB,KAAU,aAA8B;AACrE,MAAI,2CAAa,OAAQ,QAA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QAEhB,UAAU,eAAe,WAAW,YAAY,CAAC;AAAA,QACjD,WAAW,eAAe,WAAW,YAAY,CAAC;AAAA,QAClD,SAAS,MAAM,kBAAkB,IAAI;AAAA,QAErC;AAAA,UAAC;AAAA;AAAA,YACC,SAAS;AAAA,YACT,eAAe,MAAM;AACnB,gCAAkB,IAAI;AACtB,8BAAgB,CAAC,CAAC;AAAA,YACpB;AAAA;AAAA,QACF;AAAA;AAAA,MAXK,YAAY,eAAe,EAAE,IAAI,eAAe,WAAW,WAAW;AAAA,IAY7E;AAAA,KAEJ;AAEJ;","names":["_a"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/BuildingLayers/index.tsx"],"sourcesContent":["\"use client\"\n\n// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\n\nimport * as React from \"react\";\nimport { Popup } from \"react-map-gl/maplibre\";\n\nimport { useBuildings } from \"../../../../../../../hooks/buildings/buildings\";\nimport { useBuildingsContext } from \"../../../../../../../store\";\nimport { useBimContext } from \"../../../../../../../store/BIM/context\";\nimport { MapContext } from \"../../../../../../../store/Map/context\";\nimport { ViewerNames } from \"../../../../../../../types/dbTypes\";\nimport { useBuildingSensorColours } from \"../../../../../../ui/Sensors/useBuildingSensorColours\";\nimport { MapLayerClickPriority } from \"../../../../utils/MapEventManager/MapClickManager\";\nimport { maptilerKeyForRequest } from \"../../../../utils/mapStyleSpec\";\nimport MapFeaturePopoverMenu from \"../../../MapFeaturePopoverMenu\";\n\nimport {\n buildingColourExpression,\n DEFAULT_COLOUR_EXPRESSION,\n osmColourEntries,\n type PaintExpression,\n} from \"./buildingColourExpression\";\nimport { BuildingSensorMarkers } from \"./src/BuildingSensorMarkers\";\n\nimport type { MapMouseEvent } from \"maplibre-gl\";\n\nconst LAYER_ID = \"maptiler-3d-buildings\";\nconst OWN_SOURCE_ID = \"cdt-buildings\";\nconst REUSABLE_SOURCE_IDS = [\"openmaptiles\", \"maptiler_planet\", \"carto\"] as const;\n\nfunction buildLayerFilter() {\n return [\n \"all\",\n [\"!=\", [\"get\", \"hide_3d\"], true],\n [\"!=\", [\"get\", \"hide_3d\"], \"true\"],\n ];\n}\n\nfunction buildHeightExpression(hiddenBimOsmIds: string[]) {\n return [\n \"case\",\n [\n \"any\",\n [\"in\", [\"to-string\", [\"id\"]], [\"literal\", hiddenBimOsmIds]],\n [\"in\", [\"to-string\", [\"coalesce\", [\"get\", \"osm_id\"], \"\"]], [\"literal\", hiddenBimOsmIds]],\n ],\n 0.1,\n [\"coalesce\", [\"get\", \"height\"], 5],\n ];\n}\n\n/** Null when there is nothing to draw buildings from, so the layer is skipped rather than 403ing. */\nfunction resolveBuildingSource(map: any, maptilerKey?: string): string | null {\n if (maptilerKey?.trim()) return addOwnBuildingSource(map, maptilerKey);\n\n const reusable = REUSABLE_SOURCE_IDS.find((id) => map.getSource(id));\n if (reusable) return reusable;\n\n const key = maptilerKeyForRequest(maptilerKey);\n return key ? addOwnBuildingSource(map, key) : null;\n}\n\nfunction addOwnBuildingSource(map: any, key: string): string {\n if (!map.getSource(OWN_SOURCE_ID)) {\n map.addSource(OWN_SOURCE_ID, {\n type: \"vector\",\n url: `https://api.maptiler.com/tiles/buildings/tiles.json?key=${key}`,\n });\n }\n return OWN_SOURCE_ID;\n}\n\nfunction addBuildingLayer(map: any, hiddenBimOsmIds: string[], colourExpr: PaintExpression, maptilerKey?: string) {\n try {\n if (map.getLayer(LAYER_ID)) return;\n\n const sourceId = resolveBuildingSource(map, maptilerKey);\n if (!sourceId) return;\n\n // Insert below road labels so buildings don't cover text\n const beforeId = map.getLayer(\"road_label\") ? \"road_label\" : undefined;\n\n map.addLayer({\n id: LAYER_ID,\n type: \"fill-extrusion\",\n source: sourceId,\n \"source-layer\": \"building\",\n minzoom: 14,\n filter: buildLayerFilter(),\n paint: {\n // Seeded rather than hardcoded: `styledata` re-adds this layer after any setStyle, and\n // the paint effect below will not re-run for it, so the colours would be lost.\n \"fill-extrusion-color\": colourExpr,\n \"fill-extrusion-height\": buildHeightExpression(hiddenBimOsmIds),\n \"fill-extrusion-base\": [\"coalesce\", [\"get\", \"render_min_height\"], 0],\n \"fill-extrusion-opacity\": [\n \"interpolate\", [\"linear\"], [\"zoom\"],\n 14, 0.6,\n 16, 0.8,\n ],\n },\n }, beforeId);\n } catch {\n // Map style may be in a transitional state during layer addition\n }\n}\n\nexport function BuildingLayer({ maptilerKey }: { maptilerKey?: string }) {\n const { state: mapState } = React.useContext(MapContext);\n const { map, mapClickManager } = mapState.map;\n const { setCompareItems } = useBuildingsContext();\n const { buildings } = useBuildings();\n const { state: bimState } = useBimContext();\n const { bimModelsAddedToMap } = bimState.bim;\n\n const [hoveredFeature, setHoveredFeature] = React.useState<string | number | null>(null);\n const [clickedFeature, setClickedFeature] = React.useState<any>(null);\n const [buildingByOsmId, setBuildingByOsmId] = React.useState<Record<string, { id: number }>>({});\n\n // Footprints are tinted by the average reading of the legend's sensor type. Nothing is polled\n // and nothing changes colour until a type is pinned in the legend and switched on.\n const sensorColours = useBuildingSensorColours(ViewerNames.map);\n const { averages, colourKey } = sensorColours;\n\n const osmColours = React.useMemo(\n () => osmColourEntries(averages, buildings ?? []),\n [averages, buildings],\n );\n\n const colourExpr = React.useMemo(\n () => buildingColourExpression({\n osmColours,\n clickedKey: clickedFeature?.id ?? null,\n hoveredKey: hoveredFeature,\n }),\n [osmColours, clickedFeature, hoveredFeature],\n );\n\n // Read by the add-layer effect, which must not re-run when only the colours change.\n const colourExprRef = React.useRef<PaintExpression>(DEFAULT_COLOUR_EXPRESSION);\n colourExprRef.current = colourExpr;\n\n const hiddenBimOsmIds = React.useMemo(\n () => Array.from(new Set(\n (bimModelsAddedToMap || [])\n .map((model: any) => model?.building?.buildingOsmId)\n .filter((value: unknown): value is string | number => value !== null && value !== undefined)\n .map((value) => String(value))\n )),\n [bimModelsAddedToMap],\n );\n\n React.useEffect(() => {\n if (!buildings || !Array.isArray(buildings) || buildings.length === 0) {\n setBuildingByOsmId({});\n return;\n }\n\n const mapping: Record<string, { id: number }> = {};\n buildings.forEach((building: any) => {\n if (building.buildingOsmId != null) {\n mapping[String(building.buildingOsmId)] = { id: building.id };\n }\n });\n\n setBuildingByOsmId((prevMapping) => {\n const newKeys = Object.keys(mapping);\n const prevKeys = Object.keys(prevMapping);\n\n if (newKeys.length !== prevKeys.length) {\n return mapping;\n }\n\n const hasChanges = newKeys.some((key) => mapping[key]?.id !== prevMapping[key]?.id);\n return hasChanges ? mapping : prevMapping;\n });\n }, [buildings]);\n\n // Add the layer imperatively\n React.useEffect(() => {\n if (!map) return;\n\n if (map.isStyleLoaded()) {\n addBuildingLayer(map, hiddenBimOsmIds, colourExprRef.current, maptilerKey);\n }\n\n const onStyleLoad = () => addBuildingLayer(map, hiddenBimOsmIds, colourExprRef.current, maptilerKey);\n map.on(\"styledata\", onStyleLoad);\n\n return () => {\n try {\n map.off(\"styledata\", onStyleLoad);\n if (map.getLayer(LAYER_ID)) {\n map.removeLayer(LAYER_ID);\n }\n if (map.getSource(OWN_SOURCE_ID)) {\n map.removeSource(OWN_SOURCE_ID);\n }\n } catch {\n // Map may have been destroyed before cleanup runs\n }\n };\n }, [map, hiddenBimOsmIds, maptilerKey]);\n\n React.useEffect(() => {\n if (!map || !map.getLayer(LAYER_ID)) return;\n\n map.setFilter(LAYER_ID, buildLayerFilter() as any);\n map.setPaintProperty(LAYER_ID, \"fill-extrusion-height\", buildHeightExpression(hiddenBimOsmIds) as any);\n }, [map, hiddenBimOsmIds]);\n\n // Register click, hover, and mouse leave handlers\n React.useEffect(() => {\n if (!map || !mapClickManager) return;\n\n const handleClick = (e: MapMouseEvent) => {\n if (!map.getLayer(LAYER_ID)) return;\n const clicked = map.queryRenderedFeatures(e.point, { layers: [LAYER_ID] });\n const feature = clicked?.[0];\n if (!feature) {\n setClickedFeature(null);\n return;\n }\n\n const properties = feature.properties || {};\n const lng = e.lngLat.lng;\n const lat = e.lngLat.lat;\n const coordinates = [lng, lat];\n\n // Use MVT feature.id (OSM ID) or fall back to properties\n const featureId = feature.id || properties.osm_id || `temp-${Date.now()}`;\n const normalizedOsmId = String(featureId);\n const dbId = buildingByOsmId[normalizedOsmId]?.id || null;\n const _name = Object.entries(properties).find(\n ([key]) => key.toLowerCase().includes(\"name\")\n )?.[1] || undefined;\n\n const featureClone: any = {\n ...feature,\n id: featureId,\n properties: {\n ...properties,\n coordinates,\n _name,\n osm_id: normalizedOsmId,\n isBuilding: true,\n isDbBuilding: Boolean(dbId),\n dbId,\n _popupNonce: Date.now(),\n },\n };\n\n setClickedFeature(featureClone);\n };\n\n const handleHover = (e: MapMouseEvent) => {\n if (!map.getLayer(LAYER_ID)) return;\n const hovered = map.queryRenderedFeatures(e.point, { layers: [LAYER_ID] });\n\n if (hovered[0]) {\n map.getCanvas().style.cursor = \"pointer\";\n const hoveredId = hovered[0].id || hovered[0].properties?.osm_id || null;\n setHoveredFeature(hoveredId);\n } else {\n map.getCanvas().style.cursor = \"\";\n setHoveredFeature(null);\n }\n };\n\n const handleMouseLeave = () => {\n map.getCanvas().style.cursor = \"\";\n setHoveredFeature(null);\n };\n\n mapClickManager.register(\n LAYER_ID,\n MapLayerClickPriority.BuildingLayersClickPriority,\n handleClick\n );\n map.on(\"mousemove\", LAYER_ID, handleHover);\n map.on(\"mouseleave\", LAYER_ID, handleMouseLeave);\n\n return () => {\n mapClickManager.unregister(LAYER_ID);\n map.off(\"mousemove\", LAYER_ID, handleHover);\n map.off(\"mouseleave\", LAYER_ID, handleMouseLeave);\n };\n }, [map, mapClickManager, buildingByOsmId, hiddenBimOsmIds]);\n\n // Single writer for fill-extrusion-color: hover, click and sensor colours are merged into one\n // expression upstream, so there is no second effect to race with. `colourExpr` only changes\n // when a highlight moves or a sensor colour actually differs, not on every 15s poll.\n React.useEffect(() => {\n if (!map || !map.getLayer(LAYER_ID)) return;\n map.setPaintProperty(LAYER_ID, \"fill-extrusion-color\", colourExpr);\n }, [map, colourExpr]);\n\n return (\n <>\n <BuildingSensorMarkers buildings={buildings ?? []} sensorColours={sensorColours} />\n {clickedFeature && clickedFeature.properties?.coordinates && (\n <Popup\n anchor=\"bottom\"\n closeButton={true}\n closeOnClick={false}\n focusAfterOpen={true}\n key={`maptiler-${clickedFeature.id}-${clickedFeature.properties._popupNonce}`}\n latitude={clickedFeature.properties.coordinates[1]}\n longitude={clickedFeature.properties.coordinates[0]}\n onClose={() => setClickedFeature(null)}\n >\n <MapFeaturePopoverMenu\n feature={clickedFeature}\n onCloseAction={() => {\n setClickedFeature(null);\n setCompareItems([]);\n }}\n />\n </Popup>\n )}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA6SI,mBACE,KADF;AAvSJ,YAAY,WAAW;AACvB,SAAS,aAAa;AAEtB,SAAS,oBAAoB;AAC7B,SAAS,2BAA2B;AACpC,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAC3B,SAAS,mBAAmB;AAC5B,SAAS,gCAAgC;AACzC,SAAS,6BAA6B;AACtC,SAAS,6BAA6B;AACtC,OAAO,2BAA2B;AAElC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,6BAA6B;AAItC,MAAM,WAAW;AACjB,MAAM,gBAAgB;AACtB,MAAM,sBAAsB,CAAC,gBAAgB,mBAAmB,OAAO;AAEvE,SAAS,mBAAmB;AAC1B,SAAO;AAAA,IACL;AAAA,IACA,CAAC,MAAM,CAAC,OAAO,SAAS,GAAG,IAAI;AAAA,IAC/B,CAAC,MAAM,CAAC,OAAO,SAAS,GAAG,MAAM;AAAA,EACnC;AACF;AAEA,SAAS,sBAAsB,iBAA2B;AACxD,SAAO;AAAA,IACL;AAAA,IACA;AAAA,MACE;AAAA,MACA,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,eAAe,CAAC;AAAA,MAC1D,CAAC,MAAM,CAAC,aAAa,CAAC,YAAY,CAAC,OAAO,QAAQ,GAAG,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,wBAAwB,UAAU;AAAA,EACnE,GAAG,CAAC,KAAK,UAAU,CAAC;AAEpB,SACE,iCACE;AAAA,wBAAC,yBAAsB,WAAW,gCAAa,CAAC,GAAG,eAA8B;AAAA,IAChF,oBAAkB,oBAAe,eAAf,mBAA2B,gBAC5C;AAAA,MAAC;AAAA;AAAA,QACC,QAAO;AAAA,QACP,aAAa;AAAA,QACb,cAAc;AAAA,QACd,gBAAgB;AAAA,QAEhB,UAAU,eAAe,WAAW,YAAY,CAAC;AAAA,QACjD,WAAW,eAAe,WAAW,YAAY,CAAC;AAAA,QAClD,SAAS,MAAM,kBAAkB,IAAI;AAAA,QAErC;AAAA,UAAC;AAAA;AAAA,YACC,SAAS;AAAA,YACT,eAAe,MAAM;AACnB,gCAAkB,IAAI;AACtB,8BAAgB,CAAC,CAAC;AAAA,YACpB;AAAA;AAAA,QACF;AAAA;AAAA,MAXK,YAAY,eAAe,EAAE,IAAI,eAAe,WAAW,WAAW;AAAA,IAY7E;AAAA,KAEJ;AAEJ;","names":["_a"]}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import type { Organization } from '../../../../../../../types/dbTypes';
|
|
3
|
+
/**
|
|
4
|
+
* Hovered and resting width ramp. MapLibre allows one zoom curve per property, as the
|
|
5
|
+
* input of a top-level step/interpolate, so hover has to branch in the outputs.
|
|
6
|
+
*/
|
|
7
|
+
export declare const SUBDIVISION_LINE_WIDTH: readonly ["interpolate", readonly ["linear"], readonly ["zoom"], 4, readonly ["case", readonly ["boolean", readonly ["feature-state", "hover"], false], 0.5, 0.5], 8, readonly ["case", readonly ["boolean", readonly ["feature-state", "hover"], false], 1.4, 1.4], 10, readonly ["case", readonly ["boolean", readonly ["feature-state", "hover"], false], 3, 1.7], 14, readonly ["case", readonly ["boolean", readonly ["feature-state", "hover"], false], 4.6, 2.4], 15, readonly ["case", readonly ["boolean", readonly ["feature-state", "hover"], false], 5, 2.4]];
|
|
3
8
|
export declare const CountryLayer: ({ organization, maptilerKey }: {
|
|
4
9
|
organization?: Organization;
|
|
5
10
|
maptilerKey?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/CountryLayer/index.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAW9B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/CountryLayer/index.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAW9B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAA;AAWtE;;;GAGG;AACH,eAAO,MAAM,sBAAsB,2iBAOzB,CAAA;AAwIV,eAAO,MAAM,YAAY,GAAI,+BAA+B;IAAE,YAAY,CAAC,EAAE,YAAY,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,sBAwGhH,CAAA"}
|
|
@@ -23,7 +23,7 @@ import { useSearchParams, useRouter } from "next/navigation";
|
|
|
23
23
|
import * as React from "react";
|
|
24
24
|
import { Source, Layer } from "react-map-gl/maplibre";
|
|
25
25
|
import { MapContext } from "../../../../../../../store/Map/context";
|
|
26
|
-
import {
|
|
26
|
+
import { maptilerKeyForRequest } from "../../../../utils/mapStyleSpec";
|
|
27
27
|
import { hexToRgba, buildSubdivisionUrl } from "./countryLayerUtils";
|
|
28
28
|
import { useCameraSubdivision } from "./useCameraSubdivision";
|
|
29
29
|
import { useSubdivisionHover } from "./useSubdivisionHover";
|
|
@@ -33,12 +33,21 @@ const SUBDIVISION_SOURCE_ID = "admin-subdivisions-source";
|
|
|
33
33
|
const SUBDIVISION_FILL_ID = "admin-subdivisions-fill";
|
|
34
34
|
const SUBDIVISION_LINE_ID = "admin-subdivisions-line";
|
|
35
35
|
const SUBDIVISION_LINE_MAX_ZOOM = 15;
|
|
36
|
-
const
|
|
36
|
+
const HOVERED = ["boolean", ["feature-state", "hover"], false];
|
|
37
37
|
const SUBDIVISION_LINE_WIDTH = [
|
|
38
|
-
"
|
|
39
|
-
["
|
|
40
|
-
["
|
|
41
|
-
|
|
38
|
+
"interpolate",
|
|
39
|
+
["linear"],
|
|
40
|
+
["zoom"],
|
|
41
|
+
4,
|
|
42
|
+
["case", HOVERED, 0.5, 0.5],
|
|
43
|
+
8,
|
|
44
|
+
["case", HOVERED, 1.4, 1.4],
|
|
45
|
+
10,
|
|
46
|
+
["case", HOVERED, 3, 1.7],
|
|
47
|
+
14,
|
|
48
|
+
["case", HOVERED, 4.6, 2.4],
|
|
49
|
+
15,
|
|
50
|
+
["case", HOVERED, 5, 2.4]
|
|
42
51
|
];
|
|
43
52
|
const GLOBAL_LAYER_IDS = [
|
|
44
53
|
"global-borders-country",
|
|
@@ -48,11 +57,13 @@ const GLOBAL_LAYER_IDS = [
|
|
|
48
57
|
"global-labels-city"
|
|
49
58
|
];
|
|
50
59
|
function addGlobalBorderLayer(map, color, maptilerKey) {
|
|
60
|
+
const key = maptilerKeyForRequest(maptilerKey);
|
|
61
|
+
if (!key) return;
|
|
51
62
|
try {
|
|
52
63
|
if (!map.getSource(BOUNDARIES_SOURCE_ID)) {
|
|
53
64
|
map.addSource(BOUNDARIES_SOURCE_ID, {
|
|
54
65
|
type: "vector",
|
|
55
|
-
url: `https://api.maptiler.com/tiles/v3/tiles.json?key=${
|
|
66
|
+
url: `https://api.maptiler.com/tiles/v3/tiles.json?key=${key}`
|
|
56
67
|
});
|
|
57
68
|
}
|
|
58
69
|
if (!map.getLayer("global-borders-country")) {
|
|
@@ -256,6 +267,7 @@ const CountryLayer = ({ organization, maptilerKey }) => {
|
|
|
256
267
|
);
|
|
257
268
|
};
|
|
258
269
|
export {
|
|
259
|
-
CountryLayer
|
|
270
|
+
CountryLayer,
|
|
271
|
+
SUBDIVISION_LINE_WIDTH
|
|
260
272
|
};
|
|
261
273
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/CountryLayer/index.tsx"],"sourcesContent":["\"use client\"\r\n\r\n// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport { useSearchParams, useRouter } from 'next/navigation'\r\nimport * as React from 'react'\r\nimport { Source, Layer } from 'react-map-gl/maplibre'\r\n\r\nimport { MapContext } from '../../../../../../../store/Map/context'\r\n\r\nimport { maptilerKeyOrPlaceholder } from '../../../../utils/mapStyleSpec'\r\n\r\nimport { hexToRgba, buildSubdivisionUrl } from './countryLayerUtils'\r\nimport { useCameraSubdivision } from './useCameraSubdivision'\r\nimport { useSubdivisionHover } from './useSubdivisionHover'\r\n\r\nimport type { Organization } from '../../../../../../../types/dbTypes'\r\n\r\nconst DEFAULT_BORDER_COLOR = '#73cee2'\r\nconst BOUNDARIES_SOURCE_ID = 'openmaptiles-boundaries'\r\nconst SUBDIVISION_SOURCE_ID = 'admin-subdivisions-source'\r\nconst SUBDIVISION_FILL_ID = 'admin-subdivisions-fill'\r\nconst SUBDIVISION_LINE_ID = 'admin-subdivisions-line'\r\nconst SUBDIVISION_LINE_MAX_ZOOM = 15\r\nconst SUBDIVISION_HOVER_MIN_ZOOM = 10\r\n\r\nconst SUBDIVISION_LINE_WIDTH = [\r\n 'case',\r\n ['all', ['boolean', ['feature-state', 'hover'], false], ['>', ['zoom'], SUBDIVISION_HOVER_MIN_ZOOM]],\r\n ['interpolate', ['linear'], ['zoom'], 10, 3, 15, 5],\r\n ['interpolate', ['linear'], ['zoom'], 4, 0.5, 8, 1.4, 14, 2.4],\r\n] as const\r\nconst GLOBAL_LAYER_IDS = [\r\n 'global-borders-country',\r\n 'global-borders-region',\r\n 'global-labels-country',\r\n 'global-labels-state',\r\n 'global-labels-city',\r\n] as const\r\n\r\nfunction addGlobalBorderLayer(map: any, color: string, maptilerKey?: string) {\r\n try {\r\n if (!map.getSource(BOUNDARIES_SOURCE_ID)) {\r\n map.addSource(BOUNDARIES_SOURCE_ID, {\r\n type: 'vector',\r\n url: `https://api.maptiler.com/tiles/v3/tiles.json?key=${maptilerKeyOrPlaceholder(maptilerKey)}`,\r\n })\r\n }\r\n\r\n // Country borders — visible at all zooms, slightly thinner up close where states take over.\r\n if (!map.getLayer('global-borders-country')) {\r\n map.addLayer({\r\n id: 'global-borders-country',\r\n type: 'line',\r\n source: BOUNDARIES_SOURCE_ID,\r\n 'source-layer': 'boundary',\r\n filter: ['all', ['==', 'admin_level', 2], ['==', 'maritime', 0]],\r\n layout: { 'line-cap': 'round', 'line-join': 'round' },\r\n paint: {\r\n 'line-color': color,\r\n 'line-width': { base: 1, stops: [[0, 0.8], [4, 1.4], [10, 1.4], [14, 1]] },\r\n },\r\n })\r\n }\r\n\r\n // State / province borders — fade in around zoom 3, dominate from 5+.\r\n if (!map.getLayer('global-borders-region')) {\r\n map.addLayer({\r\n id: 'global-borders-region',\r\n type: 'line',\r\n source: BOUNDARIES_SOURCE_ID,\r\n 'source-layer': 'boundary',\r\n filter: ['all', ['in', 'admin_level', 3, 4], ['==', 'maritime', 0]],\r\n minzoom: 2,\r\n layout: { 'line-cap': 'round', 'line-join': 'round' },\r\n paint: {\r\n 'line-color': color,\r\n 'line-width': { base: 1, stops: [[2, 0], [4, 0.5], [8, 1.4], [14, 2.4]] },\r\n 'line-opacity': { base: 1, stops: [[2, 0], [4, 0.7], [6, 1]] },\r\n },\r\n })\r\n }\r\n\r\n // Country labels — small/global up to zoom ~6, gone by 8.\r\n if (!map.getLayer('global-labels-country')) {\r\n map.addLayer({\r\n id: 'global-labels-country',\r\n type: 'symbol',\r\n source: BOUNDARIES_SOURCE_ID,\r\n 'source-layer': 'place',\r\n filter: ['==', 'class', 'country'],\r\n minzoom: 1,\r\n maxzoom: 8,\r\n layout: {\r\n 'text-field': ['coalesce', ['get', 'name:latin'], ['get', 'name']],\r\n 'text-font': ['Noto Sans Regular'],\r\n 'text-size': { base: 1, stops: [[1, 10], [4, 13], [6, 16]] },\r\n 'text-letter-spacing': 0.1,\r\n 'text-max-width': 8,\r\n 'text-transform': 'uppercase',\r\n },\r\n paint: {\r\n 'text-color': '#ffffff',\r\n 'text-halo-color': 'rgba(0,0,0,0.7)',\r\n 'text-halo-width': 1.2,\r\n 'text-opacity': { base: 1, stops: [[5, 1], [7, 0]] },\r\n },\r\n })\r\n }\r\n\r\n // State / province labels — cover zoom 3–8.\r\n if (!map.getLayer('global-labels-state')) {\r\n map.addLayer({\r\n id: 'global-labels-state',\r\n type: 'symbol',\r\n source: BOUNDARIES_SOURCE_ID,\r\n 'source-layer': 'place',\r\n filter: ['in', 'class', 'state', 'province'],\r\n minzoom: 3,\r\n maxzoom: 9,\r\n layout: {\r\n 'text-field': ['coalesce', ['get', 'name:latin'], ['get', 'name']],\r\n 'text-font': ['Noto Sans Regular'],\r\n 'text-size': { base: 1, stops: [[3, 9], [6, 12], [8, 14]] },\r\n 'text-letter-spacing': 0.05,\r\n 'text-max-width': 8,\r\n },\r\n paint: {\r\n 'text-color': '#e8e8e8',\r\n 'text-halo-color': 'rgba(0,0,0,0.6)',\r\n 'text-halo-width': 1,\r\n 'text-opacity': { base: 1, stops: [[3, 0], [4, 1], [8, 1], [9, 0]] },\r\n },\r\n })\r\n }\r\n\r\n // Major city labels (rank ≤ 4 = most prominent cities) — appear when zoomed in past country level.\r\n if (!map.getLayer('global-labels-city')) {\r\n map.addLayer({\r\n id: 'global-labels-city',\r\n type: 'symbol',\r\n source: BOUNDARIES_SOURCE_ID,\r\n 'source-layer': 'place',\r\n filter: ['in', 'class', 'city', 'town'],\r\n minzoom: 5,\r\n maxzoom: 13,\r\n layout: {\r\n 'text-field': ['coalesce', ['get', 'name:latin'], ['get', 'name']],\r\n 'text-font': ['Noto Sans Regular'],\r\n 'text-size': { base: 1, stops: [[5, 10], [9, 13], [12, 15]] },\r\n 'text-max-width': 8,\r\n },\r\n paint: {\r\n 'text-color': '#dcdcdc',\r\n 'text-halo-color': 'rgba(0,0,0,0.7)',\r\n 'text-halo-width': 1.1,\r\n },\r\n })\r\n }\r\n } catch {\r\n // style may be in a transitional state\r\n }\r\n}\r\n\r\nexport const CountryLayer = ({ organization, maptilerKey }: { organization?: Organization; maptilerKey?: string }) => {\r\n const { state: mapState, dispatch: mapDispatch } = React.useContext(MapContext)\r\n const { map, currentLocation } = mapState.map\r\n const searchParams = useSearchParams()\r\n const router = useRouter()\r\n\r\n const countryCode = (organization?.country || 'CA').toUpperCase()\r\n const borderColor = hexToRgba((organization?.mainColor as string) || DEFAULT_BORDER_COLOR, 0.7)\r\n const subdivisionUrl = buildSubdivisionUrl(countryCode)\r\n\r\n // Re-added on every style swap: setStyle drops imperatively added layers.\r\n React.useEffect(() => {\r\n if (!map) return\r\n const addNow = () => addGlobalBorderLayer(map, borderColor, maptilerKey)\r\n if (map.isStyleLoaded()) addNow()\r\n map.on('styledata', addNow)\r\n return () => {\r\n try {\r\n map.off('styledata', addNow)\r\n for (const id of GLOBAL_LAYER_IDS) {\r\n if (map.getLayer(id)) map.removeLayer(id)\r\n }\r\n } catch {\r\n // map may be destroyed\r\n }\r\n }\r\n }, [map, borderColor, maptilerKey])\r\n\r\n // If the org already has a fixed subdivision or municipality, lock them in and skip camera tracking\r\n const orgHasLocation = !!(organization?.countrySubdivision || organization?.municipality)\r\n\r\n // When org has fixed location values, push them into currentLocation once\r\n React.useEffect(() => {\r\n if (!orgHasLocation) return\r\n mapDispatch({\r\n type: 'UPDATE_LOCATION',\r\n payload: {\r\n currentLocation: {\r\n ...(currentLocation ?? {}),\r\n countrySubdivision: organization?.countrySubdivision ?? currentLocation?.countrySubdivision,\r\n municipality: organization?.municipality ?? currentLocation?.municipality,\r\n } as any,\r\n },\r\n })\r\n\r\n }, [orgHasLocation])\r\n\r\n const commitSubdivision = React.useCallback((code: string) => {\r\n if (code === (currentLocation?.countrySubdivision || null)) return\r\n\r\n mapDispatch({\r\n type: 'UPDATE_LOCATION',\r\n payload: {\r\n currentLocation: { ...(currentLocation ?? {}), countrySubdivision: code } as any,\r\n },\r\n })\r\n\r\n const params = new URLSearchParams(searchParams.toString())\r\n params.set('countrySubdivision', code)\r\n router.replace(`?${params.toString()}`, { scroll: false })\r\n }, [currentLocation, mapDispatch, router, searchParams])\r\n\r\n useCameraSubdivision({\r\n map,\r\n layerId: SUBDIVISION_FILL_ID,\r\n sourceId: SUBDIVISION_SOURCE_ID,\r\n enabled: !orgHasLocation,\r\n onResolve: commitSubdivision,\r\n })\r\n\r\n useSubdivisionHover({\r\n map,\r\n layerId: SUBDIVISION_FILL_ID,\r\n sourceId: SUBDIVISION_SOURCE_ID,\r\n enabled: !orgHasLocation,\r\n })\r\n\r\n if (orgHasLocation) return null\r\n\r\n return (\r\n <Source\r\n id={SUBDIVISION_SOURCE_ID}\r\n type=\"geojson\"\r\n data={subdivisionUrl}\r\n generateId\r\n >\r\n {/* Zero opacity, never visible: this is what hit-tests the camera target and the pointer. */}\r\n <Layer\r\n id={SUBDIVISION_FILL_ID}\r\n type=\"fill\"\r\n paint={{ 'fill-color': borderColor, 'fill-opacity': 0 }}\r\n />\r\n <Layer\r\n id={SUBDIVISION_LINE_ID}\r\n type=\"line\"\r\n maxzoom={SUBDIVISION_LINE_MAX_ZOOM}\r\n layout={{ 'line-cap': 'round', 'line-join': 'round' }}\r\n paint={{\r\n 'line-color': borderColor,\r\n 'line-width': SUBDIVISION_LINE_WIDTH as never,\r\n }}\r\n />\r\n </Source>\r\n )\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqPI,SAOE,KAPF;AAhPJ,SAAS,iBAAiB,iBAAiB;AAC3C,YAAY,WAAW;AACvB,SAAS,QAAQ,aAAa;AAE9B,SAAS,kBAAkB;AAE3B,SAAS,gCAAgC;AAEzC,SAAS,WAAW,2BAA2B;AAC/C,SA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,YACC,IAAI;AAAA,YACJ,MAAK;AAAA,YACL,OAAO,EAAE,cAAc,aAAa,gBAAgB,EAAE;AAAA;AAAA,QACxD;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACC,IAAI;AAAA,YACJ,MAAK;AAAA,YACL,SAAS;AAAA,YACT,QAAQ,EAAE,YAAY,SAAS,aAAa,QAAQ;AAAA,YACpD,OAAO;AAAA,cACL,cAAc;AAAA,cACd,cAAc;AAAA,YAChB;AAAA;AAAA,QACF;AAAA;AAAA;AAAA,EACF;AAEJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/CountryLayer/index.tsx"],"sourcesContent":["\"use client\"\r\n\r\n// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport { useSearchParams, useRouter } from 'next/navigation'\r\nimport * as React from 'react'\r\nimport { Source, Layer } from 'react-map-gl/maplibre'\r\n\r\nimport { MapContext } from '../../../../../../../store/Map/context'\r\n\r\nimport { maptilerKeyForRequest } from '../../../../utils/mapStyleSpec'\r\n\r\nimport { hexToRgba, buildSubdivisionUrl } from './countryLayerUtils'\r\nimport { useCameraSubdivision } from './useCameraSubdivision'\r\nimport { useSubdivisionHover } from './useSubdivisionHover'\r\n\r\nimport type { Organization } from '../../../../../../../types/dbTypes'\r\n\r\nconst DEFAULT_BORDER_COLOR = '#73cee2'\r\nconst BOUNDARIES_SOURCE_ID = 'openmaptiles-boundaries'\r\nconst SUBDIVISION_SOURCE_ID = 'admin-subdivisions-source'\r\nconst SUBDIVISION_FILL_ID = 'admin-subdivisions-fill'\r\nconst SUBDIVISION_LINE_ID = 'admin-subdivisions-line'\r\nconst SUBDIVISION_LINE_MAX_ZOOM = 15\r\n\r\nconst HOVERED = ['boolean', ['feature-state', 'hover'], false] as const\r\n\r\n/**\r\n * Hovered and resting width ramp. MapLibre allows one zoom curve per property, as the\r\n * input of a top-level step/interpolate, so hover has to branch in the outputs.\r\n */\r\nexport const SUBDIVISION_LINE_WIDTH = [\r\n 'interpolate', ['linear'], ['zoom'],\r\n 4, ['case', HOVERED, 0.5, 0.5],\r\n 8, ['case', HOVERED, 1.4, 1.4],\r\n 10, ['case', HOVERED, 3, 1.7],\r\n 14, ['case', HOVERED, 4.6, 2.4],\r\n 15, ['case', HOVERED, 5, 2.4],\r\n] as const\r\nconst GLOBAL_LAYER_IDS = [\r\n 'global-borders-country',\r\n 'global-borders-region',\r\n 'global-labels-country',\r\n 'global-labels-state',\r\n 'global-labels-city',\r\n] as const\r\n\r\nfunction addGlobalBorderLayer(map: any, color: string, maptilerKey?: string) {\r\n const key = maptilerKeyForRequest(maptilerKey)\r\n if (!key) return\r\n\r\n try {\r\n if (!map.getSource(BOUNDARIES_SOURCE_ID)) {\r\n map.addSource(BOUNDARIES_SOURCE_ID, {\r\n type: 'vector',\r\n url: `https://api.maptiler.com/tiles/v3/tiles.json?key=${key}`,\r\n })\r\n }\r\n\r\n // Country borders — visible at all zooms, slightly thinner up close where states take over.\r\n if (!map.getLayer('global-borders-country')) {\r\n map.addLayer({\r\n id: 'global-borders-country',\r\n type: 'line',\r\n source: BOUNDARIES_SOURCE_ID,\r\n 'source-layer': 'boundary',\r\n filter: ['all', ['==', 'admin_level', 2], ['==', 'maritime', 0]],\r\n layout: { 'line-cap': 'round', 'line-join': 'round' },\r\n paint: {\r\n 'line-color': color,\r\n 'line-width': { base: 1, stops: [[0, 0.8], [4, 1.4], [10, 1.4], [14, 1]] },\r\n },\r\n })\r\n }\r\n\r\n // State / province borders — fade in around zoom 3, dominate from 5+.\r\n if (!map.getLayer('global-borders-region')) {\r\n map.addLayer({\r\n id: 'global-borders-region',\r\n type: 'line',\r\n source: BOUNDARIES_SOURCE_ID,\r\n 'source-layer': 'boundary',\r\n filter: ['all', ['in', 'admin_level', 3, 4], ['==', 'maritime', 0]],\r\n minzoom: 2,\r\n layout: { 'line-cap': 'round', 'line-join': 'round' },\r\n paint: {\r\n 'line-color': color,\r\n 'line-width': { base: 1, stops: [[2, 0], [4, 0.5], [8, 1.4], [14, 2.4]] },\r\n 'line-opacity': { base: 1, stops: [[2, 0], [4, 0.7], [6, 1]] },\r\n },\r\n })\r\n }\r\n\r\n // Country labels — small/global up to zoom ~6, gone by 8.\r\n if (!map.getLayer('global-labels-country')) {\r\n map.addLayer({\r\n id: 'global-labels-country',\r\n type: 'symbol',\r\n source: BOUNDARIES_SOURCE_ID,\r\n 'source-layer': 'place',\r\n filter: ['==', 'class', 'country'],\r\n minzoom: 1,\r\n maxzoom: 8,\r\n layout: {\r\n 'text-field': ['coalesce', ['get', 'name:latin'], ['get', 'name']],\r\n 'text-font': ['Noto Sans Regular'],\r\n 'text-size': { base: 1, stops: [[1, 10], [4, 13], [6, 16]] },\r\n 'text-letter-spacing': 0.1,\r\n 'text-max-width': 8,\r\n 'text-transform': 'uppercase',\r\n },\r\n paint: {\r\n 'text-color': '#ffffff',\r\n 'text-halo-color': 'rgba(0,0,0,0.7)',\r\n 'text-halo-width': 1.2,\r\n 'text-opacity': { base: 1, stops: [[5, 1], [7, 0]] },\r\n },\r\n })\r\n }\r\n\r\n // State / province labels — cover zoom 3–8.\r\n if (!map.getLayer('global-labels-state')) {\r\n map.addLayer({\r\n id: 'global-labels-state',\r\n type: 'symbol',\r\n source: BOUNDARIES_SOURCE_ID,\r\n 'source-layer': 'place',\r\n filter: ['in', 'class', 'state', 'province'],\r\n minzoom: 3,\r\n maxzoom: 9,\r\n layout: {\r\n 'text-field': ['coalesce', ['get', 'name:latin'], ['get', 'name']],\r\n 'text-font': ['Noto Sans Regular'],\r\n 'text-size': { base: 1, stops: [[3, 9], [6, 12], [8, 14]] },\r\n 'text-letter-spacing': 0.05,\r\n 'text-max-width': 8,\r\n },\r\n paint: {\r\n 'text-color': '#e8e8e8',\r\n 'text-halo-color': 'rgba(0,0,0,0.6)',\r\n 'text-halo-width': 1,\r\n 'text-opacity': { base: 1, stops: [[3, 0], [4, 1], [8, 1], [9, 0]] },\r\n },\r\n })\r\n }\r\n\r\n // Major city labels (rank ≤ 4 = most prominent cities) — appear when zoomed in past country level.\r\n if (!map.getLayer('global-labels-city')) {\r\n map.addLayer({\r\n id: 'global-labels-city',\r\n type: 'symbol',\r\n source: BOUNDARIES_SOURCE_ID,\r\n 'source-layer': 'place',\r\n filter: ['in', 'class', 'city', 'town'],\r\n minzoom: 5,\r\n maxzoom: 13,\r\n layout: {\r\n 'text-field': ['coalesce', ['get', 'name:latin'], ['get', 'name']],\r\n 'text-font': ['Noto Sans Regular'],\r\n 'text-size': { base: 1, stops: [[5, 10], [9, 13], [12, 15]] },\r\n 'text-max-width': 8,\r\n },\r\n paint: {\r\n 'text-color': '#dcdcdc',\r\n 'text-halo-color': 'rgba(0,0,0,0.7)',\r\n 'text-halo-width': 1.1,\r\n },\r\n })\r\n }\r\n } catch {\r\n // style may be in a transitional state\r\n }\r\n}\r\n\r\nexport const CountryLayer = ({ organization, maptilerKey }: { organization?: Organization; maptilerKey?: string }) => {\r\n const { state: mapState, dispatch: mapDispatch } = React.useContext(MapContext)\r\n const { map, currentLocation } = mapState.map\r\n const searchParams = useSearchParams()\r\n const router = useRouter()\r\n\r\n const countryCode = (organization?.country || 'CA').toUpperCase()\r\n const borderColor = hexToRgba((organization?.mainColor as string) || DEFAULT_BORDER_COLOR, 0.7)\r\n const subdivisionUrl = buildSubdivisionUrl(countryCode)\r\n\r\n // Re-added on every style swap: setStyle drops imperatively added layers.\r\n React.useEffect(() => {\r\n if (!map) return\r\n const addNow = () => addGlobalBorderLayer(map, borderColor, maptilerKey)\r\n if (map.isStyleLoaded()) addNow()\r\n map.on('styledata', addNow)\r\n return () => {\r\n try {\r\n map.off('styledata', addNow)\r\n for (const id of GLOBAL_LAYER_IDS) {\r\n if (map.getLayer(id)) map.removeLayer(id)\r\n }\r\n } catch {\r\n // map may be destroyed\r\n }\r\n }\r\n }, [map, borderColor, maptilerKey])\r\n\r\n // If the org already has a fixed subdivision or municipality, lock them in and skip camera tracking\r\n const orgHasLocation = !!(organization?.countrySubdivision || organization?.municipality)\r\n\r\n // When org has fixed location values, push them into currentLocation once\r\n React.useEffect(() => {\r\n if (!orgHasLocation) return\r\n mapDispatch({\r\n type: 'UPDATE_LOCATION',\r\n payload: {\r\n currentLocation: {\r\n ...(currentLocation ?? {}),\r\n countrySubdivision: organization?.countrySubdivision ?? currentLocation?.countrySubdivision,\r\n municipality: organization?.municipality ?? currentLocation?.municipality,\r\n } as any,\r\n },\r\n })\r\n\r\n }, [orgHasLocation])\r\n\r\n const commitSubdivision = React.useCallback((code: string) => {\r\n if (code === (currentLocation?.countrySubdivision || null)) return\r\n\r\n mapDispatch({\r\n type: 'UPDATE_LOCATION',\r\n payload: {\r\n currentLocation: { ...(currentLocation ?? {}), countrySubdivision: code } as any,\r\n },\r\n })\r\n\r\n const params = new URLSearchParams(searchParams.toString())\r\n params.set('countrySubdivision', code)\r\n router.replace(`?${params.toString()}`, { scroll: false })\r\n }, [currentLocation, mapDispatch, router, searchParams])\r\n\r\n useCameraSubdivision({\r\n map,\r\n layerId: SUBDIVISION_FILL_ID,\r\n sourceId: SUBDIVISION_SOURCE_ID,\r\n enabled: !orgHasLocation,\r\n onResolve: commitSubdivision,\r\n })\r\n\r\n useSubdivisionHover({\r\n map,\r\n layerId: SUBDIVISION_FILL_ID,\r\n sourceId: SUBDIVISION_SOURCE_ID,\r\n enabled: !orgHasLocation,\r\n })\r\n\r\n if (orgHasLocation) return null\r\n\r\n return (\r\n <Source\r\n id={SUBDIVISION_SOURCE_ID}\r\n type=\"geojson\"\r\n data={subdivisionUrl}\r\n generateId\r\n >\r\n {/* Zero opacity, never visible: this is what hit-tests the camera target and the pointer. */}\r\n <Layer\r\n id={SUBDIVISION_FILL_ID}\r\n type=\"fill\"\r\n paint={{ 'fill-color': borderColor, 'fill-opacity': 0 }}\r\n />\r\n <Layer\r\n id={SUBDIVISION_LINE_ID}\r\n type=\"line\"\r\n maxzoom={SUBDIVISION_LINE_MA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CAAC,IAAI,EAAE,QAAQ,MAAM,CAAC;AAAA,EAC3D,GAAG,CAAC,iBAAiB,aAAa,QAAQ,YAAY,CAAC;AAEvD,uBAAqB;AAAA,IACnB;AAAA,IACA,SAAS;AAAA,IACT,UAAU;AAAA,IACV,SAAS,CAAC;AAAA,IACV,WAAW;AAAA,EACb,CAAC;AAED,sBAAoB;AAAA,IAClB;AAAA,IACA,SAAS;AAAA,IACT,UAAU;AAAA,IACV,SAAS,CAAC;AAAA,EACZ,CAAC;AAED,MAAI,eAAgB,QAAO;AAE3B,SACE;AAAA,IAAC;AAAA;AAAA,MACC,IAAI;AAAA,MACJ,MAAK;AAAA,MACL,MAAM;AAAA,MACN,YAAU;AAAA,MAGV;AAAA;AAAA,UAAC;AAAA;AAAA,YACC,IAAI;AAAA,YACJ,MAAK;AAAA,YACL,OAAO,EAAE,cAAc,aAAa,gBAAgB,EAAE;AAAA;AAAA,QACxD;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACC,IAAI;AAAA,YACJ,MAAK;AAAA,YACL,SAAS;AAAA,YACT,QAAQ,EAAE,YAAY,SAAS,aAAa,QAAQ;AAAA,YACpD,OAAO;AAAA,cACL,cAAc;AAAA,cACd,cAAc;AAAA,YAChB;AAAA;AAAA,QACF;AAAA;AAAA;AAAA,EACF;AAEJ;","names":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Shown only where no MapTiler key is configured. Reads the same key the layers are given,
|
|
4
|
+
* so the notice cannot contradict what actually rendered.
|
|
5
|
+
*/
|
|
6
|
+
export declare function MapTilerKeyNotice({ maptilerKey }: {
|
|
7
|
+
maptilerKey?: string;
|
|
8
|
+
}): React.JSX.Element;
|
|
9
|
+
//# sourceMappingURL=MapTilerKeyNotice.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapTilerKeyNotice.d.ts","sourceRoot":"","sources":["../../../../../../src/core/components/viewers/map/src/MapTilerKeyNotice.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAQ9B;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,WAAW,EAAE,EAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,qBA8C1E"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as LR from "lucide-react";
|
|
4
|
+
import { useTranslations } from "next-intl";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import { Button } from "../../../ui/Button";
|
|
7
|
+
import { Menubar } from "../../../ui/Menubar";
|
|
8
|
+
import { isLocalhostOrigin } from "../utils/mapStyleSpec";
|
|
9
|
+
const MAPTILER_KEYS_URL = "https://cloud.maptiler.com/account/keys/";
|
|
10
|
+
function MapTilerKeyNotice({ maptilerKey }) {
|
|
11
|
+
const t = useTranslations("MapTilerKeyNotice");
|
|
12
|
+
const [dismissed, setDismissed] = React.useState(false);
|
|
13
|
+
const hasKey = Boolean((maptilerKey != null ? maptilerKey : "").trim());
|
|
14
|
+
const [isDevHost, setIsDevHost] = React.useState(null);
|
|
15
|
+
React.useEffect(() => setIsDevHost(isLocalhostOrigin()), []);
|
|
16
|
+
if (hasKey || dismissed || isDevHost === null) return null;
|
|
17
|
+
return /* @__PURE__ */ jsx("div", { className: "pointer-events-auto", role: "status", "data-testid": "maptiler-key-notice", children: /* @__PURE__ */ jsxs(Menubar, { className: "h-auto w-[min(20rem,calc(100vw-1.5rem))] items-start gap-2 p-3", children: [
|
|
18
|
+
/* @__PURE__ */ jsx(LR.KeyRound, { size: 15, className: "mt-0.5 shrink-0 opacity-70", "aria-hidden": true }),
|
|
19
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1 space-y-1", children: [
|
|
20
|
+
/* @__PURE__ */ jsx("div", { className: "text-sm font-medium leading-snug", children: isDevHost ? t("devTitle") : t("title") }),
|
|
21
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs leading-snug opacity-70", children: isDevHost ? t("devBody") : t("body") }),
|
|
22
|
+
/* @__PURE__ */ jsxs(
|
|
23
|
+
"a",
|
|
24
|
+
{
|
|
25
|
+
href: MAPTILER_KEYS_URL,
|
|
26
|
+
target: "_blank",
|
|
27
|
+
rel: "noreferrer noopener",
|
|
28
|
+
className: "inline-flex items-center gap-1 text-xs font-medium underline underline-offset-2 opacity-90 hover:opacity-100",
|
|
29
|
+
children: [
|
|
30
|
+
t("cta"),
|
|
31
|
+
/* @__PURE__ */ jsx(LR.ExternalLink, { size: 11, "aria-hidden": true })
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
)
|
|
35
|
+
] }),
|
|
36
|
+
/* @__PURE__ */ jsx(
|
|
37
|
+
Button,
|
|
38
|
+
{
|
|
39
|
+
variant: "ghost",
|
|
40
|
+
size: "icon",
|
|
41
|
+
onClick: () => setDismissed(true),
|
|
42
|
+
"aria-label": t("dismiss"),
|
|
43
|
+
title: t("dismiss"),
|
|
44
|
+
className: "h-7 w-7 shrink-0 opacity-70 transition-opacity duration-200 hover:bg-transparent hover:opacity-100",
|
|
45
|
+
children: /* @__PURE__ */ jsx(LR.X, { size: 14 })
|
|
46
|
+
}
|
|
47
|
+
)
|
|
48
|
+
] }) });
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
MapTilerKeyNotice
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=MapTilerKeyNotice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/core/components/viewers/map/src/MapTilerKeyNotice.tsx"],"sourcesContent":["'use client'\n\n// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport * as LR from 'lucide-react'\nimport { useTranslations } from 'next-intl'\nimport * as React from 'react'\n\nimport { Button } from '../../../ui/Button'\nimport { Menubar } from '../../../ui/Menubar'\nimport { isLocalhostOrigin } from '../utils/mapStyleSpec'\n\nconst MAPTILER_KEYS_URL = 'https://cloud.maptiler.com/account/keys/'\n\n/**\n * Shown only where no MapTiler key is configured. Reads the same key the layers are given,\n * so the notice cannot contradict what actually rendered.\n */\nexport function MapTilerKeyNotice({ maptilerKey }: { maptilerKey?: string }) {\n const t = useTranslations('MapTilerKeyNotice')\n const [dismissed, setDismissed] = React.useState(false)\n\n const hasKey = Boolean((maptilerKey ?? '').trim())\n\n // Effect, not render: the server has no hostname and a guess would hydrate mismatched.\n const [isDevHost, setIsDevHost] = React.useState<boolean | null>(null)\n React.useEffect(() => setIsDevHost(isLocalhostOrigin()), [])\n\n if (hasKey || dismissed || isDevHost === null) return null\n\n return (\n <div className=\"pointer-events-auto\" role=\"status\" data-testid=\"maptiler-key-notice\">\n <Menubar className=\"h-auto w-[min(20rem,calc(100vw-1.5rem))] items-start gap-2 p-3\">\n <LR.KeyRound size={15} className=\"mt-0.5 shrink-0 opacity-70\" aria-hidden />\n <div className=\"flex-1 space-y-1\">\n <div className=\"text-sm font-medium leading-snug\">\n {isDevHost ? t('devTitle') : t('title')}\n </div>\n <p className=\"text-xs leading-snug opacity-70\">\n {isDevHost ? t('devBody') : t('body')}\n </p>\n <a\n href={MAPTILER_KEYS_URL}\n target=\"_blank\"\n rel=\"noreferrer noopener\"\n className=\"inline-flex items-center gap-1 text-xs font-medium underline underline-offset-2 opacity-90 hover:opacity-100\"\n >\n {t('cta')}\n <LR.ExternalLink size={11} aria-hidden />\n </a>\n </div>\n <Button\n variant=\"ghost\"\n size=\"icon\"\n onClick={() => setDismissed(true)}\n aria-label={t('dismiss')}\n title={t('dismiss')}\n className=\"h-7 w-7 shrink-0 opacity-70 transition-opacity duration-200 hover:bg-transparent hover:opacity-100\"\n >\n <LR.X size={14} />\n </Button>\n </Menubar>\n </div>\n )\n}\n"],"mappings":";AAkCQ,cAQE,YARF;AA7BR,YAAY,QAAQ;AACpB,SAAS,uBAAuB;AAChC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AAM,IAAI;AAAA;AAAA,IAClB;AAAA,KACF,GACF;AAEJ;","names":[]}
|
|
@@ -6,6 +6,13 @@ export declare const SATELLITE_STYLE_URL = "cdt:satellite";
|
|
|
6
6
|
export declare const STREETS_STYLE_URL = "cdt:streets";
|
|
7
7
|
/** Falls back to the placeholder so a missing key degrades the map instead of breaking it. */
|
|
8
8
|
export declare function maptilerKeyOrPlaceholder(key?: string | null): string;
|
|
9
|
+
/** False during SSR: every caller adds sources from the browser, so no placeholder is needed server-side. */
|
|
10
|
+
export declare function isLocalhostOrigin(): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* The key to sign a MapTiler request with, or null when the caller must not call MapTiler:
|
|
13
|
+
* the placeholder is honoured on localhost only, so elsewhere a missing key earns a 403.
|
|
14
|
+
*/
|
|
15
|
+
export declare function maptilerKeyForRequest(key?: string | null): string | null;
|
|
9
16
|
/**
|
|
10
17
|
* Build the Satellite base style for a deployment's own MapTiler key.
|
|
11
18
|
* Without a key it falls back to Esri imagery, terrarium elevation and the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapStyleSpec.d.ts","sourceRoot":"","sources":["../../../../../../src/core/components/viewers/map/utils/mapStyleSpec.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AACrD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAErD,+FAA+F;AAC/F,eAAO,MAAM,wBAAwB,sCAAsC,CAAA;AAE3E,eAAO,MAAM,mBAAmB,kBAAkB,CAAA;AAClD,eAAO,MAAM,iBAAiB,gBAAgB,CAAA;AAU9C,8FAA8F;AAC9F,wBAAgB,wBAAwB,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAGpE;
|
|
1
|
+
{"version":3,"file":"mapStyleSpec.d.ts","sourceRoot":"","sources":["../../../../../../src/core/components/viewers/map/utils/mapStyleSpec.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AACrD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAErD,+FAA+F;AAC/F,eAAO,MAAM,wBAAwB,sCAAsC,CAAA;AAE3E,eAAO,MAAM,mBAAmB,kBAAkB,CAAA;AAClD,eAAO,MAAM,iBAAiB,gBAAgB,CAAA;AAU9C,8FAA8F;AAC9F,wBAAgB,wBAAwB,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAGpE;AAMD,6GAA6G;AAC7G,wBAAgB,iBAAiB,IAAI,OAAO,CAG3C;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAIxE;AAuCD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,kBAAkB,CAmD3E;AAYD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,QAAQ,EACf,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,GAClB,MAAM,GAAG,kBAAkB,CAQ7B"}
|
|
@@ -12,6 +12,16 @@ function maptilerKeyOrPlaceholder(key) {
|
|
|
12
12
|
return trimmed || MAPTILER_PLACEHOLDER_KEY;
|
|
13
13
|
}
|
|
14
14
|
const hasOwnKey = (key) => Boolean((key != null ? key : "").trim());
|
|
15
|
+
const LOCALHOST_HOSTNAMES = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "::1", "[::1]"]);
|
|
16
|
+
function isLocalhostOrigin() {
|
|
17
|
+
if (typeof window === "undefined") return false;
|
|
18
|
+
return LOCALHOST_HOSTNAMES.has(window.location.hostname);
|
|
19
|
+
}
|
|
20
|
+
function maptilerKeyForRequest(key) {
|
|
21
|
+
const trimmed = (key != null ? key : "").trim();
|
|
22
|
+
if (trimmed) return trimmed;
|
|
23
|
+
return isLocalhostOrigin() ? MAPTILER_PLACEHOLDER_KEY : null;
|
|
24
|
+
}
|
|
15
25
|
function satelliteImagerySource(key) {
|
|
16
26
|
if (!hasOwnKey(key)) {
|
|
17
27
|
return {
|
|
@@ -119,6 +129,8 @@ export {
|
|
|
119
129
|
SATELLITE_STYLE_URL,
|
|
120
130
|
STREETS_STYLE_URL,
|
|
121
131
|
buildSatelliteStyle,
|
|
132
|
+
isLocalhostOrigin,
|
|
133
|
+
maptilerKeyForRequest,
|
|
122
134
|
maptilerKeyOrPlaceholder,
|
|
123
135
|
resolveStyleSpec
|
|
124
136
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/core/components/viewers/map/utils/mapStyleSpec.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport type { MapStyle } from '../../../../types/map'\r\nimport type { StyleSpecification } from 'maplibre-gl'\r\n\r\n/** MapTiler's public demo key. Honoured on localhost only, so dev works without an account. */\r\nexport const MAPTILER_PLACEHOLDER_KEY = 'get_your_own_OpIi9ZULNHzrESv6T2vL'\r\n\r\nexport const SATELLITE_STYLE_URL = 'cdt:satellite'\r\nexport const STREETS_STYLE_URL = 'cdt:streets'\r\n\r\nconst MAPTILER_ATTRIBUTION = '<a href=\"https://www.maptiler.com/copyright/\" target=\"_blank\">© MapTiler</a> <a href=\"https://www.openstreetmap.org/copyright\" target=\"_blank\">© OpenStreetMap contributors</a>'\r\nconst ESRI_ATTRIBUTION = 'Imagery © <a href=\"https://www.esri.com/\" target=\"_blank\">Esri</a>, Maxar, Earthstar Geographics'\r\nconst TERRARIUM_ATTRIBUTION = '<a href=\"https://registry.opendata.aws/terrain-tiles/\" target=\"_blank\">Terrain Tiles</a>, <a href=\"https://earth.jaxa.jp/en/data/policy/\" target=\"_blank\">AW3D30 (JAXA)</a>'\r\n\r\nconst ESRI_IMAGERY_TILES = 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}'\r\nconst TERRARIUM_TILES = 'https://s3.amazonaws.com/elevation-tiles-prod/terrarium/{z}/{x}/{y}.png'\r\nconst OPENMAPTILES_GLYPHS = 'https://fonts.openmaptiles.org/{fontstack}/{range}.pbf'\r\n\r\n/** Falls back to the placeholder so a missing key degrades the map instead of breaking it. */\r\nexport function maptilerKeyOrPlaceholder(key?: string | null): string {\r\n const trimmed = (key ?? '').trim()\r\n return trimmed || MAPTILER_PLACEHOLDER_KEY\r\n}\r\n\r\nconst hasOwnKey = (key?: string | null): boolean => Boolean((key ?? '').trim())\r\n\r\nfunction satelliteImagerySource(key?: string | null) {\r\n if (!hasOwnKey(key)) {\r\n return {\r\n type: 'raster' as const,\r\n tiles: [ESRI_IMAGERY_TILES],\r\n tileSize: 256,\r\n maxzoom: 19,\r\n attribution: ESRI_ATTRIBUTION,\r\n }\r\n }\r\n return {\r\n type: 'raster' as const,\r\n tiles: [`https://api.maptiler.com/tiles/satellite-v2/{z}/{x}/{y}.jpg?key=${(key ?? '').trim()}`],\r\n tileSize: 256,\r\n maxzoom: 16,\r\n attribution: MAPTILER_ATTRIBUTION,\r\n }\r\n}\r\n\r\nfunction elevationSource(key?: string | null) {\r\n if (!hasOwnKey(key)) {\r\n return {\r\n type: 'raster-dem' as const,\r\n tiles: [TERRARIUM_TILES],\r\n encoding: 'terrarium' as const,\r\n tileSize: 256,\r\n maxzoom: 12,\r\n attribution: TERRARIUM_ATTRIBUTION,\r\n }\r\n }\r\n return {\r\n type: 'raster-dem' as const,\r\n url: `https://api.maptiler.com/tiles/terrain-rgb-v2/tiles.json?key=${(key ?? '').trim()}`,\r\n tileSize: 256,\r\n }\r\n}\r\n\r\n/**\r\n * Build the Satellite base style for a deployment's own MapTiler key.\r\n * Without a key it falls back to Esri imagery, terrarium elevation and the\r\n * OpenMapTiles font CDN, so nothing is billed to another account.\r\n */\r\nexport function buildSatelliteStyle(key?: string | null): StyleSpecification {\r\n return {\r\n version: 8,\r\n id: 'satellite',\r\n name: 'Satellite',\r\n glyphs: hasOwnKey(key)\r\n ? `https://api.maptiler.com/fonts/{fontstack}/{range}.pbf?key=${(key ?? '').trim()}`\r\n : OPENMAPTILES_GLYPHS,\r\n sources: {\r\n 'raster-tiles': satelliteImagerySource(key),\r\n terrainSource: elevationSource(key),\r\n hillshadeSource: elevationSource(key),\r\n },\r\n layers: [\r\n {\r\n id: 'background',\r\n type: 'background',\r\n layout: { visibility: 'visible' },\r\n paint: { 'background-color': '#1a1a1a' },\r\n },\r\n {\r\n id: 'simple-tiles',\r\n type: 'raster',\r\n source: 'raster-tiles',\r\n minzoom: 0,\r\n maxzoom: 24,\r\n paint: { 'raster-brightness-min': 0.15 },\r\n },\r\n {\r\n id: 'hillshade',\r\n type: 'hillshade',\r\n source: 'hillshadeSource',\r\n layout: { visibility: 'visible' },\r\n paint: {\r\n 'hillshade-shadow-color': 'rgba(0, 0, 0, 0.3)',\r\n 'hillshade-highlight-color': 'rgba(255, 255, 255, 0.3)',\r\n 'hillshade-exaggeration': 0.5,\r\n },\r\n },\r\n ],\r\n sky: {\r\n 'atmosphere-blend': ['interpolate', ['linear'], ['zoom'], 0, 1, 5, 1, 7, 0],\r\n },\r\n light: {\r\n anchor: 'viewport',\r\n color: '#ffffff',\r\n intensity: 0.6,\r\n position: [1.15, 0, 0],\r\n },\r\n terrain: { source: 'terrainSource', exaggeration: 0.6 },\r\n } as StyleSpecification\r\n}\r\n\r\nconst LEGACY_STATIC_STYLES: Record<string, string> = {\r\n 'mapStyles/satellite.json': SATELLITE_STYLE_URL,\r\n 'mapStyles/streets.json': STREETS_STYLE_URL,\r\n}\r\n\r\nfunction normalizeStyleUrl(url: string): string {\r\n const legacy = Object.keys(LEGACY_STATIC_STYLES).find((path) => url.endsWith(path))\r\n return legacy ? LEGACY_STATIC_STYLES[legacy] : url\r\n}\r\n\r\n/**\r\n * Resolve a catalog entry into something `<Map mapStyle>` accepts: a built style\r\n * object for the built-in Satellite, a keyed URL for Streets, and any other URL\r\n * (organization-supplied styles included) unchanged.\r\n */\r\nexport function resolveStyleSpec(\r\n style: MapStyle,\r\n key?: string | null\r\n): string | StyleSpecification {\r\n const url = normalizeStyleUrl((style?.url ?? '').trim())\r\n\r\n if (url === SATELLITE_STYLE_URL) return buildSatelliteStyle(key)\r\n if (url === STREETS_STYLE_URL) {\r\n return `https://api.maptiler.com/maps/streets-v2/style.json?key=${maptilerKeyOrPlaceholder(key)}`\r\n }\r\n return url\r\n}\r\n"],"mappings":"AAOO,MAAM,2BAA2B;AAEjC,MAAM,sBAAsB;AAC5B,MAAM,oBAAoB;AAEjC,MAAM,uBAAuB;AAC7B,MAAM,mBAAmB;AACzB,MAAM,wBAAwB;AAE9B,MAAM,qBAAqB;AAC3B,MAAM,kBAAkB;AACxB,MAAM,sBAAsB;AAGrB,SAAS,yBAAyB,KAA6B;AACpE,QAAM,WAAW,oBAAO,IAAI,KAAK;AACjC,SAAO,WAAW;AACpB;AAEA,MAAM,YAAY,CAAC,QAAiC,SAAS,oBAAO,IAAI,KAAK,CAAC;AAE9E,SAAS,uBAAuB,KAAqB;AACnD,MAAI,CAAC,UAAU,GAAG,GAAG;AACnB,WAAO;AAAA,MACL,MAAM;AAAA,MACN,OAAO,CAAC,kBAAkB;AAAA,MAC1B,UAAU;AAAA,MACV,SAAS;AAAA,MACT,aAAa;AAAA,IACf;AAAA,EACF;AACA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO,CAAC,oEAAoE,oBAAO,IAAI,KAAK,CAAC,EAAE;AAAA,IAC/F,UAAU;AAAA,IACV,SAAS;AAAA,IACT,aAAa;AAAA,EACf;AACF;AAEA,SAAS,gBAAgB,KAAqB;AAC5C,MAAI,CAAC,UAAU,GAAG,GAAG;AACnB,WAAO;AAAA,MACL,MAAM;AAAA,MACN,OAAO,CAAC,eAAe;AAAA,MACvB,UAAU;AAAA,MACV,UAAU;AAAA,MACV,SAAS;AAAA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,EAAE,QAAQ,iBAAiB,cAAc,IAAI;AAAA,EACxD;AACF;AAEA,MAAM,uBAA+C;AAAA,EACnD,4BAA4B;AAAA,EAC5B,0BAA0B;AAC5B;AAEA,SAAS,kBAAkB,KAAqB;AAC9C,QAAM,SAAS,OAAO,KAAK,oBAAoB,EAAE,KAAK,CAAC,SAAS,IAAI,SAAS,IAAI,CAAC;AAClF,SAAO,SAAS,qBAAqB,MAAM,IAAI;AACjD;AAOO,SAAS,iBACd,OACA,KAC6B;
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/core/components/viewers/map/utils/mapStyleSpec.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport type { MapStyle } from '../../../../types/map'\r\nimport type { StyleSpecification } from 'maplibre-gl'\r\n\r\n/** MapTiler's public demo key. Honoured on localhost only, so dev works without an account. */\r\nexport const MAPTILER_PLACEHOLDER_KEY = 'get_your_own_OpIi9ZULNHzrESv6T2vL'\r\n\r\nexport const SATELLITE_STYLE_URL = 'cdt:satellite'\r\nexport const STREETS_STYLE_URL = 'cdt:streets'\r\n\r\nconst MAPTILER_ATTRIBUTION = '<a href=\"https://www.maptiler.com/copyright/\" target=\"_blank\">© MapTiler</a> <a href=\"https://www.openstreetmap.org/copyright\" target=\"_blank\">© OpenStreetMap contributors</a>'\r\nconst ESRI_ATTRIBUTION = 'Imagery © <a href=\"https://www.esri.com/\" target=\"_blank\">Esri</a>, Maxar, Earthstar Geographics'\r\nconst TERRARIUM_ATTRIBUTION = '<a href=\"https://registry.opendata.aws/terrain-tiles/\" target=\"_blank\">Terrain Tiles</a>, <a href=\"https://earth.jaxa.jp/en/data/policy/\" target=\"_blank\">AW3D30 (JAXA)</a>'\r\n\r\nconst ESRI_IMAGERY_TILES = 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}'\r\nconst TERRARIUM_TILES = 'https://s3.amazonaws.com/elevation-tiles-prod/terrarium/{z}/{x}/{y}.png'\r\nconst OPENMAPTILES_GLYPHS = 'https://fonts.openmaptiles.org/{fontstack}/{range}.pbf'\r\n\r\n/** Falls back to the placeholder so a missing key degrades the map instead of breaking it. */\r\nexport function maptilerKeyOrPlaceholder(key?: string | null): string {\r\n const trimmed = (key ?? '').trim()\r\n return trimmed || MAPTILER_PLACEHOLDER_KEY\r\n}\r\n\r\nconst hasOwnKey = (key?: string | null): boolean => Boolean((key ?? '').trim())\r\n\r\nconst LOCALHOST_HOSTNAMES = new Set(['localhost', '127.0.0.1', '::1', '[::1]'])\r\n\r\n/** False during SSR: every caller adds sources from the browser, so no placeholder is needed server-side. */\r\nexport function isLocalhostOrigin(): boolean {\r\n if (typeof window === 'undefined') return false\r\n return LOCALHOST_HOSTNAMES.has(window.location.hostname)\r\n}\r\n\r\n/**\r\n * The key to sign a MapTiler request with, or null when the caller must not call MapTiler:\r\n * the placeholder is honoured on localhost only, so elsewhere a missing key earns a 403.\r\n */\r\nexport function maptilerKeyForRequest(key?: string | null): string | null {\r\n const trimmed = (key ?? '').trim()\r\n if (trimmed) return trimmed\r\n return isLocalhostOrigin() ? MAPTILER_PLACEHOLDER_KEY : null\r\n}\r\n\r\nfunction satelliteImagerySource(key?: string | null) {\r\n if (!hasOwnKey(key)) {\r\n return {\r\n type: 'raster' as const,\r\n tiles: [ESRI_IMAGERY_TILES],\r\n tileSize: 256,\r\n maxzoom: 19,\r\n attribution: ESRI_ATTRIBUTION,\r\n }\r\n }\r\n return {\r\n type: 'raster' as const,\r\n tiles: [`https://api.maptiler.com/tiles/satellite-v2/{z}/{x}/{y}.jpg?key=${(key ?? '').trim()}`],\r\n tileSize: 256,\r\n maxzoom: 16,\r\n attribution: MAPTILER_ATTRIBUTION,\r\n }\r\n}\r\n\r\nfunction elevationSource(key?: string | null) {\r\n if (!hasOwnKey(key)) {\r\n return {\r\n type: 'raster-dem' as const,\r\n tiles: [TERRARIUM_TILES],\r\n encoding: 'terrarium' as const,\r\n tileSize: 256,\r\n maxzoom: 12,\r\n attribution: TERRARIUM_ATTRIBUTION,\r\n }\r\n }\r\n return {\r\n type: 'raster-dem' as const,\r\n url: `https://api.maptiler.com/tiles/terrain-rgb-v2/tiles.json?key=${(key ?? '').trim()}`,\r\n tileSize: 256,\r\n }\r\n}\r\n\r\n/**\r\n * Build the Satellite base style for a deployment's own MapTiler key.\r\n * Without a key it falls back to Esri imagery, terrarium elevation and the\r\n * OpenMapTiles font CDN, so nothing is billed to another account.\r\n */\r\nexport function buildSatelliteStyle(key?: string | null): StyleSpecification {\r\n return {\r\n version: 8,\r\n id: 'satellite',\r\n name: 'Satellite',\r\n glyphs: hasOwnKey(key)\r\n ? `https://api.maptiler.com/fonts/{fontstack}/{range}.pbf?key=${(key ?? '').trim()}`\r\n : OPENMAPTILES_GLYPHS,\r\n sources: {\r\n 'raster-tiles': satelliteImagerySource(key),\r\n terrainSource: elevationSource(key),\r\n hillshadeSource: elevationSource(key),\r\n },\r\n layers: [\r\n {\r\n id: 'background',\r\n type: 'background',\r\n layout: { visibility: 'visible' },\r\n paint: { 'background-color': '#1a1a1a' },\r\n },\r\n {\r\n id: 'simple-tiles',\r\n type: 'raster',\r\n source: 'raster-tiles',\r\n minzoom: 0,\r\n maxzoom: 24,\r\n paint: { 'raster-brightness-min': 0.15 },\r\n },\r\n {\r\n id: 'hillshade',\r\n type: 'hillshade',\r\n source: 'hillshadeSource',\r\n layout: { visibility: 'visible' },\r\n paint: {\r\n 'hillshade-shadow-color': 'rgba(0, 0, 0, 0.3)',\r\n 'hillshade-highlight-color': 'rgba(255, 255, 255, 0.3)',\r\n 'hillshade-exaggeration': 0.5,\r\n },\r\n },\r\n ],\r\n sky: {\r\n 'atmosphere-blend': ['interpolate', ['linear'], ['zoom'], 0, 1, 5, 1, 7, 0],\r\n },\r\n light: {\r\n anchor: 'viewport',\r\n color: '#ffffff',\r\n intensity: 0.6,\r\n position: [1.15, 0, 0],\r\n },\r\n terrain: { source: 'terrainSource', exaggeration: 0.6 },\r\n } as StyleSpecification\r\n}\r\n\r\nconst LEGACY_STATIC_STYLES: Record<string, string> = {\r\n 'mapStyles/satellite.json': SATELLITE_STYLE_URL,\r\n 'mapStyles/streets.json': STREETS_STYLE_URL,\r\n}\r\n\r\nfunction normalizeStyleUrl(url: string): string {\r\n const legacy = Object.keys(LEGACY_STATIC_STYLES).find((path) => url.endsWith(path))\r\n return legacy ? LEGACY_STATIC_STYLES[legacy] : url\r\n}\r\n\r\n/**\r\n * Resolve a catalog entry into something `<Map mapStyle>` accepts: a built style\r\n * object for the built-in Satellite, a keyed URL for Streets, and any other URL\r\n * (organization-supplied styles included) unchanged.\r\n */\r\nexport function resolveStyleSpec(\r\n style: MapStyle,\r\n key?: string | null\r\n): string | StyleSpecification {\r\n const url = normalizeStyleUrl((style?.url ?? '').trim())\r\n\r\n if (url === SATELLITE_STYLE_URL) return buildSatelliteStyle(key)\r\n if (url === STREETS_STYLE_URL) {\r\n return `https://api.maptiler.com/maps/streets-v2/style.json?key=${maptilerKeyOrPlaceholder(key)}`\r\n }\r\n return url\r\n}\r\n"],"mappings":"AAOO,MAAM,2BAA2B;AAEjC,MAAM,sBAAsB;AAC5B,MAAM,oBAAoB;AAEjC,MAAM,uBAAuB;AAC7B,MAAM,mBAAmB;AACzB,MAAM,wBAAwB;AAE9B,MAAM,qBAAqB;AAC3B,MAAM,kBAAkB;AACxB,MAAM,sBAAsB;AAGrB,SAAS,yBAAyB,KAA6B;AACpE,QAAM,WAAW,oBAAO,IAAI,KAAK;AACjC,SAAO,WAAW;AACpB;AAEA,MAAM,YAAY,CAAC,QAAiC,SAAS,oBAAO,IAAI,KAAK,CAAC;AAE9E,MAAM,sBAAsB,oBAAI,IAAI,CAAC,aAAa,aAAa,OAAO,OAAO,CAAC;AAGvE,SAAS,oBAA6B;AAC3C,MAAI,OAAO,WAAW,YAAa,QAAO;AAC1C,SAAO,oBAAoB,IAAI,OAAO,SAAS,QAAQ;AACzD;AAMO,S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