@collabdt/core 0.4.0 → 0.4.3
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/AppSidebarContent.d.ts.map +1 -1
- package/dist/core/components/AppSidebarContent.js +2 -7
- package/dist/core/components/AppSidebarContent.js.map +1 -1
- package/dist/core/components/ConfirmDialog.d.ts +2 -1
- package/dist/core/components/ConfirmDialog.d.ts.map +1 -1
- package/dist/core/components/ConfirmDialog.js +8 -0
- package/dist/core/components/ConfirmDialog.js.map +1 -1
- package/dist/core/components/authentication/AuthPage.d.ts.map +1 -1
- package/dist/core/components/authentication/AuthPage.js +1 -2
- package/dist/core/components/authentication/AuthPage.js.map +1 -1
- package/dist/core/components/authentication/auth.css +4 -1
- package/dist/core/components/organizationConfig/src/CountrySubdivisionFields.d.ts +2 -0
- package/dist/core/components/organizationConfig/src/CountrySubdivisionFields.d.ts.map +1 -0
- package/dist/core/components/organizationConfig/src/CountrySubdivisionFields.js +180 -0
- package/dist/core/components/organizationConfig/src/CountrySubdivisionFields.js.map +1 -0
- package/dist/core/components/organizationConfig/src/organizationConfigContent.d.ts.map +1 -1
- package/dist/core/components/organizationConfig/src/organizationConfigContent.js +13 -0
- package/dist/core/components/organizationConfig/src/organizationConfigContent.js.map +1 -1
- package/dist/core/components/settings/index.js +1 -1
- package/dist/core/components/settings/index.js.map +1 -1
- package/dist/core/components/settings/src/AccountSettingsPanel.d.ts.map +1 -1
- package/dist/core/components/settings/src/AccountSettingsPanel.js +6 -7
- package/dist/core/components/settings/src/AccountSettingsPanel.js.map +1 -1
- package/dist/core/components/ui/AnimatedBackground.d.ts +2 -2
- package/dist/core/components/ui/AnimatedBackground.d.ts.map +1 -1
- package/dist/core/components/ui/AnimatedBackground.js +7 -8
- package/dist/core/components/ui/AnimatedBackground.js.map +1 -1
- package/dist/core/components/ui/FilesManager/src/FileItemComponent.d.ts.map +1 -1
- package/dist/core/components/ui/FilesManager/src/FileItemComponent.js +1 -1
- package/dist/core/components/ui/FilesManager/src/FileItemComponent.js.map +1 -1
- package/dist/core/components/ui/LegendCard.d.ts +8 -3
- package/dist/core/components/ui/LegendCard.d.ts.map +1 -1
- package/dist/core/components/ui/LegendCard.js +37 -19
- package/dist/core/components/ui/LegendCard.js.map +1 -1
- package/dist/core/components/ui/Progress.js +2 -2
- package/dist/core/components/ui/Progress.js.map +1 -1
- package/dist/core/components/ui/Sensors/SensorDetailDialog.d.ts.map +1 -1
- package/dist/core/components/ui/Sensors/SensorDetailDialog.js +56 -19
- package/dist/core/components/ui/Sensors/SensorDetailDialog.js.map +1 -1
- package/dist/core/components/ui/Sensors/SensorLegend.d.ts +6 -3
- package/dist/core/components/ui/Sensors/SensorLegend.d.ts.map +1 -1
- package/dist/core/components/ui/Sensors/SensorLegend.js +95 -27
- package/dist/core/components/ui/Sensors/SensorLegend.js.map +1 -1
- package/dist/core/components/ui/Sensors/SensorMultiSeriesChart.d.ts +10 -4
- package/dist/core/components/ui/Sensors/SensorMultiSeriesChart.d.ts.map +1 -1
- package/dist/core/components/ui/Sensors/SensorMultiSeriesChart.js +60 -9
- package/dist/core/components/ui/Sensors/SensorMultiSeriesChart.js.map +1 -1
- package/dist/core/components/ui/Sensors/SensorsSection.d.ts +1 -2
- package/dist/core/components/ui/Sensors/SensorsSection.d.ts.map +1 -1
- package/dist/core/components/ui/Sensors/SensorsSection.js +36 -6
- package/dist/core/components/ui/Sensors/SensorsSection.js.map +1 -1
- package/dist/core/components/ui/Sensors/buildingSensorColours.d.ts +49 -0
- package/dist/core/components/ui/Sensors/buildingSensorColours.d.ts.map +1 -0
- package/dist/core/components/ui/Sensors/buildingSensorColours.js +68 -0
- package/dist/core/components/ui/Sensors/buildingSensorColours.js.map +1 -0
- package/dist/core/components/ui/Sensors/sensorScope.js +1 -1
- package/dist/core/components/ui/Sensors/sensorScope.js.map +1 -1
- package/dist/core/components/ui/Sensors/sensorVisibility.d.ts +47 -0
- package/dist/core/components/ui/Sensors/sensorVisibility.d.ts.map +1 -0
- package/dist/core/components/ui/Sensors/sensorVisibility.js +29 -0
- package/dist/core/components/ui/Sensors/sensorVisibility.js.map +1 -0
- package/dist/core/components/ui/Sensors/useBuildingSensorColours.d.ts +30 -0
- package/dist/core/components/ui/Sensors/useBuildingSensorColours.d.ts.map +1 -0
- package/dist/core/components/ui/Sensors/useBuildingSensorColours.js +92 -0
- package/dist/core/components/ui/Sensors/useBuildingSensorColours.js.map +1 -0
- package/dist/core/components/ui/Sensors/useSensorSeriesMulti.d.ts +1 -1
- package/dist/core/components/ui/Sensors/useSensorSeriesMulti.d.ts.map +1 -1
- package/dist/core/components/ui/Sensors/useSensorSeriesMulti.js.map +1 -1
- package/dist/core/components/viewers/bim/BimViewer.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/BimViewer.js +10 -6
- package/dist/core/components/viewers/bim/BimViewer.js.map +1 -1
- package/dist/core/components/viewers/bim/src/BimMeasurements/BimMeasurementManager.d.ts +161 -0
- package/dist/core/components/viewers/bim/src/BimMeasurements/BimMeasurementManager.d.ts.map +1 -0
- package/dist/core/components/viewers/bim/src/BimMeasurements/BimMeasurementManager.js +382 -0
- package/dist/core/components/viewers/bim/src/BimMeasurements/BimMeasurementManager.js.map +1 -0
- package/dist/core/components/viewers/bim/src/BimMeasurements/measurementSettings.d.ts +80 -0
- package/dist/core/components/viewers/bim/src/BimMeasurements/measurementSettings.d.ts.map +1 -0
- package/dist/core/components/viewers/bim/src/BimMeasurements/measurementSettings.js +48 -0
- package/dist/core/components/viewers/bim/src/BimMeasurements/measurementSettings.js.map +1 -0
- package/dist/core/components/viewers/bim/src/BimSidebar/src/SettingsTab/index.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/src/BimSidebar/src/SettingsTab/index.js +3 -1
- package/dist/core/components/viewers/bim/src/BimSidebar/src/SettingsTab/index.js.map +1 -1
- package/dist/core/components/viewers/bim/src/BimSidebar/src/SettingsTab/src/MeasurementSettings.d.ts +11 -0
- package/dist/core/components/viewers/bim/src/BimSidebar/src/SettingsTab/src/MeasurementSettings.d.ts.map +1 -0
- package/dist/core/components/viewers/bim/src/BimSidebar/src/SettingsTab/src/MeasurementSettings.js +186 -0
- package/dist/core/components/viewers/bim/src/BimSidebar/src/SettingsTab/src/MeasurementSettings.js.map +1 -0
- package/dist/core/components/viewers/bim/src/Highlighter/index.d.ts +10 -0
- package/dist/core/components/viewers/bim/src/Highlighter/index.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/src/Highlighter/index.js +28 -6
- package/dist/core/components/viewers/bim/src/Highlighter/index.js.map +1 -1
- package/dist/core/components/viewers/bim/src/LoadModels.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/src/LoadModels.js +5 -2
- package/dist/core/components/viewers/bim/src/LoadModels.js.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/renderCSS2DMarkers.d.ts +5 -0
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/renderCSS2DMarkers.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/renderCSS2DMarkers.js +26 -14
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/renderCSS2DMarkers.js.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/useFilePlacement.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/useFilePlacement.js +4 -2
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/useFilePlacement.js.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/useSensorMarkers.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/useSensorMarkers.js +21 -18
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/useSensorMarkers.js.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/ClippingTool/ClippingTool.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/ClippingTool/ClippingTool.js +15 -10
- package/dist/core/components/viewers/bim/src/tools/ClippingTool/ClippingTool.js.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/measureBimTool.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/measureBimTool.js +52 -60
- package/dist/core/components/viewers/bim/src/tools/measureBimTool.js.map +1 -1
- package/dist/core/components/viewers/map/MapViewer.d.ts.map +1 -1
- package/dist/core/components/viewers/map/MapViewer.js +1 -1
- package/dist/core/components/viewers/map/MapViewer.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/index.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/index.js +27 -1
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/index.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingSensorDetails.d.ts +36 -0
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingSensorDetails.d.ts.map +1 -0
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingSensorDetails.js +95 -0
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingSensorDetails.js.map +1 -0
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingsTools.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingsTools.js +55 -42
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingsTools.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/NonDatabaseBuildingPopover.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/NonDatabaseBuildingPopover.js +5 -5
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/NonDatabaseBuildingPopover.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/BimLayer/index.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/BimLayer/index.js +9 -6
- package/dist/core/components/viewers/map/src/MapLayers/src/BimLayer/index.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/buildingColourExpression.d.ts +32 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/buildingColourExpression.d.ts.map +1 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/buildingColourExpression.js +56 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/buildingColourExpression.js.map +1 -0
- 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 +61 -39
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/index.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/src/BuildingSensorMarkers.d.ts +18 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/src/BuildingSensorMarkers.d.ts.map +1 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/src/BuildingSensorMarkers.js +82 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/src/BuildingSensorMarkers.js.map +1 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/CommentLayer/index.js +3 -3
- package/dist/core/components/viewers/map/src/MapLayers/src/CommentLayer/index.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/FileLayer/index.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/FileLayer/index.js +22 -2
- package/dist/core/components/viewers/map/src/MapLayers/src/FileLayer/index.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/index.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/index.js +39 -22
- package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/index.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/sensorClusterColour.d.ts +22 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/sensorClusterColour.d.ts.map +1 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/sensorClusterColour.js +36 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/sensorClusterColour.js.map +1 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/mapLayersUtils.d.ts +5 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/mapLayersUtils.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/mapLayersUtils.js +6 -2
- package/dist/core/components/viewers/map/src/MapLayers/src/mapLayersUtils.js.map +1 -1
- package/dist/core/components/viewers/map/src/SimpleMap.d.ts +1 -1
- package/dist/core/components/viewers/map/src/SimpleMap.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/SimpleMap.js +4 -10
- package/dist/core/components/viewers/map/src/SimpleMap.js.map +1 -1
- package/dist/core/components/viewers/map/src/tools/AddTools/AddDataset/DatasetAdder.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/tools/AddTools/AddDataset/DatasetAdder.js +4 -0
- package/dist/core/components/viewers/map/src/tools/AddTools/AddDataset/DatasetAdder.js.map +1 -1
- package/dist/core/components/viewers/pointcloud/src/PointCloudLoadingState/index.d.ts.map +1 -1
- package/dist/core/components/viewers/pointcloud/src/PointCloudLoadingState/index.js +16 -3
- package/dist/core/components/viewers/pointcloud/src/PointCloudLoadingState/index.js.map +1 -1
- package/dist/core/components/viewers/pointcloud/src/PointCloudSidebar/src/FileTab/src/PointCloudSection.d.ts.map +1 -1
- package/dist/core/components/viewers/pointcloud/src/PointCloudSidebar/src/FileTab/src/PointCloudSection.js +105 -26
- package/dist/core/components/viewers/pointcloud/src/PointCloudSidebar/src/FileTab/src/PointCloudSection.js.map +1 -1
- package/dist/core/components/viewers/pointcloud/src/PointCloudSidebar/src/SettingsTab/src/PerformanceSettings.js +6 -6
- package/dist/core/components/viewers/pointcloud/src/PointCloudSidebar/src/SettingsTab/src/PerformanceSettings.js.map +1 -1
- package/dist/core/i18n/messages/en.json +29 -2
- package/dist/core/i18n/messages/es.json +29 -2
- package/dist/core/i18n/messages/fr.json +29 -2
- package/dist/core/store/Menus/context.d.ts.map +1 -1
- package/dist/core/store/Menus/context.js +4 -2
- package/dist/core/store/Menus/context.js.map +1 -1
- package/dist/core/store/Menus/reducer.d.ts +15 -26
- package/dist/core/store/Menus/reducer.d.ts.map +1 -1
- package/dist/core/store/Menus/reducer.js +38 -4
- package/dist/core/store/Menus/reducer.js.map +1 -1
- package/dist/core/store/PointCloud/reducer.js +1 -1
- package/dist/core/store/PointCloud/reducer.js.map +1 -1
- package/dist/core/utils/appContent.d.ts +15 -0
- package/dist/core/utils/appContent.d.ts.map +1 -0
- package/dist/core/utils/appContent.js +24 -0
- package/dist/core/utils/appContent.js.map +1 -0
- package/dist/core/utils/colourUtils.d.ts +9 -0
- package/dist/core/utils/colourUtils.d.ts.map +1 -1
- package/dist/core/utils/colourUtils.js +16 -0
- package/dist/core/utils/colourUtils.js.map +1 -1
- package/dist/core/utils/markerUtils.d.ts +11 -0
- package/dist/core/utils/markerUtils.d.ts.map +1 -1
- package/dist/core/utils/markerUtils.js +2 -0
- package/dist/core/utils/markerUtils.js.map +1 -1
- package/package.json +1 -1
- package/dist/core/components/viewers/bim/src/BimMeasurements/LenghtMeasurement.d.ts +0 -21
- package/dist/core/components/viewers/bim/src/BimMeasurements/LenghtMeasurement.d.ts.map +0 -1
- package/dist/core/components/viewers/bim/src/BimMeasurements/LenghtMeasurement.js +0 -92
- package/dist/core/components/viewers/bim/src/BimMeasurements/LenghtMeasurement.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/BimLayer/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 * as OBC from \"@thatopen/components\";\r\nimport * as LR from \"lucide-react\";\r\nimport { type CustomLayerInterface, type LngLatLike } from \"maplibre-gl\";\r\nimport * as React from \"react\";\r\nimport { Marker } from \"react-map-gl/maplibre\";\r\nimport * as THREE from \"three\";\r\n\r\nimport { BimContext, MapContext } from \"../../../../../../../store\";\r\nimport { ViewerContextMenu } from '../../../../../../ui/FilesManager';\r\nimport { disposeThreeScene } from \"../disposeThreeScene\";\r\nimport { EditPosition, extractPositionAndRotation } from \"../EditPosition\";\r\n\r\nimport type { Building, DbFile } from \"../../../../../../../types/dbTypes\";\r\nimport type { FileAction } from \"../../../../../../../types/global\";\r\nimport type * as FRAGS from \"@thatopen/fragments\";\r\nimport type { Map } from \"maplibre-gl\";\r\n\r\n\r\nexport const BimLayer = () => {\r\n\r\n const { state: mapState } = React.useContext(MapContext);\r\n const { map } = mapState.map;\r\n\r\n const { state: bimState, dispatch: bimDispatch } = React.useContext(BimContext);\r\n const { bimModelsAddedToMap, editingBimModel } = bimState.bim;\r\n\r\n const rendererRef = React.useRef<THREE.WebGLRenderer | null>(null);\r\n\r\n const addedLayersRef = React.useRef<Set<string>>(new Set());\r\n const prevModelsRef = React.useRef<Set<string>>(new Set());\r\n\r\n const sharedRef = React.useRef<{\r\n components: OBC.Components;\r\n fragments: OBC.FragmentsManager;\r\n } | null>(null);\r\n\r\n const [loadingBuildings, setLoadingBuildings] = React.useState<Set<number>>(new Set());\r\n const [contextMenu, setContextMenu] = React.useState<{\r\n x: number; y: number; bimFile: DbFile\r\n } | null>(null);\r\n\r\n const handleContextMenuAction = React.useCallback((action: FileAction, file: DbFile) => {\r\n if (action === 'view') {\r\n bimDispatch({ type: 'REMOVE_BIM_FROM_MAP', payload: { bimModelName: file.name } });\r\n } else if (action === 'move') {\r\n bimDispatch({ type: 'EDIT_BIM_MODEL_BY_NAME', payload: { editingBimModel: file.name } });\r\n }\r\n }, [bimDispatch]);\r\n\r\n const tempPositionsRef = React.useRef<Record<string, { lat: number; lng: number }>>({});\r\n const tempRotationsRef = React.useRef<Record<string, number>>({});\r\n const tempElevationsRef = React.useRef<Record<string, number>>({});\r\n\r\n const editingBimModelRef = React.useRef<string | null>(editingBimModel);\r\n React.useEffect(() => {\r\n editingBimModelRef.current = editingBimModel;\r\n }, [editingBimModel]);\r\n\r\n const handleExitEditMode = React.useCallback(() => {\r\n bimDispatch({ type: \"EDIT_BIM_MODEL_BY_NAME\", payload: { editingBimModel: null } });\r\n }, [bimDispatch]);\r\n\r\n const handleMapRepaint = React.useCallback(() => {\r\n if (map) map.triggerRepaint();\r\n }, [map]);\r\n const getOrCreateShared = React.useCallback(async () => {\r\n if (sharedRef.current) return sharedRef.current;\r\n\r\n const components = new OBC.Components();\r\n const worlds = components.get(OBC.Worlds);\r\n const world = worlds.create<OBC.SimpleScene, OBC.SimpleCamera, OBC.SimpleRenderer>();\r\n world.scene = new OBC.SimpleScene(components);\r\n world.renderer = new OBC.SimpleRenderer(components, document.createElement(\"div\"));\r\n world.camera = new OBC.SimpleCamera(components);\r\n components.init();\r\n world.scene.setup();\r\n\r\n const fragments = components.get(OBC.FragmentsManager);\r\n const fetchedUrl = await fetch(\"https://thatopen.github.io/engine_fragment/resources/worker.mjs\");\r\n const workerBlob = await fetchedUrl.blob();\r\n const workerUrl = URL.createObjectURL(\r\n new File([workerBlob], \"worker.mjs\", { type: \"text/javascript\" })\r\n );\r\n fragments.init(workerUrl);\r\n\r\n sharedRef.current = { components, fragments };\r\n return sharedRef.current;\r\n }, []);\r\n\r\n React.useEffect(() => {\r\n if (!map) return;\r\n\r\n const currentModelNames = new Set(bimModelsAddedToMap.map(bm => bm.bimFile.name));\r\n\r\n const modelsToRemove = Array.from(prevModelsRef.current).filter(\r\n name => !currentModelNames.has(name)\r\n );\r\n const modelsToAdd = bimModelsAddedToMap.filter(\r\n bm => !prevModelsRef.current.has(bm.bimFile.name)\r\n );\r\n\r\n modelsToRemove.forEach(layerName => {\r\n if (map.getLayer(layerName)) {\r\n map.removeLayer(layerName);\r\n addedLayersRef.current.delete(layerName);\r\n }\r\n });\r\n\r\n prevModelsRef.current = currentModelNames;\r\n\r\n if (modelsToAdd.length === 0) return;\r\n\r\n // ─── Load a single BIM model ──────────────────────────────────────────\r\n const loadModel = async (\r\n buildingModel: { bimFile: DbFile; building?: Building | null },\r\n fragments: OBC.FragmentsManager,\r\n scene: THREE.Scene,\r\n map: Map,\r\n lodCamera: THREE.PerspectiveCamera\r\n ): Promise<FRAGS.FragmentsModel | null> => {\r\n\r\n const { bimFile, building } = buildingModel;\r\n if (!bimFile) return null;\r\n\r\n const buildingId = building?.id ?? bimFile.id;\r\n setLoadingBuildings(prev => new Set(prev).add(buildingId));\r\n\r\n try {\r\n const file = await fetch(bimFile.url);\r\n if (!file.ok) throw new Error(`Fetch failed: ${file.status} ${file.statusText}`);\r\n\r\n const buffer = await file.arrayBuffer();\r\n const model = await fragments.core.load(buffer, { modelId: bimFile.name });\r\n\r\n if (!model.box.isEmpty()) {\r\n const center = model.box.getCenter(new THREE.Vector3());\r\n const size = model.box.getSize(new THREE.Vector3());\r\n model.object.position.set(-center.x, 0, -center.z);\r\n\r\n // lodCamera: above the model's new IFC-space centre (XZ is now 0,0)\r\n lodCamera.position.set(0, center.y + Math.max(size.x, size.y, size.z) * 2, 0);\r\n lodCamera.lookAt(0, center.y, 0);\r\n } else {\r\n lodCamera.position.set(0, 100, 0);\r\n lodCamera.lookAt(0, 0, 0);\r\n }\r\n lodCamera.updateMatrixWorld();\r\n model.useCamera(lodCamera);\r\n\r\n model.graphicsQuality = 1;\r\n scene.add(model.object);\r\n void fragments.core.update(true);\r\n map.triggerRepaint();\r\n\r\n return model;\r\n\r\n } catch (error) {\r\n console.error(\"Error loading BIM model:\", error);\r\n return null;\r\n } finally {\r\n setLoadingBuildings(prev => {\r\n const next = new Set(prev);\r\n next.delete(buildingId);\r\n return next;\r\n });\r\n }\r\n };\r\n\r\n // ─── Build a MapLibre custom layer for one model ──────────────────────\r\n const createCustomLayer = (\r\n buildingModel: { bimFile: DbFile; building?: Building | null },\r\n fragments: OBC.FragmentsManager,\r\n scene: THREE.Scene\r\n ): CustomLayerInterface | undefined => {\r\n\r\n const { bimFile, building } = buildingModel;\r\n const {\r\n lng: baseLng, lat: baseLat,\r\n rotation: originalRotation,\r\n } = extractPositionAndRotation(bimFile, building);\r\n if (baseLng === null || baseLat === null) return undefined;\r\n\r\n // Per-layer state kept in closure\r\n let model: FRAGS.FragmentsModel | null = null;\r\n let lastAppliedRotation = originalRotation;\r\n let lastLodUpdate = 0;\r\n // Render-on-demand: cache terrain elevation off the per-frame path and\r\n // only keep repainting while the camera recently moved, so an idle map\r\n // with a placed model stops re-rendering instead of pinning the main\r\n // thread (this was the freeze after a geocoder flyTo to high zoom).\r\n let cachedTerrainElev = 0;\r\n let lastMoveTime = performance.now();\r\n const SETTLE_MS = 1000;\r\n const recomputeTerrainElev = () => {\r\n const { lng, lat } = extractPositionAndRotation(bimFile, building);\r\n if (lng !== null && lat !== null) {\r\n const e = map.queryTerrainElevation([lng, lat]);\r\n if (e !== null && e !== undefined) cachedTerrainElev = e;\r\n }\r\n };\r\n\r\n let onMapMove: () => void;\r\n let onMapMoveEnd: () => void;\r\n const renderCamera = new THREE.PerspectiveCamera();\r\n const lodCamera = new THREE.PerspectiveCamera();\r\n // Reused per-frame matrices/vectors — render() must not allocate.\r\n const _vp = new THREE.Matrix4();\r\n const _m = new THREE.Matrix4();\r\n const _p = new THREE.Matrix4();\r\n const _vm = new THREE.Matrix4();\r\n const _camPos = new THREE.Vector3();\r\n const _center = new THREE.Vector3();\r\n const _lookTarget = new THREE.Vector3();\r\n const _scaleVec = new THREE.Vector3(1, 1, 1);\r\n\r\n return {\r\n id: bimFile.name,\r\n type: \"custom\",\r\n renderingMode: \"3d\",\r\n\r\n onAdd(map, gl) {\r\n scene.rotateY(originalRotation * (Math.PI / 180));\r\n this.scene = scene;\r\n\r\n void loadModel(buildingModel, fragments, scene, map, lodCamera).then(loaded => {\r\n model = loaded;\r\n // Open the settle window so the just-loaded fragments stream\r\n // in and paint over the next frames, then idle.\r\n lastMoveTime = performance.now();\r\n recomputeTerrainElev();\r\n map.triggerRepaint();\r\n });\r\n\r\n if (!rendererRef.current) {\r\n rendererRef.current = new THREE.WebGLRenderer({\r\n canvas: map.getCanvas(),\r\n context: gl,\r\n alpha: true,\r\n });\r\n rendererRef.current.autoClear = false;\r\n }\r\n this.renderer = rendererRef.current;\r\n // Track movement so render() knows when it may stop repainting.\r\n onMapMove = () => { lastMoveTime = performance.now(); };\r\n onMapMoveEnd = () => {\r\n lastMoveTime = performance.now();\r\n if (model) void fragments.core.update(true);\r\n // Terrain tiles for the new view are loaded once the camera\r\n // settles — refresh the cached elevation here, not per frame.\r\n recomputeTerrainElev();\r\n map.triggerRepaint();\r\n };\r\n map.on(\"move\", onMapMove);\r\n map.on(\"moveend\", onMapMoveEnd);\r\n },\r\n\r\n render(_, args) {\r\n if (\r\n editingBimModelRef.current === bimFile.name &&\r\n tempRotationsRef.current[bimFile.name] !== undefined\r\n ) {\r\n const cur = tempRotationsRef.current[bimFile.name];\r\n if (cur !== lastAppliedRotation) {\r\n scene.rotateY((cur - lastAppliedRotation) * (Math.PI / 180));\r\n lastAppliedRotation = cur;\r\n map.triggerRepaint();\r\n }\r\n } else {\r\n const { rotation: baseRot } = extractPositionAndRotation(bimFile, building);\r\n if (baseRot !== lastAppliedRotation) {\r\n scene.rotateY((baseRot - lastAppliedRotation) * (Math.PI / 180));\r\n lastAppliedRotation = baseRot;\r\n map.triggerRepaint();\r\n }\r\n }\r\n\r\n const {\r\n lng: baseLngNow, lat: baseLatNow,\r\n elevation: baseElevNow,\r\n } = extractPositionAndRotation(bimFile, building);\r\n\r\n let modelLongitude = baseLngNow;\r\n let modelLatitude = baseLatNow;\r\n let modelElevation = baseElevNow;\r\n\r\n if (editingBimModelRef.current === bimFile.name) {\r\n const tp = tempPositionsRef.current[bimFile.name];\r\n if (tp) { modelLongitude = tp.lng; modelLatitude = tp.lat; }\r\n const te = tempElevationsRef.current[bimFile.name];\r\n if (te !== undefined) modelElevation = te;\r\n }\r\n\r\n const modelOrigin = [modelLongitude, modelLatitude] as LngLatLike;\r\n // Use the cached terrain elevation (refreshed on moveend); query\r\n // live only while actively editing this model's position. Keeps\r\n // the expensive queryTerrainElevation off the hot path — the\r\n // per-frame query was a main driver of the high-zoom freeze.\r\n const terrainElev = editingBimModelRef.current === bimFile.name\r\n ? (map.queryTerrainElevation([modelLongitude, modelLatitude]) ?? cachedTerrainElev)\r\n : cachedTerrainElev;\r\n const modelAltitude = modelElevation + terrainElev;\r\n const scaling = 1;\r\n\r\n // ── Build renderCamera (VP × M, for Three.js rendering) ───\r\n // Reused temps — render() allocates nothing. Math is identical\r\n // to the prior allocate-every-frame version.\r\n const modelMatrix = map.transform.getMatrixForModel(modelOrigin, modelAltitude);\r\n _scaleVec.set(scaling, scaling, scaling);\r\n _vp.fromArray(args.defaultProjectionData.mainMatrix);\r\n _m.fromArray(modelMatrix).scale(_scaleVec);\r\n renderCamera.projectionMatrix.multiplyMatrices(_vp, _m); // VP × M, into the camera's own matrix\r\n\r\n // camIFCPos = translation of (P⁻¹ · (VP×M))⁻¹\r\n _p.fromArray(args.projectionMatrix).invert(); // _p = P⁻¹\r\n _vm.multiplyMatrices(_p, renderCamera.projectionMatrix).invert();\r\n _camPos.setFromMatrixPosition(_vm);\r\n lodCamera.position.copy(_camPos);\r\n\r\n if (model) {\r\n model.box.getCenter(_center);\r\n _lookTarget.set(0, _center.y, 0);\r\n } else {\r\n _lookTarget.set(0, 0, 0);\r\n }\r\n lodCamera.lookAt(_lookTarget);\r\n lodCamera.fov = args.fov * (180 / Math.PI) + 40;\r\n lodCamera.aspect = map.getCanvas().width / map.getCanvas().height;\r\n lodCamera.updateProjectionMatrix(); // rebuilds projectionMatrix from fov/aspect\r\n lodCamera.updateMatrixWorld(); // rebuilds matrixWorld + matrixWorldInverse\r\n\r\n if (model) {\r\n model.useCamera(lodCamera);\r\n const now = performance.now();\r\n if (now - lastLodUpdate > 50) {\r\n lastLodUpdate = now;\r\n void fragments.core.update();\r\n }\r\n // Render-on-demand: only keep the frame loop alive while the\r\n // camera recently moved (settle window, for fragment\r\n // streaming) or this model is being edited. Idle map ⇒ no\r\n // self-scheduled repaints ⇒ main thread freed (no freeze).\r\n if (\r\n editingBimModelRef.current === bimFile.name ||\r\n now - lastMoveTime < SETTLE_MS\r\n ) {\r\n map.triggerRepaint();\r\n }\r\n }\r\n\r\n this.renderer.resetState();\r\n this.renderer.render(this.scene, renderCamera);\r\n },\r\n\r\n onRemove() {\r\n if (onMapMove) map.off(\"move\", onMapMove);\r\n if (onMapMoveEnd) map.off(\"moveend\", onMapMoveEnd);\r\n if (model) {\r\n model.dispose().catch(console.warn);\r\n model = null;\r\n }\r\n // Dispose all Three.js GPU resources (geometries, materials, textures)\r\n disposeThreeScene(scene);\r\n },\r\n };\r\n };\r\n\r\n void Promise.all(modelsToAdd.map(async (buildingModel) => {\r\n try {\r\n const { fragments } = await getOrCreateShared();\r\n\r\n const layerName = buildingModel.bimFile.name;\r\n if (map.getLayer(layerName)) return;\r\n const scene = new THREE.Scene();\r\n scene.add(new THREE.AmbientLight(0xffffff, 0.8));\r\n const sun = new THREE.DirectionalLight(0xffffff, 1.0);\r\n sun.position.set(10, 20, 10);\r\n scene.add(sun);\r\n\r\n const customLayer = createCustomLayer(buildingModel, fragments, scene);\r\n if (!customLayer) return;\r\n\r\n map.addLayer(customLayer);\r\n addedLayersRef.current.add(layerName);\r\n\r\n } catch (err) {\r\n console.error(\"Error adding BIM layer:\", err);\r\n }\r\n }));\r\n\r\n }, [map, bimModelsAddedToMap]);\r\n\r\n // Cleanup on unmount — dispose shared components and renderer\r\n React.useEffect(() => {\r\n return () => {\r\n if (map) {\r\n addedLayersRef.current.forEach(layerName => {\r\n if (map.getLayer(layerName)) map.removeLayer(layerName);\r\n });\r\n addedLayersRef.current.clear();\r\n }\r\n if (sharedRef.current) {\r\n sharedRef.current.components.dispose();\r\n sharedRef.current = null;\r\n }\r\n if (rendererRef.current) {\r\n rendererRef.current.dispose();\r\n rendererRef.current = null;\r\n }\r\n };\r\n }, [map]);\r\n\r\n return (\r\n <>\r\n {bimModelsAddedToMap.map((buildingModel, index) => {\r\n const { lng, lat } = extractPositionAndRotation(\r\n buildingModel.bimFile, buildingModel.building\r\n );\r\n const isLoading = loadingBuildings.has(\r\n buildingModel.building?.id ?? buildingModel.bimFile.id\r\n );\r\n if (lng === null || lat === null) return null;\r\n return (\r\n <React.Fragment key={buildingModel.bimFile.id + \"-fragment-\" + index}>\r\n {isLoading && (\r\n <Marker\r\n key={buildingModel.bimFile.id + \"-loading-animation\" + index}\r\n latitude={lat}\r\n longitude={lng}\r\n >\r\n <LR.Loader className=\"animate-spin w-6 h-6 text-gray-700\" />\r\n </Marker>\r\n )}\r\n {/* Invisible hit-target for right-click context menu on WebGL-rendered BIM models */}\r\n {buildingModel.bimFile.name !== editingBimModel && (\r\n <Marker\r\n key={buildingModel.bimFile.id + \"-ctx-target-\" + index}\r\n latitude={lat}\r\n longitude={lng}\r\n >\r\n <div\r\n className=\"w-10 h-10 opacity-0 cursor-context-menu\"\r\n onContextMenu={(e) => {\r\n e.preventDefault();\r\n setContextMenu({ x: e.clientX, y: e.clientY, bimFile: buildingModel.bimFile });\r\n }}\r\n />\r\n </Marker>\r\n )}\r\n </React.Fragment>\r\n );\r\n })}\r\n {editingBimModel && (() => {\r\n const currentModel = bimModelsAddedToMap.find(bm => bm.bimFile.name === editingBimModel);\r\n if (!currentModel) return null;\r\n const { lng, lat, rotation, elevation } = extractPositionAndRotation(\r\n currentModel.bimFile, currentModel.building\r\n );\r\n return (\r\n <EditPosition\r\n file={currentModel.bimFile}\r\n displayName={currentModel.building?.buildingName || currentModel.bimFile.name}\r\n mode=\"3d\"\r\n initialLat={lat}\r\n initialLng={lng}\r\n initialRotation={rotation}\r\n initialElevation={elevation}\r\n onExitEditMode={handleExitEditMode}\r\n tempPositionsRef={tempPositionsRef}\r\n tempRotationsRef={tempRotationsRef}\r\n tempElevationsRef={tempElevationsRef}\r\n onMapRepaint={handleMapRepaint}\r\n />\r\n );\r\n })()}\r\n\r\n {contextMenu && (\r\n <ViewerContextMenu\r\n x={contextMenu.x}\r\n y={contextMenu.y}\r\n file={{ ...contextMenu.bimFile, isVisible: true }}\r\n options={['view', 'move']}\r\n onAction={handleContextMenuAction}\r\n onClose={() => setContextMenu(null)}\r\n />\r\n )}\r\n </>\r\n );\r\n\r\n};\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAiaQ,mBAiBwB,KAPZ,YAVZ;AA5ZR,YAAY,SAAS;AACrB,YAAY,QAAQ;AAEpB,YAAY,WAAW;AACvB,SAAS,cAAc;AACvB,YAAY,WAAW;AAEvB,SAAS,YAAY,kBAAkB;AACvC,SAAS,yBAAyB;AAClC,SAAS,yBAAyB;AAClC,SAAS,cAAc,kCAAkC;AAQlD,MAAM,WAAW,MAAM;AAE1B,QAAM,EAAE,OAAO,SAAS,IAAI,MAAM,WAAW,UAAU;AACvD,QAAM,EAAE,IAAI,IAAI,SAAS;AAEzB,QAAM,EAAE,OAAO,UAAU,UAAU,YAAY,IAAI,MAAM,WAAW,UAAU;AAC9E,QAAM,EAAE,qBAAqB,gBAAgB,IAAI,SAAS;AAE1D,QAAM,cAAc,MAAM,OAAmC,IAAI;AAEjE,QAAM,iBAAiB,MAAM,OAAoB,oBAAI,IAAI,CAAC;AAC1D,QAAM,gBAAgB,MAAM,OAAoB,oBAAI,IAAI,CAAC;AAEzD,QAAM,YAAY,MAAM,OAGd,IAAI;AAEd,QAAM,CAAC,kBAAkB,mBAAmB,IAAI,MAAM,SAAsB,oBAAI,IAAI,CAAC;AACrF,QAAM,CAAC,aAAa,cAAc,IAAI,MAAM,SAElC,IAAI;AAEd,QAAM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AAycgB,YAAM,eAAe,oBAAoB,KAAK,QAAM,GAAG,QAAQ,SAAS,eAAe;AACvF,UAAI,CAAC,aAAc,QAAO;AAC1B,YAAM,EAAE,KAAK,KAAK,UAAU,UAAU,IAAI;AAAA,QACtC,aAAa;AAAA,QAAS,aAAa;AAAA,MACvC;AACA,aACI;AAAA,QAAC;AAAA;AAAA,UACG,MAAM,aAAa;AAAA,UACnB,eAAa,kBAAa,aAAb,mBAAuB,iBAAgB,aAAa,QAAQ;AAAA,UACzE,MAAK;AAAA,UACL,YAAY;AAAA,UACZ,YAAY;AAAA,UACZ,iBAAiB;AAAA,UACjB,kBAAkB;AAAA,UAClB,gBAAgB;AAAA,UAChB;AAAA,UACA;AAAA,UACA;AAAA,UACA,cAAc;AAAA;AAAA,MAClB;AAAA,IAER,GAAG;AAAA,IAEF,eACG;AAAA,MAAC;AAAA;AAAA,QACG,GAAG,YAAY;AAAA,QACf,GAAG,YAAY;AAAA,QACf,MAAM,iCAAK,YAAY,UAAjB,EAA0B,WAAW,KAAK;AAAA,QAChD,SAAS,CAAC,QAAQ,MAAM;AAAA,QACxB,UAAU;AAAA,QACV,SAAS,MAAM,eAAe,IAAI;AAAA;AAAA,IACtC;AAAA,KAER;AAGR;","names":["map"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/BimLayer/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 * as OBC from \"@thatopen/components\";\r\nimport * as LR from \"lucide-react\";\r\nimport { type CustomLayerInterface, type LngLatLike } from \"maplibre-gl\";\r\nimport * as React from \"react\";\r\nimport { Marker } from \"react-map-gl/maplibre\";\r\nimport * as THREE from \"three\";\r\n\r\nimport { BimContext, MapContext } from \"../../../../../../../store\";\r\nimport { markerOcclusionProps } from \"../../../../../../../utils/markerUtils\";\r\nimport { ViewerContextMenu } from '../../../../../../ui/FilesManager';\r\nimport { disposeThreeScene } from \"../disposeThreeScene\";\r\nimport { EditPosition, extractPositionAndRotation } from \"../EditPosition\";\r\n\r\nimport type { Building, DbFile } from \"../../../../../../../types/dbTypes\";\r\nimport type { FileAction } from \"../../../../../../../types/global\";\r\nimport type * as FRAGS from \"@thatopen/fragments\";\r\nimport type { Map } from \"maplibre-gl\";\r\n\r\n\r\nexport const BimLayer = () => {\r\n\r\n const { state: mapState } = React.useContext(MapContext);\r\n const { map } = mapState.map;\r\n\r\n const { state: bimState, dispatch: bimDispatch } = React.useContext(BimContext);\r\n const { bimModelsAddedToMap, editingBimModel } = bimState.bim;\r\n\r\n const rendererRef = React.useRef<THREE.WebGLRenderer | null>(null);\r\n\r\n const addedLayersRef = React.useRef<Set<string>>(new Set());\r\n const prevModelsRef = React.useRef<Set<string>>(new Set());\r\n\r\n const sharedRef = React.useRef<{\r\n components: OBC.Components;\r\n fragments: OBC.FragmentsManager;\r\n } | null>(null);\r\n\r\n const [loadingBuildings, setLoadingBuildings] = React.useState<Set<number>>(new Set());\r\n const [contextMenu, setContextMenu] = React.useState<{\r\n x: number; y: number; bimFile: DbFile\r\n } | null>(null);\r\n\r\n const handleContextMenuAction = React.useCallback((action: FileAction, file: DbFile) => {\r\n if (action === 'view') {\r\n bimDispatch({ type: 'REMOVE_BIM_FROM_MAP', payload: { bimModelName: file.name } });\r\n } else if (action === 'move') {\r\n bimDispatch({ type: 'EDIT_BIM_MODEL_BY_NAME', payload: { editingBimModel: file.name } });\r\n }\r\n }, [bimDispatch]);\r\n\r\n const tempPositionsRef = React.useRef<Record<string, { lat: number; lng: number }>>({});\r\n const tempRotationsRef = React.useRef<Record<string, number>>({});\r\n const tempElevationsRef = React.useRef<Record<string, number>>({});\r\n\r\n const editingBimModelRef = React.useRef<string | null>(editingBimModel);\r\n React.useEffect(() => {\r\n editingBimModelRef.current = editingBimModel;\r\n }, [editingBimModel]);\r\n\r\n const handleExitEditMode = React.useCallback(() => {\r\n bimDispatch({ type: \"EDIT_BIM_MODEL_BY_NAME\", payload: { editingBimModel: null } });\r\n }, [bimDispatch]);\r\n\r\n const handleMapRepaint = React.useCallback(() => {\r\n if (map) map.triggerRepaint();\r\n }, [map]);\r\n const getOrCreateShared = React.useCallback(async () => {\r\n if (sharedRef.current) return sharedRef.current;\r\n\r\n const components = new OBC.Components();\r\n const worlds = components.get(OBC.Worlds);\r\n const world = worlds.create<OBC.SimpleScene, OBC.SimpleCamera, OBC.SimpleRenderer>();\r\n world.scene = new OBC.SimpleScene(components);\r\n world.renderer = new OBC.SimpleRenderer(components, document.createElement(\"div\"));\r\n world.camera = new OBC.SimpleCamera(components);\r\n components.init();\r\n world.scene.setup();\r\n\r\n const fragments = components.get(OBC.FragmentsManager);\r\n const fetchedUrl = await fetch(\"https://thatopen.github.io/engine_fragment/resources/worker.mjs\");\r\n const workerBlob = await fetchedUrl.blob();\r\n const workerUrl = URL.createObjectURL(\r\n new File([workerBlob], \"worker.mjs\", { type: \"text/javascript\" })\r\n );\r\n fragments.init(workerUrl);\r\n\r\n sharedRef.current = { components, fragments };\r\n return sharedRef.current;\r\n }, []);\r\n\r\n React.useEffect(() => {\r\n if (!map) return;\r\n\r\n const currentModelNames = new Set(bimModelsAddedToMap.map(bm => bm.bimFile.name));\r\n\r\n const modelsToRemove = Array.from(prevModelsRef.current).filter(\r\n name => !currentModelNames.has(name)\r\n );\r\n const modelsToAdd = bimModelsAddedToMap.filter(\r\n bm => !prevModelsRef.current.has(bm.bimFile.name)\r\n );\r\n\r\n modelsToRemove.forEach(layerName => {\r\n if (map.getLayer(layerName)) {\r\n map.removeLayer(layerName);\r\n addedLayersRef.current.delete(layerName);\r\n }\r\n });\r\n\r\n prevModelsRef.current = currentModelNames;\r\n\r\n if (modelsToAdd.length === 0) return;\r\n\r\n // ─── Load a single BIM model ──────────────────────────────────────────\r\n const loadModel = async (\r\n buildingModel: { bimFile: DbFile; building?: Building | null },\r\n fragments: OBC.FragmentsManager,\r\n scene: THREE.Scene,\r\n map: Map,\r\n lodCamera: THREE.PerspectiveCamera\r\n ): Promise<FRAGS.FragmentsModel | null> => {\r\n\r\n const { bimFile, building } = buildingModel;\r\n if (!bimFile) return null;\r\n\r\n const buildingId = building?.id ?? bimFile.id;\r\n setLoadingBuildings(prev => new Set(prev).add(buildingId));\r\n\r\n try {\r\n const file = await fetch(bimFile.url);\r\n if (!file.ok) throw new Error(`Fetch failed: ${file.status} ${file.statusText}`);\r\n\r\n const buffer = await file.arrayBuffer();\r\n const model = await fragments.core.load(buffer, { modelId: bimFile.name });\r\n\r\n if (!model.box.isEmpty()) {\r\n const center = model.box.getCenter(new THREE.Vector3());\r\n const size = model.box.getSize(new THREE.Vector3());\r\n model.object.position.set(-center.x, 0, -center.z);\r\n\r\n // lodCamera: above the model's new IFC-space centre (XZ is now 0,0)\r\n lodCamera.position.set(0, center.y + Math.max(size.x, size.y, size.z) * 2, 0);\r\n lodCamera.lookAt(0, center.y, 0);\r\n } else {\r\n lodCamera.position.set(0, 100, 0);\r\n lodCamera.lookAt(0, 0, 0);\r\n }\r\n lodCamera.updateMatrixWorld();\r\n model.useCamera(lodCamera);\r\n\r\n model.graphicsQuality = 1;\r\n scene.add(model.object);\r\n void fragments.core.update(true);\r\n map.triggerRepaint();\r\n\r\n return model;\r\n\r\n } catch (error) {\r\n console.error(\"Error loading BIM model:\", error);\r\n return null;\r\n } finally {\r\n setLoadingBuildings(prev => {\r\n const next = new Set(prev);\r\n next.delete(buildingId);\r\n return next;\r\n });\r\n }\r\n };\r\n\r\n // ─── Build a MapLibre custom layer for one model ──────────────────────\r\n const createCustomLayer = (\r\n buildingModel: { bimFile: DbFile; building?: Building | null },\r\n fragments: OBC.FragmentsManager,\r\n scene: THREE.Scene\r\n ): CustomLayerInterface | undefined => {\r\n\r\n const { bimFile, building } = buildingModel;\r\n const {\r\n lng: baseLng, lat: baseLat,\r\n rotation: originalRotation,\r\n } = extractPositionAndRotation(bimFile, building);\r\n if (baseLng === null || baseLat === null) return undefined;\r\n\r\n // Per-layer state kept in closure\r\n let model: FRAGS.FragmentsModel | null = null;\r\n let lastAppliedRotation = originalRotation;\r\n let lastLodUpdate = 0;\r\n // Render-on-demand: cache terrain elevation off the per-frame path and\r\n // only keep repainting while the camera recently moved, so an idle map\r\n // with a placed model stops re-rendering instead of pinning the main\r\n // thread (this was the freeze after a geocoder flyTo to high zoom).\r\n let cachedTerrainElev = 0;\r\n let lastMoveTime = performance.now();\r\n const SETTLE_MS = 1000;\r\n const recomputeTerrainElev = () => {\r\n const { lng, lat } = extractPositionAndRotation(bimFile, building);\r\n if (lng !== null && lat !== null) {\r\n const e = map.queryTerrainElevation([lng, lat]);\r\n if (e !== null && e !== undefined) cachedTerrainElev = e;\r\n }\r\n };\r\n\r\n let onMapMove: () => void;\r\n let onMapMoveEnd: () => void;\r\n const renderCamera = new THREE.PerspectiveCamera();\r\n const lodCamera = new THREE.PerspectiveCamera();\r\n // Reused per-frame matrices/vectors — render() must not allocate.\r\n const _vp = new THREE.Matrix4();\r\n const _m = new THREE.Matrix4();\r\n const _p = new THREE.Matrix4();\r\n const _vm = new THREE.Matrix4();\r\n const _camPos = new THREE.Vector3();\r\n const _center = new THREE.Vector3();\r\n const _lookTarget = new THREE.Vector3();\r\n const _scaleVec = new THREE.Vector3(1, 1, 1);\r\n\r\n return {\r\n id: bimFile.name,\r\n type: \"custom\",\r\n renderingMode: \"3d\",\r\n\r\n onAdd(map, gl) {\r\n scene.rotateY(originalRotation * (Math.PI / 180));\r\n this.scene = scene;\r\n\r\n void loadModel(buildingModel, fragments, scene, map, lodCamera).then(loaded => {\r\n model = loaded;\r\n // Open the settle window so the just-loaded fragments stream\r\n // in and paint over the next frames, then idle.\r\n lastMoveTime = performance.now();\r\n recomputeTerrainElev();\r\n map.triggerRepaint();\r\n });\r\n\r\n if (!rendererRef.current) {\r\n rendererRef.current = new THREE.WebGLRenderer({\r\n canvas: map.getCanvas(),\r\n context: gl,\r\n alpha: true,\r\n });\r\n rendererRef.current.autoClear = false;\r\n }\r\n this.renderer = rendererRef.current;\r\n // Track movement so render() knows when it may stop repainting.\r\n onMapMove = () => { lastMoveTime = performance.now(); };\r\n onMapMoveEnd = () => {\r\n lastMoveTime = performance.now();\r\n if (model) void fragments.core.update(true);\r\n // Terrain tiles for the new view are loaded once the camera\r\n // settles — refresh the cached elevation here, not per frame.\r\n recomputeTerrainElev();\r\n map.triggerRepaint();\r\n };\r\n map.on(\"move\", onMapMove);\r\n map.on(\"moveend\", onMapMoveEnd);\r\n },\r\n\r\n render(_, args) {\r\n if (\r\n editingBimModelRef.current === bimFile.name &&\r\n tempRotationsRef.current[bimFile.name] !== undefined\r\n ) {\r\n const cur = tempRotationsRef.current[bimFile.name];\r\n if (cur !== lastAppliedRotation) {\r\n scene.rotateY((cur - lastAppliedRotation) * (Math.PI / 180));\r\n lastAppliedRotation = cur;\r\n map.triggerRepaint();\r\n }\r\n } else {\r\n const { rotation: baseRot } = extractPositionAndRotation(bimFile, building);\r\n if (baseRot !== lastAppliedRotation) {\r\n scene.rotateY((baseRot - lastAppliedRotation) * (Math.PI / 180));\r\n lastAppliedRotation = baseRot;\r\n map.triggerRepaint();\r\n }\r\n }\r\n\r\n const {\r\n lng: baseLngNow, lat: baseLatNow,\r\n elevation: baseElevNow,\r\n } = extractPositionAndRotation(bimFile, building);\r\n\r\n let modelLongitude = baseLngNow;\r\n let modelLatitude = baseLatNow;\r\n let modelElevation = baseElevNow;\r\n\r\n if (editingBimModelRef.current === bimFile.name) {\r\n const tp = tempPositionsRef.current[bimFile.name];\r\n if (tp) { modelLongitude = tp.lng; modelLatitude = tp.lat; }\r\n const te = tempElevationsRef.current[bimFile.name];\r\n if (te !== undefined) modelElevation = te;\r\n }\r\n\r\n const modelOrigin = [modelLongitude, modelLatitude] as LngLatLike;\r\n // Use the cached terrain elevation (refreshed on moveend); query\r\n // live only while actively editing this model's position. Keeps\r\n // the expensive queryTerrainElevation off the hot path — the\r\n // per-frame query was a main driver of the high-zoom freeze.\r\n const terrainElev = editingBimModelRef.current === bimFile.name\r\n ? (map.queryTerrainElevation([modelLongitude, modelLatitude]) ?? cachedTerrainElev)\r\n : cachedTerrainElev;\r\n const modelAltitude = modelElevation + terrainElev;\r\n const scaling = 1;\r\n\r\n // ── Build renderCamera (VP × M, for Three.js rendering) ───\r\n // Reused temps — render() allocates nothing. Math is identical\r\n // to the prior allocate-every-frame version.\r\n const modelMatrix = map.transform.getMatrixForModel(modelOrigin, modelAltitude);\r\n _scaleVec.set(scaling, scaling, scaling);\r\n _vp.fromArray(args.defaultProjectionData.mainMatrix);\r\n _m.fromArray(modelMatrix).scale(_scaleVec);\r\n renderCamera.projectionMatrix.multiplyMatrices(_vp, _m); // VP × M, into the camera's own matrix\r\n\r\n // camIFCPos = translation of (P⁻¹ · (VP×M))⁻¹\r\n _p.fromArray(args.projectionMatrix).invert(); // _p = P⁻¹\r\n _vm.multiplyMatrices(_p, renderCamera.projectionMatrix).invert();\r\n _camPos.setFromMatrixPosition(_vm);\r\n lodCamera.position.copy(_camPos);\r\n\r\n if (model) {\r\n model.box.getCenter(_center);\r\n _lookTarget.set(0, _center.y, 0);\r\n } else {\r\n _lookTarget.set(0, 0, 0);\r\n }\r\n lodCamera.lookAt(_lookTarget);\r\n lodCamera.fov = args.fov * (180 / Math.PI) + 40;\r\n lodCamera.aspect = map.getCanvas().width / map.getCanvas().height;\r\n lodCamera.updateProjectionMatrix(); // rebuilds projectionMatrix from fov/aspect\r\n lodCamera.updateMatrixWorld(); // rebuilds matrixWorld + matrixWorldInverse\r\n\r\n if (model) {\r\n model.useCamera(lodCamera);\r\n const now = performance.now();\r\n if (now - lastLodUpdate > 50) {\r\n lastLodUpdate = now;\r\n void fragments.core.update();\r\n }\r\n // Render-on-demand: only keep the frame loop alive while the\r\n // camera recently moved (settle window, for fragment\r\n // streaming) or this model is being edited. Idle map ⇒ no\r\n // self-scheduled repaints ⇒ main thread freed (no freeze).\r\n if (\r\n editingBimModelRef.current === bimFile.name ||\r\n now - lastMoveTime < SETTLE_MS\r\n ) {\r\n map.triggerRepaint();\r\n }\r\n }\r\n\r\n this.renderer.resetState();\r\n this.renderer.render(this.scene, renderCamera);\r\n },\r\n\r\n onRemove() {\r\n if (onMapMove) map.off(\"move\", onMapMove);\r\n if (onMapMoveEnd) map.off(\"moveend\", onMapMoveEnd);\r\n if (model) {\r\n model.dispose().catch(console.warn);\r\n model = null;\r\n }\r\n // Dispose all Three.js GPU resources (geometries, materials, textures)\r\n disposeThreeScene(scene);\r\n },\r\n };\r\n };\r\n\r\n void Promise.all(modelsToAdd.map(async (buildingModel) => {\r\n try {\r\n const { fragments } = await getOrCreateShared();\r\n\r\n const layerName = buildingModel.bimFile.name;\r\n if (map.getLayer(layerName)) return;\r\n const scene = new THREE.Scene();\r\n scene.add(new THREE.AmbientLight(0xffffff, 0.8));\r\n const sun = new THREE.DirectionalLight(0xffffff, 1.0);\r\n sun.position.set(10, 20, 10);\r\n scene.add(sun);\r\n\r\n const customLayer = createCustomLayer(buildingModel, fragments, scene);\r\n if (!customLayer) return;\r\n\r\n map.addLayer(customLayer);\r\n addedLayersRef.current.add(layerName);\r\n\r\n } catch (err) {\r\n console.error(\"Error adding BIM layer:\", err);\r\n }\r\n }));\r\n\r\n }, [map, bimModelsAddedToMap]);\r\n\r\n // Cleanup on unmount — dispose shared components and renderer\r\n React.useEffect(() => {\r\n return () => {\r\n if (map) {\r\n addedLayersRef.current.forEach(layerName => {\r\n if (map.getLayer(layerName)) map.removeLayer(layerName);\r\n });\r\n addedLayersRef.current.clear();\r\n }\r\n if (sharedRef.current) {\r\n sharedRef.current.components.dispose();\r\n sharedRef.current = null;\r\n }\r\n if (rendererRef.current) {\r\n rendererRef.current.dispose();\r\n rendererRef.current = null;\r\n }\r\n };\r\n }, [map]);\r\n\r\n return (\r\n <>\r\n {bimModelsAddedToMap.map((buildingModel, index) => {\r\n const { lng, lat } = extractPositionAndRotation(\r\n buildingModel.bimFile, buildingModel.building\r\n );\r\n const isLoading = loadingBuildings.has(\r\n buildingModel.building?.id ?? buildingModel.bimFile.id\r\n );\r\n if (lng === null || lat === null) return null;\r\n return (\r\n <React.Fragment key={buildingModel.bimFile.id + \"-fragment-\" + index}>\r\n {isLoading && (\r\n <Marker\r\n key={buildingModel.bimFile.id + \"-loading-animation\" + index}\r\n latitude={lat}\r\n longitude={lng}\r\n {...markerOcclusionProps}\r\n >\r\n <LR.Loader className=\"animate-spin w-6 h-6 text-gray-700\" />\r\n </Marker>\r\n )}\r\n {/* Invisible hit-target for right-click context menu on WebGL-rendered BIM models */}\r\n {buildingModel.bimFile.name !== editingBimModel && (\r\n <Marker\r\n key={buildingModel.bimFile.id + \"-ctx-target-\" + index}\r\n latitude={lat}\r\n longitude={lng}\r\n {...markerOcclusionProps}\r\n >\r\n <div\r\n className=\"w-10 h-10 opacity-0 cursor-context-menu\"\r\n onContextMenu={(e) => {\r\n e.preventDefault();\r\n setContextMenu({ x: e.clientX, y: e.clientY, bimFile: buildingModel.bimFile });\r\n }}\r\n />\r\n </Marker>\r\n )}\r\n </React.Fragment>\r\n );\r\n })}\r\n {editingBimModel && (() => {\r\n const currentModel = bimModelsAddedToMap.find(bm => bm.bimFile.name === editingBimModel);\r\n if (!currentModel) return null;\r\n const { lng, lat, rotation, elevation } = extractPositionAndRotation(\r\n currentModel.bimFile, currentModel.building\r\n );\r\n return (\r\n <EditPosition\r\n file={currentModel.bimFile}\r\n displayName={currentModel.building?.buildingName || currentModel.bimFile.name}\r\n mode=\"3d\"\r\n initialLat={lat}\r\n initialLng={lng}\r\n initialRotation={rotation}\r\n initialElevation={elevation}\r\n onExitEditMode={handleExitEditMode}\r\n tempPositionsRef={tempPositionsRef}\r\n tempRotationsRef={tempRotationsRef}\r\n tempElevationsRef={tempElevationsRef}\r\n onMapRepaint={handleMapRepaint}\r\n />\r\n );\r\n })()}\r\n\r\n {contextMenu && (\r\n <ViewerContextMenu\r\n x={contextMenu.x}\r\n y={contextMenu.y}\r\n file={{ ...contextMenu.bimFile, isV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B,eAAa,kBAAa,aAAb,mBAAuB,iBAAgB,aAAa,QAAQ;AAAA,UACzE,MAAK;AAAA,UACL,YAAY;AAAA,UACZ,YAAY;AAAA,UACZ,iBAAiB;AAAA,UACjB,kBAAkB;AAAA,UAClB,gBAAgB;AAAA,UAChB;AAAA,UACA;AAAA,UACA;AAAA,UACA,cAAc;AAAA;AAAA,MAClB;AAAA,IAER,GAAG;AAAA,IAEF,eACG;AAAA,MAAC;AAAA;AAAA,QACG,GAAG,YAAY;AAAA,QACf,GAAG,YAAY;AAAA,QACf,MAAM,iCAAK,YAAY,UAAjB,EAA0B,WAAW,KAAK;AAAA,QAChD,SAAS,CAAC,QAAQ,MAAM;AAAA,QACxB,UAAU;AAAA,QACV,SAAS,MAAM,eAAe,IAAI;AAAA;AAAA,IACtC;AAAA,KAER;AAGR;","names":["map"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Building } from "../../../../../../../types/dbTypes";
|
|
2
|
+
import type { BuildingSensorAverage } from "../../../../../../ui/Sensors/buildingSensorColours";
|
|
3
|
+
/**
|
|
4
|
+
* JSON form of a MapLibre expression. Declared structurally so this module needs no maplibre
|
|
5
|
+
* import and its test stays in the node environment.
|
|
6
|
+
*/
|
|
7
|
+
export type PaintExpression = (string | number | boolean | null | PaintExpression)[];
|
|
8
|
+
/** Colour a footprint gets with nothing else to say about it: the tile's own, else grey. */
|
|
9
|
+
export declare const DEFAULT_COLOUR_EXPRESSION: PaintExpression;
|
|
10
|
+
export declare const HOVER_COLOUR = "#e0e0e0";
|
|
11
|
+
/**
|
|
12
|
+
* `[osmId, colour]` pairs ready for a MapLibre `match`, joining sensor averages (keyed by DB
|
|
13
|
+
* building id) to the tile-side OSM ids.
|
|
14
|
+
*
|
|
15
|
+
* Deduped and sorted, both load-bearing: MapLibre rejects a `match` with duplicate labels, which
|
|
16
|
+
* would throw out of `setPaintProperty` and leave the layer on a stale expression, and a stable
|
|
17
|
+
* order keeps the expression identical between renders that resolved the same colours.
|
|
18
|
+
*/
|
|
19
|
+
export declare function osmColourEntries(averages: ReadonlyMap<number, BuildingSensorAverage>, buildings: readonly Pick<Building, "id" | "buildingOsmId">[]): [string, string][];
|
|
20
|
+
/**
|
|
21
|
+
* The layer's `fill-extrusion-color`: hover and click highlights first, then the sensor colour,
|
|
22
|
+
* then the tile default.
|
|
23
|
+
*
|
|
24
|
+
* With no colours to apply this returns the default expression unchanged, so the feature being
|
|
25
|
+
* off reproduces the layer's original paint exactly.
|
|
26
|
+
*/
|
|
27
|
+
export declare function buildingColourExpression({ osmColours, clickedKey, hoveredKey, }: {
|
|
28
|
+
osmColours: readonly (readonly [string, string])[];
|
|
29
|
+
clickedKey?: string | number | null;
|
|
30
|
+
hoveredKey?: string | number | null;
|
|
31
|
+
}): PaintExpression;
|
|
32
|
+
//# sourceMappingURL=buildingColourExpression.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildingColourExpression.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/BuildingLayers/buildingColourExpression.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oDAAoD,CAAC;AAEhG;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,eAAe,CAAC,EAAE,CAAC;AAErF,4FAA4F;AAC5F,eAAO,MAAM,yBAAyB,EAAE,eAA4D,CAAC;AAErG,eAAO,MAAM,YAAY,YAAY,CAAC;AAgBtC;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,qBAAqB,CAAC,EACpD,SAAS,EAAE,SAAS,IAAI,CAAC,QAAQ,EAAE,IAAI,GAAG,eAAe,CAAC,EAAE,GAC3D,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAgBpB;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,EACvC,UAAU,EACV,UAAU,EACV,UAAU,GACX,EAAE;IACD,UAAU,EAAE,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC;IACnD,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACpC,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;CACrC,GAAG,eAAe,CA0BlB"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { highlightColor } from "../../../../../../../types/martinTypes";
|
|
2
|
+
import { lerpHex } from "../../../../../../../utils/colourUtils";
|
|
3
|
+
const DEFAULT_COLOUR_EXPRESSION = ["coalesce", ["get", "colour"], "#cccccc"];
|
|
4
|
+
const HOVER_COLOUR = "#e0e0e0";
|
|
5
|
+
const HOVER_LIFT = 0.18;
|
|
6
|
+
const ID_KEY = ["to-string", ["id"]];
|
|
7
|
+
const PROP_KEY = ["to-string", ["coalesce", ["get", "osm_id"], ""]];
|
|
8
|
+
function matchesKey(key) {
|
|
9
|
+
return ["any", ["==", ID_KEY, key], ["==", PROP_KEY, key]];
|
|
10
|
+
}
|
|
11
|
+
function osmColourEntries(averages, buildings) {
|
|
12
|
+
var _a;
|
|
13
|
+
const seen = /* @__PURE__ */ new Set();
|
|
14
|
+
const entries = [];
|
|
15
|
+
for (const building of buildings) {
|
|
16
|
+
const average = averages.get(building.id);
|
|
17
|
+
if (!average) continue;
|
|
18
|
+
const osmId = String((_a = building.buildingOsmId) != null ? _a : "").trim();
|
|
19
|
+
if (!osmId || seen.has(osmId)) continue;
|
|
20
|
+
seen.add(osmId);
|
|
21
|
+
entries.push([osmId, average.colour]);
|
|
22
|
+
}
|
|
23
|
+
return entries.sort((a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0);
|
|
24
|
+
}
|
|
25
|
+
function buildingColourExpression({
|
|
26
|
+
osmColours,
|
|
27
|
+
clickedKey,
|
|
28
|
+
hoveredKey
|
|
29
|
+
}) {
|
|
30
|
+
var _a;
|
|
31
|
+
let lookup = DEFAULT_COLOUR_EXPRESSION;
|
|
32
|
+
if (osmColours.length > 0) {
|
|
33
|
+
const pairs = osmColours.flatMap(([osmId, colour]) => [osmId, colour]);
|
|
34
|
+
lookup = ["match", ID_KEY, ...pairs, ["match", PROP_KEY, ...pairs, DEFAULT_COLOUR_EXPRESSION]];
|
|
35
|
+
}
|
|
36
|
+
const branches = [];
|
|
37
|
+
const clicked = clickedKey == null ? "" : String(clickedKey);
|
|
38
|
+
const hovered = hoveredKey == null ? "" : String(hoveredKey);
|
|
39
|
+
if (clicked) branches.push(matchesKey(clicked), highlightColor);
|
|
40
|
+
if (hovered) {
|
|
41
|
+
const sensorColour = (_a = osmColours.find(([osmId]) => osmId === hovered)) == null ? void 0 : _a[1];
|
|
42
|
+
branches.push(
|
|
43
|
+
matchesKey(hovered),
|
|
44
|
+
sensorColour ? lerpHex(sensorColour, "#ffffff", HOVER_LIFT) : HOVER_COLOUR
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
if (branches.length === 0) return lookup;
|
|
48
|
+
return ["case", ...branches, lookup];
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
DEFAULT_COLOUR_EXPRESSION,
|
|
52
|
+
HOVER_COLOUR,
|
|
53
|
+
buildingColourExpression,
|
|
54
|
+
osmColourEntries
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=buildingColourExpression.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/BuildingLayers/buildingColourExpression.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport { highlightColor } from \"../../../../../../../types/martinTypes\";\r\nimport { lerpHex } from \"../../../../../../../utils/colourUtils\";\r\n\r\nimport type { Building } from \"../../../../../../../types/dbTypes\";\r\nimport type { BuildingSensorAverage } from \"../../../../../../ui/Sensors/buildingSensorColours\";\r\n\r\n/**\r\n * JSON form of a MapLibre expression. Declared structurally so this module needs no maplibre\r\n * import and its test stays in the node environment.\r\n */\r\nexport type PaintExpression = (string | number | boolean | null | PaintExpression)[];\r\n\r\n/** Colour a footprint gets with nothing else to say about it: the tile's own, else grey. */\r\nexport const DEFAULT_COLOUR_EXPRESSION: PaintExpression = [\"coalesce\", [\"get\", \"colour\"], \"#cccccc\"];\r\n\r\nexport const HOVER_COLOUR = \"#e0e0e0\";\r\n\r\n/** How far a sensor-coloured footprint is lifted toward white on hover. */\r\nconst HOVER_LIFT = 0.18;\r\n\r\n// Two ways the same footprint identifies itself. The MVT feature id is usually the OSM id, but\r\n// some tiles carry it only as a property, so both are tried. Copied from the height expression,\r\n// which already proves the pair parses against these tiles.\r\nconst ID_KEY: PaintExpression = [\"to-string\", [\"id\"]];\r\nconst PROP_KEY: PaintExpression = [\"to-string\", [\"coalesce\", [\"get\", \"osm_id\"], \"\"]];\r\n\r\n/** Matches a footprint by either key, mirroring `buildHeightExpression`. */\r\nfunction matchesKey(key: string): PaintExpression {\r\n return [\"any\", [\"==\", ID_KEY, key], [\"==\", PROP_KEY, key]];\r\n}\r\n\r\n/**\r\n * `[osmId, colour]` pairs ready for a MapLibre `match`, joining sensor averages (keyed by DB\r\n * building id) to the tile-side OSM ids.\r\n *\r\n * Deduped and sorted, both load-bearing: MapLibre rejects a `match` with duplicate labels, which\r\n * would throw out of `setPaintProperty` and leave the layer on a stale expression, and a stable\r\n * order keeps the expression identical between renders that resolved the same colours.\r\n */\r\nexport function osmColourEntries(\r\n averages: ReadonlyMap<number, BuildingSensorAverage>,\r\n buildings: readonly Pick<Building, \"id\" | \"buildingOsmId\">[],\r\n): [string, string][] {\r\n const seen = new Set<string>();\r\n const entries: [string, string][] = [];\r\n\r\n for (const building of buildings) {\r\n const average = averages.get(building.id);\r\n if (!average) continue;\r\n // An empty label would match every feature whose id stringifies to \"\", i.e. every id-less\r\n // building, so a building with no OSM id simply cannot be coloured.\r\n const osmId = String(building.buildingOsmId ?? \"\").trim();\r\n if (!osmId || seen.has(osmId)) continue;\r\n seen.add(osmId);\r\n entries.push([osmId, average.colour]);\r\n }\r\n\r\n return entries.sort((a, b) => (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0));\r\n}\r\n\r\n/**\r\n * The layer's `fill-extrusion-color`: hover and click highlights first, then the sensor colour,\r\n * then the tile default.\r\n *\r\n * With no colours to apply this returns the default expression unchanged, so the feature being\r\n * off reproduces the layer's original paint exactly.\r\n */\r\nexport function buildingColourExpression({\r\n osmColours,\r\n clickedKey,\r\n hoveredKey,\r\n}: {\r\n osmColours: readonly (readonly [string, string])[];\r\n clickedKey?: string | number | null;\r\n hoveredKey?: string | number | null;\r\n}): PaintExpression {\r\n // `match` needs at least one label/output pair, so an empty set short-circuits. The id lookup\r\n // falls back to the property lookup, which falls back to the tile default.\r\n let lookup: PaintExpression = DEFAULT_COLOUR_EXPRESSION;\r\n if (osmColours.length > 0) {\r\n const pairs = osmColours.flatMap(([osmId, colour]) => [osmId, colour]);\r\n lookup = [\"match\", ID_KEY, ...pairs, [\"match\", PROP_KEY, ...pairs, DEFAULT_COLOUR_EXPRESSION]];\r\n }\r\n\r\n const branches: PaintExpression = [];\r\n const clicked = clickedKey == null ? \"\" : String(clickedKey);\r\n const hovered = hoveredKey == null ? \"\" : String(hoveredKey);\r\n if (clicked) branches.push(matchesKey(clicked), highlightColor);\r\n if (hovered) {\r\n // Flat grey would throw away the reading the footprint is carrying, so a sensor-coloured\r\n // building is lifted toward white instead: still obvious feedback, still the same value.\r\n // Buildings with no sensor colour keep the original grey.\r\n const sensorColour = osmColours.find(([osmId]) => osmId === hovered)?.[1];\r\n branches.push(\r\n matchesKey(hovered),\r\n sensorColour ? lerpHex(sensorColour, \"#ffffff\", HOVER_LIFT) : HO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AAS,CAAC,SAAS,QAAQ,GAAG,OAAO,CAAC,SAAS,UAAU,GAAG,OAAO,yBAAyB,CAAC;AAAA,EAC/F;AAEA,QAAM,WAA4B,CAAC;AACnC,QAAM,UAAU,cAAc,OAAO,KAAK,OAAO,UAAU;AAC3D,QAAM,UAAU,cAAc,OAAO,KAAK,OAAO,UAAU;AAC3D,MAAI,QAAS,UAAS,KAAK,WAAW,OAAO,GAAG,cAAc;AAC9D,MAAI,SAAS;AAIX,UAAM,gBAAe,gBAAW,KAAK,CAAC,CAAC,KAAK,MAAM,UAAU,OAAO,MAA9C,mBAAkD;AACvE,aAAS;AAAA,MACP,WAAW,OAAO;AAAA,MAClB,eAAe,QAAQ,cAAc,WAAW,UAAU,IAAI;AAAA,IAChE;AAAA,EACF;AAEA,MAAI,SAAS,WAAW,EAAG,QAAO;AAClC,SAAO,CAAC,QAAQ,GAAG,UAAU,MAAM;AACrC;","names":[]}
|
|
@@ -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;AA8E/B,wBAAgB,aAAa,sBAoN5B"}
|
|
@@ -18,16 +18,23 @@ var __spreadValues = (a, b) => {
|
|
|
18
18
|
return a;
|
|
19
19
|
};
|
|
20
20
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
-
import { Fragment, jsx } from "react/jsx-runtime";
|
|
21
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
22
22
|
import * as React from "react";
|
|
23
23
|
import { Popup } from "react-map-gl/maplibre";
|
|
24
24
|
import { useBuildings } from "../../../../../../../hooks/buildings/buildings";
|
|
25
25
|
import { useBuildingsContext } from "../../../../../../../store";
|
|
26
26
|
import { useBimContext } from "../../../../../../../store/BIM/context";
|
|
27
27
|
import { MapContext } from "../../../../../../../store/Map/context";
|
|
28
|
-
import {
|
|
28
|
+
import { ViewerNames } from "../../../../../../../types/dbTypes";
|
|
29
|
+
import { useBuildingSensorColours } from "../../../../../../ui/Sensors/useBuildingSensorColours";
|
|
29
30
|
import { MapLayerClickPriority } from "../../../../utils/MapEventManager/MapClickManager";
|
|
30
31
|
import MapFeaturePopoverMenu from "../../../MapFeaturePopoverMenu";
|
|
32
|
+
import {
|
|
33
|
+
buildingColourExpression,
|
|
34
|
+
DEFAULT_COLOUR_EXPRESSION,
|
|
35
|
+
osmColourEntries
|
|
36
|
+
} from "./buildingColourExpression";
|
|
37
|
+
import { BuildingSensorMarkers } from "./src/BuildingSensorMarkers";
|
|
31
38
|
const LAYER_ID = "maptiler-3d-buildings";
|
|
32
39
|
function buildLayerFilter() {
|
|
33
40
|
return [
|
|
@@ -48,7 +55,7 @@ function buildHeightExpression(hiddenBimOsmIds) {
|
|
|
48
55
|
["coalesce", ["get", "height"], 5]
|
|
49
56
|
];
|
|
50
57
|
}
|
|
51
|
-
function addBuildingLayer(map, hiddenBimOsmIds) {
|
|
58
|
+
function addBuildingLayer(map, hiddenBimOsmIds, colourExpr) {
|
|
52
59
|
try {
|
|
53
60
|
if (!map.getSource("openmaptiles")) return;
|
|
54
61
|
if (map.getLayer(LAYER_ID)) return;
|
|
@@ -61,7 +68,9 @@ function addBuildingLayer(map, hiddenBimOsmIds) {
|
|
|
61
68
|
minzoom: 14,
|
|
62
69
|
filter: buildLayerFilter(),
|
|
63
70
|
paint: {
|
|
64
|
-
|
|
71
|
+
// Seeded rather than hardcoded: `styledata` re-adds this layer after any setStyle, and
|
|
72
|
+
// the paint effect below will not re-run for it, so the colours would be lost.
|
|
73
|
+
"fill-extrusion-color": colourExpr,
|
|
65
74
|
"fill-extrusion-height": buildHeightExpression(hiddenBimOsmIds),
|
|
66
75
|
"fill-extrusion-base": ["coalesce", ["get", "render_min_height"], 0],
|
|
67
76
|
"fill-extrusion-opacity": [
|
|
@@ -89,6 +98,25 @@ function BuildingLayer() {
|
|
|
89
98
|
const [hoveredFeature, setHoveredFeature] = React.useState(null);
|
|
90
99
|
const [clickedFeature, setClickedFeature] = React.useState(null);
|
|
91
100
|
const [buildingByOsmId, setBuildingByOsmId] = React.useState({});
|
|
101
|
+
const sensorColours = useBuildingSensorColours(ViewerNames.map);
|
|
102
|
+
const { averages, colourKey } = sensorColours;
|
|
103
|
+
const osmColours = React.useMemo(
|
|
104
|
+
() => osmColourEntries(averages, buildings != null ? buildings : []),
|
|
105
|
+
[averages, buildings]
|
|
106
|
+
);
|
|
107
|
+
const colourExpr = React.useMemo(
|
|
108
|
+
() => {
|
|
109
|
+
var _a2;
|
|
110
|
+
return buildingColourExpression({
|
|
111
|
+
osmColours,
|
|
112
|
+
clickedKey: (_a2 = clickedFeature == null ? void 0 : clickedFeature.id) != null ? _a2 : null,
|
|
113
|
+
hoveredKey: hoveredFeature
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
[osmColours, clickedFeature, hoveredFeature]
|
|
117
|
+
);
|
|
118
|
+
const colourExprRef = React.useRef(DEFAULT_COLOUR_EXPRESSION);
|
|
119
|
+
colourExprRef.current = colourExpr;
|
|
92
120
|
const hiddenBimOsmIds = React.useMemo(
|
|
93
121
|
() => Array.from(new Set(
|
|
94
122
|
(bimModelsAddedToMap || []).map((model) => {
|
|
@@ -125,9 +153,9 @@ function BuildingLayer() {
|
|
|
125
153
|
React.useEffect(() => {
|
|
126
154
|
if (!map) return;
|
|
127
155
|
if (map.isStyleLoaded()) {
|
|
128
|
-
addBuildingLayer(map, hiddenBimOsmIds);
|
|
156
|
+
addBuildingLayer(map, hiddenBimOsmIds, colourExprRef.current);
|
|
129
157
|
}
|
|
130
|
-
const onStyleLoad = () => addBuildingLayer(map, hiddenBimOsmIds);
|
|
158
|
+
const onStyleLoad = () => addBuildingLayer(map, hiddenBimOsmIds, colourExprRef.current);
|
|
131
159
|
map.on("styledata", onStyleLoad);
|
|
132
160
|
return () => {
|
|
133
161
|
try {
|
|
@@ -211,40 +239,34 @@ function BuildingLayer() {
|
|
|
211
239
|
}, [map, mapClickManager, buildingByOsmId, hiddenBimOsmIds]);
|
|
212
240
|
React.useEffect(() => {
|
|
213
241
|
if (!map || !map.getLayer(LAYER_ID)) return;
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
MapFeaturePopoverMenu,
|
|
237
|
-
{
|
|
238
|
-
feature: clickedFeature,
|
|
239
|
-
onCloseAction: () => {
|
|
240
|
-
setClickedFeature(null);
|
|
241
|
-
setCompareItems([]);
|
|
242
|
+
map.setPaintProperty(LAYER_ID, "fill-extrusion-color", colourExpr);
|
|
243
|
+
}, [map, colourExpr]);
|
|
244
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
245
|
+
/* @__PURE__ */ jsx(BuildingSensorMarkers, { buildings: buildings != null ? buildings : [], sensorColours }),
|
|
246
|
+
clickedFeature && ((_a = clickedFeature.properties) == null ? void 0 : _a.coordinates) && /* @__PURE__ */ jsx(
|
|
247
|
+
Popup,
|
|
248
|
+
{
|
|
249
|
+
anchor: "bottom",
|
|
250
|
+
closeButton: true,
|
|
251
|
+
closeOnClick: false,
|
|
252
|
+
focusAfterOpen: true,
|
|
253
|
+
latitude: clickedFeature.properties.coordinates[1],
|
|
254
|
+
longitude: clickedFeature.properties.coordinates[0],
|
|
255
|
+
onClose: () => setClickedFeature(null),
|
|
256
|
+
children: /* @__PURE__ */ jsx(
|
|
257
|
+
MapFeaturePopoverMenu,
|
|
258
|
+
{
|
|
259
|
+
feature: clickedFeature,
|
|
260
|
+
onCloseAction: () => {
|
|
261
|
+
setClickedFeature(null);
|
|
262
|
+
setCompareItems([]);
|
|
263
|
+
}
|
|
242
264
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
265
|
+
)
|
|
266
|
+
},
|
|
267
|
+
`maptiler-${clickedFeature.id}-${clickedFeature.properties._popupNonce}`
|
|
268
|
+
)
|
|
269
|
+
] });
|
|
248
270
|
}
|
|
249
271
|
export {
|
|
250
272
|
BuildingLayer
|
|
@@ -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 { highlightColor } from \"../../../../../../../types/martinTypes\";\r\nimport { MapLayerClickPriority } from \"../../../../utils/MapEventManager/MapClickManager\";\r\nimport MapFeaturePopoverMenu from \"../../../MapFeaturePopoverMenu\";\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[]) {\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 \"fill-extrusion-color\": [\"coalesce\", [\"get\", \"colour\"], \"#cccccc\"],\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 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);\r\n }\r\n\r\n const onStyleLoad = () => addBuildingLayer(map, hiddenBimOsmIds);\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 // Update paint property for hover/click highlighting\r\n React.useEffect(() => {\r\n if (!map || !map.getLayer(LAYER_ID)) return;\r\n\r\n const defaultColorExpr = [\"coalesce\", [\"get\", \"colour\"], \"#cccccc\"] as const;\r\n const conditionalColorArgs: any[] = [];\r\n\r\n if (clickedFeature?.id != null) {\r\n conditionalColorArgs.push([\"==\", [\"id\"], clickedFeature.id], highlightColor);\r\n }\r\n if (hoveredFeature != null) {\r\n conditionalColorArgs.push([\"==\", [\"id\"], hoveredFeature], \"#e0e0e0\");\r\n }\r\n\r\n const colorExpr = conditionalColorArgs.length > 0\r\n ? [\"case\", ...conditionalColorArgs, defaultColorExpr]\r\n : defaultColorExpr;\r\n\r\n map.setPaintProperty(LAYER_ID, \"fill-extrusion-color\", colorExpr);\r\n }, [map, hoveredFeature, clickedFeature]);\r\n\r\n return (\r\n <>\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":";;;;;;;;;;;;;;;;;;;;AA2PI,mBAYM,WAZN;AArPJ,YAAY,WAA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f,mBAA2B,gBAC5C;AAAA,IAAC;AAAA;AAAA,MACC,QAAO;AAAA,MACP,aAAa;AAAA,MACb,cAAc;AAAA,MACd,gBAAgB;AAAA,MAEhB,UAAU,eAAe,WAAW,YAAY,CAAC;AAAA,MACjD,WAAW,eAAe,WAAW,YAAY,CAAC;AAAA,MAClD,SAAS,MAAM,kBAAkB,IAAI;AAAA,MAErC;AAAA,QAAC;AAAA;AAAA,UACC,SAAS;AAAA,UACT,eAAe,MAAM;AACnB,8BAAkB,IAAI;AACtB,4BAAgB,CAAC,CAAC;AAAA,UACpB;AAAA;AAAA,MACF;AAAA;AAAA,IAXK,YAAY,eAAe,EAAE,IAAI,eAAe,WAAW,WAAW;AAAA,EAY7E,GAEJ;AAEJ;","names":["_a"]}
|
|
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,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,OA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eAAe,WAAW,WAAW;AAAA,IAY7E;AAAA,KAEJ;AAEJ;","names":["_a"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { Building } from "../../../../../../../../types/dbTypes";
|
|
3
|
+
import type { UseBuildingSensorColoursResult } from "../../../../../../../ui/Sensors/useBuildingSensorColours";
|
|
4
|
+
export interface BuildingSensorMarkersProps {
|
|
5
|
+
buildings: Building[];
|
|
6
|
+
sensorColours: UseBuildingSensorColoursResult;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A count badge at the centre of every building that has sensors of the active type, filled with
|
|
10
|
+
* the same average colour as its footprint.
|
|
11
|
+
*
|
|
12
|
+
* Read-only on purpose: it does not swallow the pointer, so clicking it clicks the footprint
|
|
13
|
+
* underneath and opens the building popover, which is where the sensor readings are listed.
|
|
14
|
+
* The extrusion tint alone says "warmer than that one" but not how many readings back it; the
|
|
15
|
+
* badge carries that count, and the popover carries the breakdown.
|
|
16
|
+
*/
|
|
17
|
+
export declare function BuildingSensorMarkers({ buildings, sensorColours, }: BuildingSensorMarkersProps): React.ReactElement | null;
|
|
18
|
+
//# sourceMappingURL=BuildingSensorMarkers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BuildingSensorMarkers.d.ts","sourceRoot":"","sources":["../../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/BuildingLayers/src/BuildingSensorMarkers.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uCAAuC,CAAC;AACtE,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,0DAA0D,CAAC;AAE/G,MAAM,WAAW,0BAA0B;IACzC,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,aAAa,EAAE,8BAA8B,CAAC;CAC/C;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,SAAS,EACT,aAAa,GACd,EAAE,0BAA0B,GAAG,KAAK,CAAC,YAAY,GAAG,IAAI,CAuDxD"}
|