@collabdt/core 0.6.0 → 0.8.0

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.
Files changed (143) hide show
  1. package/dist/core/components/AppSidebarContent.d.ts.map +1 -1
  2. package/dist/core/components/AppSidebarContent.js +3 -2
  3. package/dist/core/components/AppSidebarContent.js.map +1 -1
  4. package/dist/core/components/authentication/AuthPage.d.ts.map +1 -1
  5. package/dist/core/components/authentication/AuthPage.js +33 -13
  6. package/dist/core/components/authentication/AuthPage.js.map +1 -1
  7. package/dist/core/components/viewers/map/MapViewer.d.ts.map +1 -1
  8. package/dist/core/components/viewers/map/MapViewer.js +4 -2
  9. package/dist/core/components/viewers/map/MapViewer.js.map +1 -1
  10. package/dist/core/components/viewers/map/src/MapLayers/index.js +1 -1
  11. package/dist/core/components/viewers/map/src/MapLayers/index.js.map +1 -1
  12. package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/index.d.ts +3 -1
  13. package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/index.d.ts.map +1 -1
  14. package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/index.js +27 -7
  15. package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/index.js.map +1 -1
  16. package/dist/core/components/viewers/map/src/MapLayers/src/CountryLayer/countryLayerUtils.d.ts +6 -0
  17. package/dist/core/components/viewers/map/src/MapLayers/src/CountryLayer/countryLayerUtils.d.ts.map +1 -1
  18. package/dist/core/components/viewers/map/src/MapLayers/src/CountryLayer/countryLayerUtils.js +10 -1
  19. package/dist/core/components/viewers/map/src/MapLayers/src/CountryLayer/countryLayerUtils.js.map +1 -1
  20. package/dist/core/components/viewers/map/src/MapLayers/src/CountryLayer/index.d.ts.map +1 -1
  21. package/dist/core/components/viewers/map/src/MapLayers/src/CountryLayer/index.js +67 -68
  22. package/dist/core/components/viewers/map/src/MapLayers/src/CountryLayer/index.js.map +1 -1
  23. package/dist/core/components/viewers/map/src/MapLayers/src/CountryLayer/useCameraSubdivision.d.ts +16 -0
  24. package/dist/core/components/viewers/map/src/MapLayers/src/CountryLayer/useCameraSubdivision.d.ts.map +1 -0
  25. package/dist/core/components/viewers/map/src/MapLayers/src/CountryLayer/useCameraSubdivision.js +44 -0
  26. package/dist/core/components/viewers/map/src/MapLayers/src/CountryLayer/useCameraSubdivision.js.map +1 -0
  27. package/dist/core/components/viewers/map/src/MapLayers/src/CountryLayer/useSubdivisionHover.d.ts +11 -0
  28. package/dist/core/components/viewers/map/src/MapLayers/src/CountryLayer/useSubdivisionHover.d.ts.map +1 -0
  29. package/dist/core/components/viewers/map/src/MapLayers/src/CountryLayer/useSubdivisionHover.js +38 -0
  30. package/dist/core/components/viewers/map/src/MapLayers/src/CountryLayer/useSubdivisionHover.js.map +1 -0
  31. package/dist/core/components/viewers/map/utils/mapStyleCatalog.d.ts +2 -1
  32. package/dist/core/components/viewers/map/utils/mapStyleCatalog.d.ts.map +1 -1
  33. package/dist/core/components/viewers/map/utils/mapStyleCatalog.js +3 -2
  34. package/dist/core/components/viewers/map/utils/mapStyleCatalog.js.map +1 -1
  35. package/dist/core/components/viewers/map/utils/mapStyleSpec.d.ts +21 -0
  36. package/dist/core/components/viewers/map/utils/mapStyleSpec.d.ts.map +1 -0
  37. package/dist/core/components/viewers/map/utils/mapStyleSpec.js +125 -0
  38. package/dist/core/components/viewers/map/utils/mapStyleSpec.js.map +1 -0
  39. package/dist/core/components/viewers/plugins/src/PluginCard.d.ts.map +1 -1
  40. package/dist/core/components/viewers/plugins/src/PluginCard.js +19 -36
  41. package/dist/core/components/viewers/plugins/src/PluginCard.js.map +1 -1
  42. package/dist/core/plugins/hello-bim/src/components/SpaceDialog.d.ts.map +1 -0
  43. package/dist/core/plugins/hello-bim/{components → src/components}/SpaceDialog.js +3 -3
  44. package/dist/core/plugins/hello-bim/src/components/SpaceDialog.js.map +1 -0
  45. package/dist/core/plugins/hello-bim/{components → src/components}/SpacesLegend.d.ts +1 -1
  46. package/dist/core/plugins/hello-bim/src/components/SpacesLegend.d.ts.map +1 -0
  47. package/dist/core/plugins/hello-bim/{components → src/components}/SpacesLegend.js +1 -1
  48. package/dist/core/plugins/hello-bim/src/components/SpacesLegend.js.map +1 -0
  49. package/dist/core/plugins/hello-bim/src/components/SpacesTab.d.ts.map +1 -0
  50. package/dist/core/plugins/hello-bim/{components → src/components}/SpacesTab.js +5 -5
  51. package/dist/core/plugins/hello-bim/src/components/SpacesTab.js.map +1 -0
  52. package/dist/core/plugins/hello-bim/{components → src/components}/SpacesTool.d.ts +1 -2
  53. package/dist/core/plugins/hello-bim/src/components/SpacesTool.d.ts.map +1 -0
  54. package/dist/core/plugins/hello-bim/{components → src/components}/SpacesTool.js +2 -2
  55. package/dist/core/plugins/hello-bim/src/components/SpacesTool.js.map +1 -0
  56. package/dist/core/plugins/hello-bim/src/components/icons.d.ts.map +1 -0
  57. package/dist/core/plugins/hello-bim/src/components/icons.js.map +1 -0
  58. package/dist/core/plugins/hello-bim/src/index.d.ts +10 -0
  59. package/dist/core/plugins/hello-bim/src/index.d.ts.map +1 -0
  60. package/dist/core/plugins/hello-bim/{index.js → src/index.js} +2 -3
  61. package/dist/core/plugins/hello-bim/src/index.js.map +1 -0
  62. package/dist/core/plugins/hello-bim/{spaces.d.ts → src/spaces.d.ts} +1 -1
  63. package/dist/core/plugins/hello-bim/src/spaces.d.ts.map +1 -0
  64. package/dist/core/plugins/hello-bim/{spaces.js → src/spaces.js} +4 -4
  65. package/dist/core/plugins/hello-bim/src/spaces.js.map +1 -0
  66. package/dist/core/plugins/hello-map/{components → src/components}/MapTool.d.ts +1 -2
  67. package/dist/core/plugins/hello-map/src/components/MapTool.d.ts.map +1 -0
  68. package/dist/core/plugins/hello-map/{components → src/components}/MapTool.js +3 -3
  69. package/dist/core/plugins/hello-map/src/components/MapTool.js.map +1 -0
  70. package/dist/core/plugins/hello-map/src/components/MarkerDialog.d.ts.map +1 -0
  71. package/dist/core/plugins/hello-map/{components → src/components}/MarkerDialog.js +2 -2
  72. package/dist/core/plugins/hello-map/src/components/MarkerDialog.js.map +1 -0
  73. package/dist/core/plugins/hello-map/{components → src/components}/MarkersLayer.d.ts +1 -1
  74. package/dist/core/plugins/hello-map/src/components/MarkersLayer.d.ts.map +1 -0
  75. package/dist/core/plugins/hello-map/{components → src/components}/MarkersLayer.js +1 -1
  76. package/dist/core/plugins/hello-map/src/components/MarkersLayer.js.map +1 -0
  77. package/dist/core/plugins/hello-map/{components → src/components}/MarkersLegend.d.ts +1 -1
  78. package/dist/core/plugins/hello-map/src/components/MarkersLegend.d.ts.map +1 -0
  79. package/dist/core/plugins/hello-map/{components → src/components}/MarkersLegend.js +1 -1
  80. package/dist/core/plugins/hello-map/src/components/MarkersLegend.js.map +1 -0
  81. package/dist/core/plugins/hello-map/{components → src/components}/MarkersPage.d.ts +1 -1
  82. package/dist/core/plugins/hello-map/src/components/MarkersPage.d.ts.map +1 -0
  83. package/dist/core/plugins/hello-map/{components → src/components}/MarkersPage.js +1 -1
  84. package/dist/core/plugins/hello-map/src/components/MarkersPage.js.map +1 -0
  85. package/dist/core/plugins/hello-map/src/components/MarkersTab.d.ts.map +1 -0
  86. package/dist/core/plugins/hello-map/{components → src/components}/MarkersTab.js +4 -4
  87. package/dist/core/plugins/hello-map/src/components/MarkersTab.js.map +1 -0
  88. package/dist/core/plugins/hello-map/src/index.d.ts +10 -0
  89. package/dist/core/plugins/hello-map/src/index.d.ts.map +1 -0
  90. package/dist/core/plugins/hello-map/{index.js → src/index.js} +2 -3
  91. package/dist/core/plugins/hello-map/src/index.js.map +1 -0
  92. package/dist/core/plugins/hello-map/src/markers.d.ts.map +1 -0
  93. package/dist/core/plugins/hello-map/{markers.js → src/markers.js} +3 -3
  94. package/dist/core/plugins/hello-map/src/markers.js.map +1 -0
  95. package/dist/core/plugins/host/context.js.map +1 -1
  96. package/dist/core/plugins/host/pluginIcon.js.map +1 -1
  97. package/dist/core/plugins/host/runtimeShims.js.map +1 -1
  98. package/dist/core/plugins/installed.js +2 -2
  99. package/dist/core/plugins/installed.js.map +1 -1
  100. package/dist/core/plugins/manifests.js.map +1 -1
  101. package/dist/core/plugins/sdk/types.d.ts +9 -4
  102. package/dist/core/plugins/sdk/types.d.ts.map +1 -1
  103. package/dist/core/plugins/sdk/types.js.map +1 -1
  104. package/package.json +2 -1
  105. package/dist/core/plugins/hello-bim/components/SpaceDialog.d.ts.map +0 -1
  106. package/dist/core/plugins/hello-bim/components/SpaceDialog.js.map +0 -1
  107. package/dist/core/plugins/hello-bim/components/SpacesLegend.d.ts.map +0 -1
  108. package/dist/core/plugins/hello-bim/components/SpacesLegend.js.map +0 -1
  109. package/dist/core/plugins/hello-bim/components/SpacesTab.d.ts.map +0 -1
  110. package/dist/core/plugins/hello-bim/components/SpacesTab.js.map +0 -1
  111. package/dist/core/plugins/hello-bim/components/SpacesTool.d.ts.map +0 -1
  112. package/dist/core/plugins/hello-bim/components/SpacesTool.js.map +0 -1
  113. package/dist/core/plugins/hello-bim/components/icons.d.ts.map +0 -1
  114. package/dist/core/plugins/hello-bim/components/icons.js.map +0 -1
  115. package/dist/core/plugins/hello-bim/index.d.ts +0 -7
  116. package/dist/core/plugins/hello-bim/index.d.ts.map +0 -1
  117. package/dist/core/plugins/hello-bim/index.js.map +0 -1
  118. package/dist/core/plugins/hello-bim/spaces.d.ts.map +0 -1
  119. package/dist/core/plugins/hello-bim/spaces.js.map +0 -1
  120. package/dist/core/plugins/hello-map/components/MapTool.d.ts.map +0 -1
  121. package/dist/core/plugins/hello-map/components/MapTool.js.map +0 -1
  122. package/dist/core/plugins/hello-map/components/MarkerDialog.d.ts.map +0 -1
  123. package/dist/core/plugins/hello-map/components/MarkerDialog.js.map +0 -1
  124. package/dist/core/plugins/hello-map/components/MarkersLayer.d.ts.map +0 -1
  125. package/dist/core/plugins/hello-map/components/MarkersLayer.js.map +0 -1
  126. package/dist/core/plugins/hello-map/components/MarkersLegend.d.ts.map +0 -1
  127. package/dist/core/plugins/hello-map/components/MarkersLegend.js.map +0 -1
  128. package/dist/core/plugins/hello-map/components/MarkersPage.d.ts.map +0 -1
  129. package/dist/core/plugins/hello-map/components/MarkersPage.js.map +0 -1
  130. package/dist/core/plugins/hello-map/components/MarkersTab.d.ts.map +0 -1
  131. package/dist/core/plugins/hello-map/components/MarkersTab.js.map +0 -1
  132. package/dist/core/plugins/hello-map/index.d.ts +0 -7
  133. package/dist/core/plugins/hello-map/index.d.ts.map +0 -1
  134. package/dist/core/plugins/hello-map/index.js.map +0 -1
  135. package/dist/core/plugins/hello-map/markers.d.ts.map +0 -1
  136. package/dist/core/plugins/hello-map/markers.js.map +0 -1
  137. /package/dist/core/plugins/hello-bim/{components → src/components}/SpaceDialog.d.ts +0 -0
  138. /package/dist/core/plugins/hello-bim/{components → src/components}/SpacesTab.d.ts +0 -0
  139. /package/dist/core/plugins/hello-bim/{components → src/components}/icons.d.ts +0 -0
  140. /package/dist/core/plugins/hello-bim/{components → src/components}/icons.js +0 -0
  141. /package/dist/core/plugins/hello-map/{components → src/components}/MarkerDialog.d.ts +0 -0
  142. /package/dist/core/plugins/hello-map/{components → src/components}/MarkersTab.d.ts +0 -0
  143. /package/dist/core/plugins/hello-map/{markers.d.ts → src/markers.d.ts} +0 -0
@@ -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 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\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 addBuildingLayer(map: any, hiddenBimOsmIds: string[], colourExpr: PaintExpression) {\r\n try {\r\n if (!map.getSource(\"openmaptiles\")) return;\r\n if (map.getLayer(LAYER_ID)) return;\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: \"openmaptiles\",\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() {\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);\r\n }\r\n\r\n const onStyleLoad = () => addBuildingLayer(map, hiddenBimOsmIds, colourExprRef.current);\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 } catch {\r\n // Map may have been destroyed before cleanup runs\r\n }\r\n };\r\n }, [map, hiddenBimOsmIds]);\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":";;;;;;;;;;;;;;;;;;;;AAgRI,mBACE,KADF;AA1QJ,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,OAAO,2BAA2B;AAElC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,6BAA6B;AAItC,MAAM,WAAW;AAEjB,SAAS,mBAAmB;AAC1B,SAAO;AAAA,IACL;AAAA,IACA,CAAC,MAAM,CAAC,OAAO,SAAS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,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 { maptilerKeyOrPlaceholder } 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\nfunction resolveBuildingSource(map: any, maptilerKey?: string): string {\n if (maptilerKey?.trim()) return addOwnBuildingSource(map, maptilerKey);\n\n const reusable = REUSABLE_SOURCE_IDS.find((id) => map.getSource(id));\n return reusable ?? addOwnBuildingSource(map, maptilerKeyOrPlaceholder(maptilerKey));\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\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":";;;;;;;;;;;;;;;;;;;;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,CAA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AA2B,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"]}
@@ -5,5 +5,11 @@ export declare const ARCGIS_BASE = "https://services.arcgis.com/P3ePLMYs2RVChkJx
5
5
  * MapLibre paint expression never receives a NaN channel.
6
6
  */
7
7
  export declare function hexToRgba(hex: string, opacity: number): string;
8
+ /**
9
+ * Derive an ISO 3166-2 code from an ArcGIS admin-division feature's properties.
10
+ * `ISO_CODE` arrives as the country code concatenated with the subdivision
11
+ * (`CAON`), so the prefix is stripped and re-joined with a hyphen (`CA-ON`).
12
+ */
13
+ export declare function subdivisionCodeFromFeature(properties?: Record<string, unknown> | null): string | null;
8
14
  export declare const buildSubdivisionUrl: (countryCode: string, base?: string) => string;
9
15
  //# sourceMappingURL=countryLayerUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"countryLayerUtils.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/CountryLayer/countryLayerUtils.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,WAAW,2HAA2H,CAAA;AAEnJ;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAY9D;AAED,eAAO,MAAM,mBAAmB,GAAI,aAAa,MAAM,EAAE,OAAM,MAAoB,KAAG,MAOrF,CAAA"}
1
+ {"version":3,"file":"countryLayerUtils.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/CountryLayer/countryLayerUtils.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,WAAW,2HAA2H,CAAA;AAEnJ;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAY9D;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CACxC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAC1C,MAAM,GAAG,IAAI,CAOf;AAED,eAAO,MAAM,mBAAmB,GAAI,aAAa,MAAM,EAAE,OAAM,MAAoB,KAAG,MAOrF,CAAA"}
@@ -12,6 +12,14 @@ function hexToRgba(hex, opacity) {
12
12
  }
13
13
  return `rgba(${r}, ${g}, ${b}, ${opacity})`;
14
14
  }
15
+ function subdivisionCodeFromFeature(properties) {
16
+ const isoCC = properties == null ? void 0 : properties.ISO_CC;
17
+ const isoCode = properties == null ? void 0 : properties.ISO_CODE;
18
+ if (isoCC && isoCode && isoCode.startsWith(isoCC)) {
19
+ return `${isoCC}-${isoCode.slice(isoCC.length)}`;
20
+ }
21
+ return isoCode || (properties == null ? void 0 : properties.NAME) || null;
22
+ }
15
23
  const buildSubdivisionUrl = (countryCode, base = ARCGIS_BASE) => {
16
24
  const params = new URLSearchParams({
17
25
  outFields: "NAME,ISO_CC,ISO_CODE,ADMINTYPE",
@@ -23,6 +31,7 @@ const buildSubdivisionUrl = (countryCode, base = ARCGIS_BASE) => {
23
31
  export {
24
32
  ARCGIS_BASE,
25
33
  buildSubdivisionUrl,
26
- hexToRgba
34
+ hexToRgba,
35
+ subdivisionCodeFromFeature
27
36
  };
28
37
  //# sourceMappingURL=countryLayerUtils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/CountryLayer/countryLayerUtils.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nexport const ARCGIS_BASE = 'https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/World_Administrative_Divisions/FeatureServer/0/query'\r\n\r\n/**\r\n * Convert a hex colour (`#rgb`, `#rrggbb`, or without `#`) to an `rgba()` string.\r\n * Expands 3-digit shorthand and falls back to black on malformed input so the\r\n * MapLibre paint expression never receives a NaN channel.\r\n */\r\nexport function hexToRgba(hex: string, opacity: number): string {\r\n let clean = (hex ?? '').replace('#', '').trim()\r\n if (clean.length === 3) {\r\n clean = clean[0] + clean[0] + clean[1] + clean[1] + clean[2] + clean[2]\r\n }\r\n const r = parseInt(clean.slice(0, 2), 16)\r\n const g = parseInt(clean.slice(2, 4), 16)\r\n const b = parseInt(clean.slice(4, 6), 16)\r\n if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {\r\n return `rgba(0, 0, 0, ${opacity})`\r\n }\r\n return `rgba(${r}, ${g}, ${b}, ${opacity})`\r\n}\r\n\r\nexport const buildSubdivisionUrl = (countryCode: string, base: string = ARCGIS_BASE): string => {\r\n const params = new URLSearchParams({\r\n outFields: 'NAME,ISO_CC,ISO_CODE,ADMINTYPE',\r\n where: `ISO_CC='${countryCode}'`,\r\n f: 'geojson',\r\n })\r\n return `${base}?${params.toString()}`\r\n}\r\n"],"mappings":"AAGO,MAAM,cAAc;AAOpB,SAAS,UAAU,KAAa,SAAyB;AAC9D,MAAI,SAAS,oBAAO,IAAI,QAAQ,KAAK,EAAE,EAAE,KAAK;AAC9C,MAAI,MAAM,WAAW,GAAG;AACtB,YAAQ,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,MAAM,CAAC;AAAA,EACxE;AACA,QAAM,IAAI,SAAS,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE;AACxC,QAAM,IAAI,SAAS,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE;AACxC,QAAM,IAAI,SAAS,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE;AACxC,MAAI,OAAO,MAAM,CAAC,KAAK,OAAO,MAAM,CAAC,KAAK,OAAO,MAAM,CAAC,GAAG;AACzD,WAAO,iBAAiB,OAAO;AAAA,EACjC;AACA,SAAO,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,OAAO;AAC1C;AAEO,MAAM,sBAAsB,CAAC,aAAqB,OAAe,gBAAwB;AAC9F,QAAM,SAAS,IAAI,gBAAgB;AAAA,IACjC,WAAW;AAAA,IACX,OAAO,WAAW,WAAW;AAAA,IAC7B,GAAG;AAAA,EACL,CAAC;AACD,SAAO,GAAG,IAAI,IAAI,OAAO,SAAS,CAAC;AACrC;","names":[]}
1
+ {"version":3,"sources":["../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/CountryLayer/countryLayerUtils.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nexport const ARCGIS_BASE = 'https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/World_Administrative_Divisions/FeatureServer/0/query'\r\n\r\n/**\r\n * Convert a hex colour (`#rgb`, `#rrggbb`, or without `#`) to an `rgba()` string.\r\n * Expands 3-digit shorthand and falls back to black on malformed input so the\r\n * MapLibre paint expression never receives a NaN channel.\r\n */\r\nexport function hexToRgba(hex: string, opacity: number): string {\r\n let clean = (hex ?? '').replace('#', '').trim()\r\n if (clean.length === 3) {\r\n clean = clean[0] + clean[0] + clean[1] + clean[1] + clean[2] + clean[2]\r\n }\r\n const r = parseInt(clean.slice(0, 2), 16)\r\n const g = parseInt(clean.slice(2, 4), 16)\r\n const b = parseInt(clean.slice(4, 6), 16)\r\n if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {\r\n return `rgba(0, 0, 0, ${opacity})`\r\n }\r\n return `rgba(${r}, ${g}, ${b}, ${opacity})`\r\n}\r\n\r\n/**\r\n * Derive an ISO 3166-2 code from an ArcGIS admin-division feature's properties.\r\n * `ISO_CODE` arrives as the country code concatenated with the subdivision\r\n * (`CAON`), so the prefix is stripped and re-joined with a hyphen (`CA-ON`).\r\n */\r\nexport function subdivisionCodeFromFeature(\r\n properties?: Record<string, unknown> | null\r\n): string | null {\r\n const isoCC = properties?.ISO_CC as string | undefined\r\n const isoCode = properties?.ISO_CODE as string | undefined\r\n if (isoCC && isoCode && isoCode.startsWith(isoCC)) {\r\n return `${isoCC}-${isoCode.slice(isoCC.length)}`\r\n }\r\n return (isoCode || (properties?.NAME as string | undefined) || null)\r\n}\r\n\r\nexport const buildSubdivisionUrl = (countryCode: string, base: string = ARCGIS_BASE): string => {\r\n const params = new URLSearchParams({\r\n outFields: 'NAME,ISO_CC,ISO_CODE,ADMINTYPE',\r\n where: `ISO_CC='${countryCode}'`,\r\n f: 'geojson',\r\n })\r\n return `${base}?${params.toString()}`\r\n}\r\n"],"mappings":"AAGO,MAAM,cAAc;AAOpB,SAAS,UAAU,KAAa,SAAyB;AAC9D,MAAI,SAAS,oBAAO,IAAI,QAAQ,KAAK,EAAE,EAAE,KAAK;AAC9C,MAAI,MAAM,WAAW,GAAG;AACtB,YAAQ,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,MAAM,CAAC;AAAA,EACxE;AACA,QAAM,IAAI,SAAS,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE;AACxC,QAAM,IAAI,SAAS,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE;AACxC,QAAM,IAAI,SAAS,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE;AACxC,MAAI,OAAO,MAAM,CAAC,KAAK,OAAO,MAAM,CAAC,KAAK,OAAO,MAAM,CAAC,GAAG;AACzD,WAAO,iBAAiB,OAAO;AAAA,EACjC;AACA,SAAO,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,OAAO;AAC1C;AAOO,SAAS,2BACd,YACe;AACf,QAAM,QAAQ,yCAAY;AAC1B,QAAM,UAAU,yCAAY;AAC5B,MAAI,SAAS,WAAW,QAAQ,WAAW,KAAK,GAAG;AACjD,WAAO,GAAG,KAAK,IAAI,QAAQ,MAAM,MAAM,MAAM,CAAC;AAAA,EAChD;AACA,SAAQ,YAAY,yCAAY,SAA+B;AACjE;AAEO,MAAM,sBAAsB,CAAC,aAAqB,OAAe,gBAAwB;AAC9F,QAAM,SAAS,IAAI,gBAAgB;AAAA,IACjC,WAAW;AAAA,IACX,OAAO,WAAW,WAAW;AAAA,IAC7B,GAAG;AAAA,EACL,CAAC;AACD,SAAO,GAAG,IAAI,IAAI,OAAO,SAAS,CAAC;AACrC;","names":[]}
@@ -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;AAO9B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAA;AA0ItE,eAAO,MAAM,YAAY,GAAI,+BAA+B;IAAE,YAAY,CAAC,EAAE,YAAY,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,sBA0IhH,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;AAoJtE,eAAO,MAAM,YAAY,GAAI,+BAA+B;IAAE,YAAY,CAAC,EAAE,YAAY,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,sBAwGhH,CAAA"}
@@ -18,14 +18,28 @@ var __spreadValues = (a, b) => {
18
18
  return a;
19
19
  };
20
20
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
- import { jsx } from "react/jsx-runtime";
21
+ import { jsx, jsxs } from "react/jsx-runtime";
22
22
  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 { maptilerKeyOrPlaceholder } from "../../../../utils/mapStyleSpec";
26
27
  import { hexToRgba, buildSubdivisionUrl } from "./countryLayerUtils";
28
+ import { useCameraSubdivision } from "./useCameraSubdivision";
29
+ import { useSubdivisionHover } from "./useSubdivisionHover";
27
30
  const DEFAULT_BORDER_COLOR = "#73cee2";
28
31
  const BOUNDARIES_SOURCE_ID = "openmaptiles-boundaries";
32
+ const SUBDIVISION_SOURCE_ID = "admin-subdivisions-source";
33
+ const SUBDIVISION_FILL_ID = "admin-subdivisions-fill";
34
+ const SUBDIVISION_LINE_ID = "admin-subdivisions-line";
35
+ const SUBDIVISION_LINE_MAX_ZOOM = 15;
36
+ const SUBDIVISION_HOVER_MIN_ZOOM = 10;
37
+ const SUBDIVISION_LINE_WIDTH = [
38
+ "case",
39
+ ["all", ["boolean", ["feature-state", "hover"], false], [">", ["zoom"], SUBDIVISION_HOVER_MIN_ZOOM]],
40
+ ["interpolate", ["linear"], ["zoom"], 10, 3, 15, 5],
41
+ ["interpolate", ["linear"], ["zoom"], 4, 0.5, 8, 1.4, 14, 2.4]
42
+ ];
29
43
  const GLOBAL_LAYER_IDS = [
30
44
  "global-borders-country",
31
45
  "global-borders-region",
@@ -34,12 +48,11 @@ const GLOBAL_LAYER_IDS = [
34
48
  "global-labels-city"
35
49
  ];
36
50
  function addGlobalBorderLayer(map, color, maptilerKey) {
37
- if (!maptilerKey) return;
38
51
  try {
39
52
  if (!map.getSource(BOUNDARIES_SOURCE_ID)) {
40
53
  map.addSource(BOUNDARIES_SOURCE_ID, {
41
54
  type: "vector",
42
- url: `https://api.maptiler.com/tiles/v3/tiles.json?key=${maptilerKey}`
55
+ url: `https://api.maptiler.com/tiles/v3/tiles.json?key=${maptilerKeyOrPlaceholder(maptilerKey)}`
43
56
  });
44
57
  }
45
58
  if (!map.getLayer("global-borders-country")) {
@@ -151,7 +164,6 @@ const CountryLayer = ({ organization, maptilerKey }) => {
151
164
  const { map, currentLocation } = mapState.map;
152
165
  const searchParams = useSearchParams();
153
166
  const router = useRouter();
154
- const debounceRef = React.useRef(null);
155
167
  const countryCode = ((organization == null ? void 0 : organization.country) || "CA").toUpperCase();
156
168
  const borderColor = hexToRgba((organization == null ? void 0 : organization.mainColor) || DEFAULT_BORDER_COLOR, 0.7);
157
169
  const subdivisionUrl = buildSubdivisionUrl(countryCode);
@@ -184,75 +196,62 @@ const CountryLayer = ({ organization, maptilerKey }) => {
184
196
  }
185
197
  });
186
198
  }, [orgHasLocation]);
187
- React.useEffect(() => {
188
- if (orgHasLocation) return;
189
- if (!(map && currentLocation)) return;
190
- const currentCountrySubdivision = currentLocation.countrySubdivision || null;
191
- const currentMunicipality = currentLocation.municipality || null;
192
- function onMouseMove(e) {
193
- if (!map.isStyleLoaded()) return;
194
- if (debounceRef.current) clearTimeout(debounceRef.current);
195
- const eventPoint = e.point;
196
- debounceRef.current = setTimeout(() => {
197
- var _a, _b, _c;
198
- const features = map.queryRenderedFeatures(eventPoint, {
199
- layers: ["admin-subdivisions-fill"]
200
- });
201
- let newCountrySubdivision = null;
202
- if (features.length > 0) {
203
- const f = features[0];
204
- const isoCC = (_a = f.properties) == null ? void 0 : _a.ISO_CC;
205
- const isoCode = (_b = f.properties) == null ? void 0 : _b.ISO_CODE;
206
- if (isoCC && isoCode && isoCode.startsWith(isoCC)) {
207
- newCountrySubdivision = `${isoCC}-${isoCode.slice(isoCC.length)}`;
208
- } else {
209
- newCountrySubdivision = isoCode || ((_c = f.properties) == null ? void 0 : _c.NAME) || null;
210
- }
211
- }
212
- const finalCountrySubdivision = newCountrySubdivision || currentCountrySubdivision;
213
- if (finalCountrySubdivision !== currentCountrySubdivision) {
214
- mapDispatch({
215
- type: "UPDATE_LOCATION",
216
- payload: {
217
- currentLocation: __spreadProps(__spreadValues({}, currentLocation), {
218
- countrySubdivision: finalCountrySubdivision,
219
- municipality: currentMunicipality
220
- })
221
- }
222
- });
223
- const params = new URLSearchParams(searchParams.toString());
224
- params.set("countrySubdivision", finalCountrySubdivision || "");
225
- router.replace(`?${params.toString()}`, { scroll: false });
226
- }
227
- }, 300);
228
- }
229
- if (map.isStyleLoaded()) {
230
- map.on("mousemove", onMouseMove);
231
- } else {
232
- void map.once("styledata", () => {
233
- map.on("mousemove", onMouseMove);
234
- });
235
- }
236
- return () => {
237
- map.off("mousemove", onMouseMove);
238
- if (debounceRef.current) clearTimeout(debounceRef.current);
239
- };
240
- }, [map, mapDispatch, currentLocation, searchParams, router]);
199
+ const commitSubdivision = React.useCallback((code) => {
200
+ if (code === ((currentLocation == null ? void 0 : currentLocation.countrySubdivision) || null)) return;
201
+ mapDispatch({
202
+ type: "UPDATE_LOCATION",
203
+ payload: {
204
+ currentLocation: __spreadProps(__spreadValues({}, currentLocation != null ? currentLocation : {}), { countrySubdivision: code })
205
+ }
206
+ });
207
+ const params = new URLSearchParams(searchParams.toString());
208
+ params.set("countrySubdivision", code);
209
+ router.replace(`?${params.toString()}`, { scroll: false });
210
+ }, [currentLocation, mapDispatch, router, searchParams]);
211
+ useCameraSubdivision({
212
+ map,
213
+ layerId: SUBDIVISION_FILL_ID,
214
+ sourceId: SUBDIVISION_SOURCE_ID,
215
+ enabled: !orgHasLocation,
216
+ onResolve: commitSubdivision
217
+ });
218
+ useSubdivisionHover({
219
+ map,
220
+ layerId: SUBDIVISION_FILL_ID,
221
+ sourceId: SUBDIVISION_SOURCE_ID,
222
+ enabled: !orgHasLocation
223
+ });
241
224
  if (orgHasLocation) return null;
242
- return /* @__PURE__ */ jsx(
225
+ return /* @__PURE__ */ jsxs(
243
226
  Source,
244
227
  {
245
- id: "admin-subdivisions-source",
228
+ id: SUBDIVISION_SOURCE_ID,
246
229
  type: "geojson",
247
230
  data: subdivisionUrl,
248
- children: /* @__PURE__ */ jsx(
249
- Layer,
250
- {
251
- id: "admin-subdivisions-fill",
252
- type: "fill",
253
- paint: { "fill-color": "transparent", "fill-opacity": 0 }
254
- }
255
- )
231
+ generateId: true,
232
+ children: [
233
+ /* @__PURE__ */ jsx(
234
+ Layer,
235
+ {
236
+ id: SUBDIVISION_FILL_ID,
237
+ type: "fill",
238
+ paint: { "fill-color": borderColor, "fill-opacity": 0 }
239
+ }
240
+ ),
241
+ /* @__PURE__ */ jsx(
242
+ Layer,
243
+ {
244
+ id: SUBDIVISION_LINE_ID,
245
+ type: "line",
246
+ maxzoom: SUBDIVISION_LINE_MAX_ZOOM,
247
+ layout: { "line-cap": "round", "line-join": "round" },
248
+ paint: {
249
+ "line-color": borderColor,
250
+ "line-width": SUBDIVISION_LINE_WIDTH
251
+ }
252
+ }
253
+ )
254
+ ]
256
255
  }
257
256
  );
258
257
  };
@@ -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 { hexToRgba, buildSubdivisionUrl } from './countryLayerUtils'\r\n\r\nimport type { Organization } from '../../../../../../../types/dbTypes'\r\nimport type { MapMouseEvent } from 'maplibre-gl'\r\n\r\nconst DEFAULT_BORDER_COLOR = '#73cee2'\r\nconst BOUNDARIES_SOURCE_ID = 'openmaptiles-boundaries'\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 if (!maptilerKey) return\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=${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 const debounceRef = React.useRef<NodeJS.Timeout | null>(null)\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 // Add the global boundary line layer imperatively (vector-tile lines from the style's openmaptiles source). Re-adds on style swap so it survives basemap changes.\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 hover\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 React.useEffect(() => {\r\n if (orgHasLocation) return\r\n if (!(map && currentLocation)) return\r\n\r\n const currentCountrySubdivision = currentLocation.countrySubdivision || null\r\n const currentMunicipality = currentLocation.municipality || null\r\n\r\n function onMouseMove(e: MapMouseEvent) {\r\n if (!map.isStyleLoaded()) return\r\n\r\n if (debounceRef.current) clearTimeout(debounceRef.current)\r\n\r\n const eventPoint = e.point\r\n\r\n debounceRef.current = setTimeout(() => {\r\n const features = map.queryRenderedFeatures(eventPoint, {\r\n layers: ['admin-subdivisions-fill'],\r\n })\r\n\r\n // if (features.length > 0) {\r\n // console.group('[CountryLayer] hover')\r\n // features.forEach(f => console.log(f.properties))\r\n // console.groupEnd()\r\n // }\r\n\r\n let newCountrySubdivision = null\r\n\r\n if (features.length > 0) {\r\n const f = features[0]\r\n const isoCC = f.properties?.ISO_CC\r\n const isoCode = f.properties?.ISO_CODE\r\n // Build \"CA-ON\" from ISO_CC \"CA\" + ISO_CODE \"CAON\" → strip prefix to get \"ON\"\r\n if (isoCC && isoCode && isoCode.startsWith(isoCC)) {\r\n newCountrySubdivision = `${isoCC}-${isoCode.slice(isoCC.length)}`\r\n } else {\r\n newCountrySubdivision = (isoCode || f.properties?.NAME || null) as string | null\r\n }\r\n }\r\n\r\n const finalCountrySubdivision = newCountrySubdivision || currentCountrySubdivision\r\n\r\n if (finalCountrySubdivision !== currentCountrySubdivision) {\r\n mapDispatch({\r\n type: 'UPDATE_LOCATION',\r\n payload: {\r\n currentLocation: {\r\n ...currentLocation,\r\n countrySubdivision: finalCountrySubdivision,\r\n municipality: currentMunicipality,\r\n },\r\n },\r\n })\r\n\r\n const params = new URLSearchParams(searchParams.toString())\r\n params.set('countrySubdivision', finalCountrySubdivision || '')\r\n router.replace(`?${params.toString()}`, { scroll: false })\r\n }\r\n }, 300)\r\n }\r\n\r\n if (map.isStyleLoaded()) {\r\n map.on('mousemove', onMouseMove)\r\n } else {\r\n void map.once('styledata', () => {\r\n map.on('mousemove', onMouseMove)\r\n })\r\n }\r\n\r\n return () => {\r\n map.off('mousemove', onMouseMove)\r\n if (debounceRef.current) clearTimeout(debounceRef.current)\r\n }\r\n }, [map, mapDispatch, currentLocation, searchParams, router])\r\n\r\n if (orgHasLocation) return null\r\n\r\n // Invisible ArcGIS subdivision polygons for hover hit-detection (only mounted when the org hasn't locked a subdivision). The visible borders come from the imperative openmaptiles layer above.\r\n return (\r\n <Source\r\n id=\"admin-subdivisions-source\"\r\n type=\"geojson\"\r\n data={subdivisionUrl}\r\n >\r\n <Layer\r\n id=\"admin-subdivisions-fill\"\r\n type=\"fill\"\r\n paint={{ 'fill-color': 'transparent', 'fill-opacity': 0 }}\r\n />\r\n </Source>\r\n )\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA0RM;AArRN,SAAS,iBAAiB,iBAAiB;AAC3C,YAAY,WAAW;AACvB,SAAS,QAAQ,aAAa;AAE9B,SAAS,kBAAkB;AAE3B,SAAS,WAAW,2BAA2B;AAK/C,MAAM,uBAAuB;AAC7B,MAAM,uBAAuB;AAC7B,MAAM,mBAAmB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,SAAS,qBAAqB,KAAU,OAAe,aAAsB;AAC3E,MAAI,CAAC,YAAa;AAClB,MAAI;AACF,QAAI,CAAC,IAAI,UAAU,oBAAoB,GAAG;AACxC,UAAI,UAAU,sBAAsB;AAAA,QAClC,MAAM;AAAA,QACN,KAAK,oDAAoD,WAAW;AAAA,MACtE,CAAC;AAAA,IACH;AAGA,QAAI,CAAC,IAAI,SAAS,wBAAwB,GAAG;AAC3C,UAAI,SAAS;AAAA,QACX,IAAI;AAAA,QACJ,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,gBAAgB;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eAAe,gBAAgB,EAAE;AAAA;AAAA,MAC1D;AAAA;AAAA,EACF;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/CountryLayer/index.tsx"],"sourcesContent":["\"use client\"\n\n// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport { useSearchParams, useRouter } from 'next/navigation'\nimport * as React from 'react'\nimport { Source, Layer } from 'react-map-gl/maplibre'\n\nimport { MapContext } from '../../../../../../../store/Map/context'\n\nimport { maptilerKeyOrPlaceholder } from '../../../../utils/mapStyleSpec'\n\nimport { hexToRgba, buildSubdivisionUrl } from './countryLayerUtils'\nimport { useCameraSubdivision } from './useCameraSubdivision'\nimport { useSubdivisionHover } from './useSubdivisionHover'\n\nimport type { Organization } from '../../../../../../../types/dbTypes'\n\nconst DEFAULT_BORDER_COLOR = '#73cee2'\nconst BOUNDARIES_SOURCE_ID = 'openmaptiles-boundaries'\nconst SUBDIVISION_SOURCE_ID = 'admin-subdivisions-source'\nconst SUBDIVISION_FILL_ID = 'admin-subdivisions-fill'\nconst SUBDIVISION_LINE_ID = 'admin-subdivisions-line'\nconst SUBDIVISION_LINE_MAX_ZOOM = 15\nconst SUBDIVISION_HOVER_MIN_ZOOM = 10\n\nconst SUBDIVISION_LINE_WIDTH = [\n 'case',\n ['all', ['boolean', ['feature-state', 'hover'], false], ['>', ['zoom'], SUBDIVISION_HOVER_MIN_ZOOM]],\n ['interpolate', ['linear'], ['zoom'], 10, 3, 15, 5],\n ['interpolate', ['linear'], ['zoom'], 4, 0.5, 8, 1.4, 14, 2.4],\n] as const\nconst GLOBAL_LAYER_IDS = [\n 'global-borders-country',\n 'global-borders-region',\n 'global-labels-country',\n 'global-labels-state',\n 'global-labels-city',\n] as const\n\nfunction addGlobalBorderLayer(map: any, color: string, maptilerKey?: string) {\n try {\n if (!map.getSource(BOUNDARIES_SOURCE_ID)) {\n map.addSource(BOUNDARIES_SOURCE_ID, {\n type: 'vector',\n url: `https://api.maptiler.com/tiles/v3/tiles.json?key=${maptilerKeyOrPlaceholder(maptilerKey)}`,\n })\n }\n\n // Country borders — visible at all zooms, slightly thinner up close where states take over.\n if (!map.getLayer('global-borders-country')) {\n map.addLayer({\n id: 'global-borders-country',\n type: 'line',\n source: BOUNDARIES_SOURCE_ID,\n 'source-layer': 'boundary',\n filter: ['all', ['==', 'admin_level', 2], ['==', 'maritime', 0]],\n layout: { 'line-cap': 'round', 'line-join': 'round' },\n paint: {\n 'line-color': color,\n 'line-width': { base: 1, stops: [[0, 0.8], [4, 1.4], [10, 1.4], [14, 1]] },\n },\n })\n }\n\n // State / province borders — fade in around zoom 3, dominate from 5+.\n if (!map.getLayer('global-borders-region')) {\n map.addLayer({\n id: 'global-borders-region',\n type: 'line',\n source: BOUNDARIES_SOURCE_ID,\n 'source-layer': 'boundary',\n filter: ['all', ['in', 'admin_level', 3, 4], ['==', 'maritime', 0]],\n minzoom: 2,\n layout: { 'line-cap': 'round', 'line-join': 'round' },\n paint: {\n 'line-color': color,\n 'line-width': { base: 1, stops: [[2, 0], [4, 0.5], [8, 1.4], [14, 2.4]] },\n 'line-opacity': { base: 1, stops: [[2, 0], [4, 0.7], [6, 1]] },\n },\n })\n }\n\n // Country labels — small/global up to zoom ~6, gone by 8.\n if (!map.getLayer('global-labels-country')) {\n map.addLayer({\n id: 'global-labels-country',\n type: 'symbol',\n source: BOUNDARIES_SOURCE_ID,\n 'source-layer': 'place',\n filter: ['==', 'class', 'country'],\n minzoom: 1,\n maxzoom: 8,\n layout: {\n 'text-field': ['coalesce', ['get', 'name:latin'], ['get', 'name']],\n 'text-font': ['Noto Sans Regular'],\n 'text-size': { base: 1, stops: [[1, 10], [4, 13], [6, 16]] },\n 'text-letter-spacing': 0.1,\n 'text-max-width': 8,\n 'text-transform': 'uppercase',\n },\n paint: {\n 'text-color': '#ffffff',\n 'text-halo-color': 'rgba(0,0,0,0.7)',\n 'text-halo-width': 1.2,\n 'text-opacity': { base: 1, stops: [[5, 1], [7, 0]] },\n },\n })\n }\n\n // State / province labels — cover zoom 3–8.\n if (!map.getLayer('global-labels-state')) {\n map.addLayer({\n id: 'global-labels-state',\n type: 'symbol',\n source: BOUNDARIES_SOURCE_ID,\n 'source-layer': 'place',\n filter: ['in', 'class', 'state', 'province'],\n minzoom: 3,\n maxzoom: 9,\n layout: {\n 'text-field': ['coalesce', ['get', 'name:latin'], ['get', 'name']],\n 'text-font': ['Noto Sans Regular'],\n 'text-size': { base: 1, stops: [[3, 9], [6, 12], [8, 14]] },\n 'text-letter-spacing': 0.05,\n 'text-max-width': 8,\n },\n paint: {\n 'text-color': '#e8e8e8',\n 'text-halo-color': 'rgba(0,0,0,0.6)',\n 'text-halo-width': 1,\n 'text-opacity': { base: 1, stops: [[3, 0], [4, 1], [8, 1], [9, 0]] },\n },\n })\n }\n\n // Major city labels (rank ≤ 4 = most prominent cities) — appear when zoomed in past country level.\n if (!map.getLayer('global-labels-city')) {\n map.addLayer({\n id: 'global-labels-city',\n type: 'symbol',\n source: BOUNDARIES_SOURCE_ID,\n 'source-layer': 'place',\n filter: ['in', 'class', 'city', 'town'],\n minzoom: 5,\n maxzoom: 13,\n layout: {\n 'text-field': ['coalesce', ['get', 'name:latin'], ['get', 'name']],\n 'text-font': ['Noto Sans Regular'],\n 'text-size': { base: 1, stops: [[5, 10], [9, 13], [12, 15]] },\n 'text-max-width': 8,\n },\n paint: {\n 'text-color': '#dcdcdc',\n 'text-halo-color': 'rgba(0,0,0,0.7)',\n 'text-halo-width': 1.1,\n },\n })\n }\n } catch {\n // style may be in a transitional state\n }\n}\n\nexport const CountryLayer = ({ organization, maptilerKey }: { organization?: Organization; maptilerKey?: string }) => {\n const { state: mapState, dispatch: mapDispatch } = React.useContext(MapContext)\n const { map, currentLocation } = mapState.map\n const searchParams = useSearchParams()\n const router = useRouter()\n\n const countryCode = (organization?.country || 'CA').toUpperCase()\n const borderColor = hexToRgba((organization?.mainColor as string) || DEFAULT_BORDER_COLOR, 0.7)\n const subdivisionUrl = buildSubdivisionUrl(countryCode)\n\n // Re-added on every style swap: setStyle drops imperatively added layers.\n React.useEffect(() => {\n if (!map) return\n const addNow = () => addGlobalBorderLayer(map, borderColor, maptilerKey)\n if (map.isStyleLoaded()) addNow()\n map.on('styledata', addNow)\n return () => {\n try {\n map.off('styledata', addNow)\n for (const id of GLOBAL_LAYER_IDS) {\n if (map.getLayer(id)) map.removeLayer(id)\n }\n } catch {\n // map may be destroyed\n }\n }\n }, [map, borderColor, maptilerKey])\n\n // If the org already has a fixed subdivision or municipality, lock them in and skip camera tracking\n const orgHasLocation = !!(organization?.countrySubdivision || organization?.municipality)\n\n // When org has fixed location values, push them into currentLocation once\n React.useEffect(() => {\n if (!orgHasLocation) return\n mapDispatch({\n type: 'UPDATE_LOCATION',\n payload: {\n currentLocation: {\n ...(currentLocation ?? {}),\n countrySubdivision: organization?.countrySubdivision ?? currentLocation?.countrySubdivision,\n municipality: organization?.municipality ?? currentLocation?.municipality,\n } as any,\n },\n })\n\n }, [orgHasLocation])\n\n const commitSubdivision = React.useCallback((code: string) => {\n if (code === (currentLocation?.countrySubdivision || null)) return\n\n mapDispatch({\n type: 'UPDATE_LOCATION',\n payload: {\n currentLocation: { ...(currentLocation ?? {}), countrySubdivision: code } as any,\n },\n })\n\n const params = new URLSearchParams(searchParams.toString())\n params.set('countrySubdivision', code)\n router.replace(`?${params.toString()}`, { scroll: false })\n }, [currentLocation, mapDispatch, router, searchParams])\n\n useCameraSubdivision({\n map,\n layerId: SUBDIVISION_FILL_ID,\n sourceId: SUBDIVISION_SOURCE_ID,\n enabled: !orgHasLocation,\n onResolve: commitSubdivision,\n })\n\n useSubdivisionHover({\n map,\n layerId: SUBDIVISION_FILL_ID,\n sourceId: SUBDIVISION_SOURCE_ID,\n enabled: !orgHasLocation,\n })\n\n if (orgHasLocation) return null\n\n return (\n <Source\n id={SUBDIVISION_SOURCE_ID}\n type=\"geojson\"\n data={subdivisionUrl}\n generateId\n >\n {/* Zero opacity, never visible: this is what hit-tests the camera target and the pointer. */}\n <Layer\n id={SUBDIVISION_FILL_ID}\n type=\"fill\"\n paint={{ 'fill-color': borderColor, 'fill-opacity': 0 }}\n />\n <Layer\n id={SUBDIVISION_LINE_ID}\n type=\"line\"\n maxzoom={SUBDIVISION_LINE_MAX_ZOOM}\n layout={{ 'line-cap': 'round', 'line-join': 'round' }}\n paint={{\n 'line-color': borderColor,\n 'line-width': SUBDIVISION_LINE_WIDTH as never,\n }}\n />\n </Source>\n )\n}\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,SAAS,4BAA4B;AACrC,SAAS,2BAA2B;AAIpC,MAAM,uBAAuB;AAC7B,MAAM,uBAAuB;AAC7B,MAAM,wBAAwB;AAC9B,MAAM,sBAAsB;AAC5B,MAAM,sBAAsB;AAC5B,MAAM,4BAA4B;AAClC,MAAM,6BAA6B;AAEnC,MAAM,yBAAyB;AAAA,EAC7B;AAAA,EACA,CAAC,OAAO,CAAC,WAAW,CAAC,iBAAiB,OAAO,GAAG,KAAK,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,0BAA0B,CAAC;AAAA,EACnG,CAAC,eAAe,CAAC,QAAQ,GAAG,CAAC,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;AAAA,EAClD,CAAC,eAAe,CAAC,QAAQ,GAAG,CAAC,MAAM,GAAG,GAAG,KAAK,GAAG,KAAK,IAAI,GAAG;AAC/D;AACA,MAAM,mBAAmB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,SAAS,qBAAqB,KAAU,OAAe,aAAsB;AAC3E,MAAI;AACF,QAAI,CAAC,IAAI,UAAU,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1D,WAAO,IAAI,sBAAsB,IAAI;AACrC,WAAO,QAAQ,IAAI,OAAO,SAAS,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,16 @@
1
+ import type { Map as MaplibreMap } from 'maplibre-gl';
2
+ interface Params {
3
+ map?: MaplibreMap | null;
4
+ layerId: string;
5
+ sourceId: string;
6
+ enabled: boolean;
7
+ onResolve: (code: string) => void;
8
+ }
9
+ /**
10
+ * Track which administrative subdivision the camera is looking at, resolving the
11
+ * polygon under the camera target after every move. Nothing is reported when the
12
+ * target sits outside the loaded polygons, so the caller keeps its last value.
13
+ */
14
+ export declare function useCameraSubdivision({ map, layerId, sourceId, enabled, onResolve }: Params): void;
15
+ export {};
16
+ //# sourceMappingURL=useCameraSubdivision.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCameraSubdivision.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/CountryLayer/useCameraSubdivision.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,aAAa,CAAA;AAIrD,UAAU,MAAM;IACd,GAAG,CAAC,EAAE,WAAW,GAAG,IAAI,CAAA;IACxB,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;CAClC;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,QA4C1F"}
@@ -0,0 +1,44 @@
1
+ "use client";
2
+ import * as React from "react";
3
+ import { subdivisionCodeFromFeature } from "./countryLayerUtils";
4
+ const RESOLVE_DEBOUNCE_MS = 150;
5
+ function useCameraSubdivision({ map, layerId, sourceId, enabled, onResolve }) {
6
+ const onResolveRef = React.useRef(onResolve);
7
+ React.useEffect(() => {
8
+ onResolveRef.current = onResolve;
9
+ });
10
+ React.useEffect(() => {
11
+ if (!map || !enabled) return;
12
+ let timer = null;
13
+ const resolveNow = () => {
14
+ try {
15
+ if (!map.getLayer(layerId)) return;
16
+ const [feature] = map.queryRenderedFeatures(map.project(map.getCenter()), { layers: [layerId] });
17
+ const code = subdivisionCodeFromFeature(feature == null ? void 0 : feature.properties);
18
+ if (code) onResolveRef.current(code);
19
+ } catch (e) {
20
+ }
21
+ };
22
+ const schedule = () => {
23
+ if (timer) clearTimeout(timer);
24
+ timer = setTimeout(resolveNow, RESOLVE_DEBOUNCE_MS);
25
+ };
26
+ const onSourceData = (e) => {
27
+ if (e.sourceId === sourceId && e.isSourceLoaded) schedule();
28
+ };
29
+ map.on("moveend", schedule);
30
+ map.on("styledata", schedule);
31
+ map.on("sourcedata", onSourceData);
32
+ schedule();
33
+ return () => {
34
+ if (timer) clearTimeout(timer);
35
+ map.off("moveend", schedule);
36
+ map.off("styledata", schedule);
37
+ map.off("sourcedata", onSourceData);
38
+ };
39
+ }, [map, enabled, layerId, sourceId]);
40
+ }
41
+ export {
42
+ useCameraSubdivision
43
+ };
44
+ //# sourceMappingURL=useCameraSubdivision.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/CountryLayer/useCameraSubdivision.ts"],"sourcesContent":["'use client'\n\n// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport * as React from 'react'\n\nimport { subdivisionCodeFromFeature } from './countryLayerUtils'\n\nimport type { Map as MaplibreMap } from 'maplibre-gl'\n\nconst RESOLVE_DEBOUNCE_MS = 150\n\ninterface Params {\n map?: MaplibreMap | null\n layerId: string\n sourceId: string\n enabled: boolean\n onResolve: (code: string) => void\n}\n\n/**\n * Track which administrative subdivision the camera is looking at, resolving the\n * polygon under the camera target after every move. Nothing is reported when the\n * target sits outside the loaded polygons, so the caller keeps its last value.\n */\nexport function useCameraSubdivision({ map, layerId, sourceId, enabled, onResolve }: Params) {\n const onResolveRef = React.useRef(onResolve)\n\n React.useEffect(() => {\n onResolveRef.current = onResolve\n })\n\n React.useEffect(() => {\n if (!map || !enabled) return\n\n let timer: ReturnType<typeof setTimeout> | null = null\n\n const resolveNow = () => {\n try {\n if (!map.getLayer(layerId)) return\n const [feature] = map.queryRenderedFeatures(map.project(map.getCenter()), { layers: [layerId] })\n const code = subdivisionCodeFromFeature(feature?.properties)\n if (code) onResolveRef.current(code)\n } catch {\n // style or source may be in a transitional state\n }\n }\n\n const schedule = () => {\n if (timer) clearTimeout(timer)\n timer = setTimeout(resolveNow, RESOLVE_DEBOUNCE_MS)\n }\n\n const onSourceData = (e: { sourceId?: string; isSourceLoaded?: boolean }) => {\n if (e.sourceId === sourceId && e.isSourceLoaded) schedule()\n }\n\n map.on('moveend', schedule)\n map.on('styledata', schedule)\n map.on('sourcedata', onSourceData)\n schedule()\n\n return () => {\n if (timer) clearTimeout(timer)\n map.off('moveend', schedule)\n map.off('styledata', schedule)\n map.off('sourcedata', onSourceData)\n }\n }, [map, enabled, layerId, sourceId])\n}\n"],"mappings":";AAKA,YAAY,WAAW;AAEvB,SAAS,kCAAkC;AAI3C,MAAM,sBAAsB;AAerB,SAAS,qBAAqB,EAAE,KAAK,SAAS,UAAU,SAAS,UAAU,GAAW;AAC3F,QAAM,eAAe,MAAM,OAAO,SAAS;AAE3C,QAAM,UAAU,MAAM;AACpB,iBAAa,UAAU;AAAA,EACzB,CAAC;AAED,QAAM,UAAU,MAAM;AACpB,QAAI,CAAC,OAAO,CAAC,QAAS;AAEtB,QAAI,QAA8C;AAElD,UAAM,aAAa,MAAM;AACvB,UAAI;AACF,YAAI,CAAC,IAAI,SAAS,OAAO,EAAG;AAC5B,cAAM,CAAC,OAAO,IAAI,IAAI,sBAAsB,IAAI,QAAQ,IAAI,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC;AAC/F,cAAM,OAAO,2BAA2B,mCAAS,UAAU;AAC3D,YAAI,KAAM,cAAa,QAAQ,IAAI;AAAA,MACrC,SAAQ;AAAA,MAER;AAAA,IACF;AAEA,UAAM,WAAW,MAAM;AACrB,UAAI,MAAO,cAAa,KAAK;AAC7B,cAAQ,WAAW,YAAY,mBAAmB;AAAA,IACpD;AAEA,UAAM,eAAe,CAAC,MAAuD;AAC3E,UAAI,EAAE,aAAa,YAAY,EAAE,eAAgB,UAAS;AAAA,IAC5D;AAEA,QAAI,GAAG,WAAW,QAAQ;AAC1B,QAAI,GAAG,aAAa,QAAQ;AAC5B,QAAI,GAAG,cAAc,YAAY;AACjC,aAAS;AAET,WAAO,MAAM;AACX,UAAI,MAAO,cAAa,KAAK;AAC7B,UAAI,IAAI,WAAW,QAAQ;AAC3B,UAAI,IAAI,aAAa,QAAQ;AAC7B,UAAI,IAAI,cAAc,YAAY;AAAA,IACpC;AAAA,EACF,GAAG,CAAC,KAAK,SAAS,SAAS,QAAQ,CAAC;AACtC;","names":[]}
@@ -0,0 +1,11 @@
1
+ import type { Map as MaplibreMap } from 'maplibre-gl';
2
+ interface Params {
3
+ map?: MaplibreMap | null;
4
+ layerId: string;
5
+ sourceId: string;
6
+ enabled: boolean;
7
+ }
8
+ /** Highlight the hovered subdivision through feature-state, so pointer movement costs no React render. */
9
+ export declare function useSubdivisionHover({ map, layerId, sourceId, enabled }: Params): void;
10
+ export {};
11
+ //# sourceMappingURL=useSubdivisionHover.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSubdivisionHover.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/CountryLayer/useSubdivisionHover.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAsB,GAAG,IAAI,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzE,UAAU,MAAM;IACd,GAAG,CAAC,EAAE,WAAW,GAAG,IAAI,CAAA;IACxB,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;CACjB;AAED,0GAA0G;AAC1G,wBAAgB,mBAAmB,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,MAAM,QAqC9E"}
@@ -0,0 +1,38 @@
1
+ "use client";
2
+ import * as React from "react";
3
+ function useSubdivisionHover({ map, layerId, sourceId, enabled }) {
4
+ React.useEffect(() => {
5
+ if (!map || !enabled) return;
6
+ let hoveredId = null;
7
+ const setHover = (id, hover) => {
8
+ if (id === null) return;
9
+ try {
10
+ map.setFeatureState({ source: sourceId, id }, { hover });
11
+ } catch (e) {
12
+ }
13
+ };
14
+ const onMove = (e) => {
15
+ var _a, _b, _c;
16
+ const id = (_c = (_b = (_a = e.features) == null ? void 0 : _a[0]) == null ? void 0 : _b.id) != null ? _c : null;
17
+ if (id === hoveredId) return;
18
+ setHover(hoveredId, false);
19
+ hoveredId = id;
20
+ setHover(hoveredId, true);
21
+ };
22
+ const onLeave = () => {
23
+ setHover(hoveredId, false);
24
+ hoveredId = null;
25
+ };
26
+ map.on("mousemove", layerId, onMove);
27
+ map.on("mouseleave", layerId, onLeave);
28
+ return () => {
29
+ onLeave();
30
+ map.off("mousemove", layerId, onMove);
31
+ map.off("mouseleave", layerId, onLeave);
32
+ };
33
+ }, [map, layerId, sourceId, enabled]);
34
+ }
35
+ export {
36
+ useSubdivisionHover
37
+ };
38
+ //# sourceMappingURL=useSubdivisionHover.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/CountryLayer/useSubdivisionHover.ts"],"sourcesContent":["'use client'\n\n// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport * as React from 'react'\n\nimport type { MapLayerMouseEvent, Map as MaplibreMap } from 'maplibre-gl'\n\ninterface Params {\n map?: MaplibreMap | null\n layerId: string\n sourceId: string\n enabled: boolean\n}\n\n/** Highlight the hovered subdivision through feature-state, so pointer movement costs no React render. */\nexport function useSubdivisionHover({ map, layerId, sourceId, enabled }: Params) {\n React.useEffect(() => {\n if (!map || !enabled) return\n\n let hoveredId: string | number | null = null\n\n const setHover = (id: string | number | null, hover: boolean) => {\n if (id === null) return\n try {\n map.setFeatureState({ source: sourceId, id }, { hover })\n } catch {\n // source may have been swapped out with the style\n }\n }\n\n const onMove = (e: MapLayerMouseEvent) => {\n const id = e.features?.[0]?.id ?? null\n if (id === hoveredId) return\n setHover(hoveredId, false)\n hoveredId = id\n setHover(hoveredId, true)\n }\n\n const onLeave = () => {\n setHover(hoveredId, false)\n hoveredId = null\n }\n\n map.on('mousemove', layerId, onMove)\n map.on('mouseleave', layerId, onLeave)\n\n return () => {\n onLeave()\n map.off('mousemove', layerId, onMove)\n map.off('mouseleave', layerId, onLeave)\n }\n }, [map, layerId, sourceId, enabled])\n}\n"],"mappings":";AAKA,YAAY,WAAW;AAYhB,SAAS,oBAAoB,EAAE,KAAK,SAAS,UAAU,QAAQ,GAAW;AAC/E,QAAM,UAAU,MAAM;AACpB,QAAI,CAAC,OAAO,CAAC,QAAS;AAEtB,QAAI,YAAoC;AAExC,UAAM,WAAW,CAAC,IAA4B,UAAmB;AAC/D,UAAI,OAAO,KAAM;AACjB,UAAI;AACF,YAAI,gBAAgB,EAAE,QAAQ,UAAU,GAAG,GAAG,EAAE,MAAM,CAAC;AAAA,MACzD,SAAQ;AAAA,MAER;AAAA,IACF;AAEA,UAAM,SAAS,CAAC,MAA0B;AAhC9C;AAiCM,YAAM,MAAK,mBAAE,aAAF,mBAAa,OAAb,mBAAiB,OAAjB,YAAuB;AAClC,UAAI,OAAO,UAAW;AACtB,eAAS,WAAW,KAAK;AACzB,kBAAY;AACZ,eAAS,WAAW,IAAI;AAAA,IAC1B;AAEA,UAAM,UAAU,MAAM;AACpB,eAAS,WAAW,KAAK;AACzB,kBAAY;AAAA,IACd;AAEA,QAAI,GAAG,aAAa,SAAS,MAAM;AACnC,QAAI,GAAG,cAAc,SAAS,OAAO;AAErC,WAAO,MAAM;AACX,cAAQ;AACR,UAAI,IAAI,aAAa,SAAS,MAAM;AACpC,UAAI,IAAI,cAAc,SAAS,OAAO;AAAA,IACxC;AAAA,EACF,GAAG,CAAC,KAAK,SAAS,UAAU,OAAO,CAAC;AACtC;","names":[]}
@@ -1,7 +1,8 @@
1
1
  import type { MapStyle } from '../../../../types/map';
2
2
  /**
3
3
  * Built-in map style catalog that is always available.
4
- * These are the default base styles available to all organizations.
4
+ * The two `cdt:` entries are sentinels resolved by `resolveStyleSpec` against the
5
+ * deployment's own MapTiler key, so no key ever reaches React state or the URL.
5
6
  */
6
7
  export declare const BUILT_IN_MAP_STYLES: MapStyle[];
7
8
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"mapStyleCatalog.d.ts","sourceRoot":"","sources":["../../../../../../src/core/components/viewers/map/utils/mapStyleCatalog.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAErD;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,QAAQ,EAMzC,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,EAAE,QAAiC,CAAC;AA2DlE;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,kBAAkB,EAAE,OAAO,GAAG,QAAQ,EAAE,CA+B7E;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,YAAY,EAAE,QAAQ,GAAG,IAAI,GAAG,SAAS,EACzC,OAAO,EAAE,QAAQ,EAAE,GAClB,QAAQ,CAQV"}
1
+ {"version":3,"file":"mapStyleCatalog.d.ts","sourceRoot":"","sources":["../../../../../../src/core/components/viewers/map/utils/mapStyleCatalog.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAErD;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAE,QAAQ,EAMzC,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,EAAE,QAAiC,CAAC;AA2DlE;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,kBAAkB,EAAE,OAAO,GAAG,QAAQ,EAAE,CA+B7E;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,YAAY,EAAE,QAAQ,GAAG,IAAI,GAAG,SAAS,EACzC,OAAO,EAAE,QAAQ,EAAE,GAClB,QAAQ,CAQV"}
@@ -1,6 +1,7 @@
1
+ import { SATELLITE_STYLE_URL, STREETS_STYLE_URL } from "./mapStyleSpec";
1
2
  const BUILT_IN_MAP_STYLES = [
2
- { name: "Satellite", url: "/mapStyles/satellite.json" },
3
- // { name: 'Streets', url: '/mapStyles/streets.json' },
3
+ { name: "Satellite", url: SATELLITE_STYLE_URL },
4
+ { name: "Streets", url: STREETS_STYLE_URL },
4
5
  { name: "Dark", url: "https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json" },
5
6
  { name: "Positron", url: "https://basemaps.cartocdn.com/gl/positron-gl-style/style.json" },
6
7
  { name: "Maplibre", url: "https://demotiles.maplibre.org/style.json" }