@collabdt/core 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/dist/core/components/AppSidebarContent.d.ts.map +1 -1
  2. package/dist/core/components/AppSidebarContent.js +2 -7
  3. package/dist/core/components/AppSidebarContent.js.map +1 -1
  4. package/dist/core/components/ui/LegendCard.d.ts +8 -3
  5. package/dist/core/components/ui/LegendCard.d.ts.map +1 -1
  6. package/dist/core/components/ui/LegendCard.js +36 -18
  7. package/dist/core/components/ui/LegendCard.js.map +1 -1
  8. package/dist/core/components/ui/Sensors/SensorDetailDialog.d.ts.map +1 -1
  9. package/dist/core/components/ui/Sensors/SensorDetailDialog.js +56 -19
  10. package/dist/core/components/ui/Sensors/SensorDetailDialog.js.map +1 -1
  11. package/dist/core/components/ui/Sensors/SensorLegend.d.ts +6 -3
  12. package/dist/core/components/ui/Sensors/SensorLegend.d.ts.map +1 -1
  13. package/dist/core/components/ui/Sensors/SensorLegend.js +95 -27
  14. package/dist/core/components/ui/Sensors/SensorLegend.js.map +1 -1
  15. package/dist/core/components/ui/Sensors/SensorMultiSeriesChart.d.ts +10 -4
  16. package/dist/core/components/ui/Sensors/SensorMultiSeriesChart.d.ts.map +1 -1
  17. package/dist/core/components/ui/Sensors/SensorMultiSeriesChart.js +60 -9
  18. package/dist/core/components/ui/Sensors/SensorMultiSeriesChart.js.map +1 -1
  19. package/dist/core/components/ui/Sensors/SensorsSection.d.ts +1 -2
  20. package/dist/core/components/ui/Sensors/SensorsSection.d.ts.map +1 -1
  21. package/dist/core/components/ui/Sensors/SensorsSection.js +34 -4
  22. package/dist/core/components/ui/Sensors/SensorsSection.js.map +1 -1
  23. package/dist/core/components/ui/Sensors/buildingSensorColours.d.ts +49 -0
  24. package/dist/core/components/ui/Sensors/buildingSensorColours.d.ts.map +1 -0
  25. package/dist/core/components/ui/Sensors/buildingSensorColours.js +68 -0
  26. package/dist/core/components/ui/Sensors/buildingSensorColours.js.map +1 -0
  27. package/dist/core/components/ui/Sensors/sensorScope.js +1 -1
  28. package/dist/core/components/ui/Sensors/sensorScope.js.map +1 -1
  29. package/dist/core/components/ui/Sensors/sensorVisibility.d.ts +47 -0
  30. package/dist/core/components/ui/Sensors/sensorVisibility.d.ts.map +1 -0
  31. package/dist/core/components/ui/Sensors/sensorVisibility.js +29 -0
  32. package/dist/core/components/ui/Sensors/sensorVisibility.js.map +1 -0
  33. package/dist/core/components/ui/Sensors/useBuildingSensorColours.d.ts +30 -0
  34. package/dist/core/components/ui/Sensors/useBuildingSensorColours.d.ts.map +1 -0
  35. package/dist/core/components/ui/Sensors/useBuildingSensorColours.js +92 -0
  36. package/dist/core/components/ui/Sensors/useBuildingSensorColours.js.map +1 -0
  37. package/dist/core/components/ui/Sensors/useSensorSeriesMulti.d.ts +1 -1
  38. package/dist/core/components/ui/Sensors/useSensorSeriesMulti.d.ts.map +1 -1
  39. package/dist/core/components/ui/Sensors/useSensorSeriesMulti.js.map +1 -1
  40. package/dist/core/components/viewers/bim/src/tools/AddToBim/src/useSensorMarkers.d.ts.map +1 -1
  41. package/dist/core/components/viewers/bim/src/tools/AddToBim/src/useSensorMarkers.js +17 -17
  42. package/dist/core/components/viewers/bim/src/tools/AddToBim/src/useSensorMarkers.js.map +1 -1
  43. package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/index.d.ts.map +1 -1
  44. package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/index.js +27 -1
  45. package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/index.js.map +1 -1
  46. package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingSensorDetails.d.ts +36 -0
  47. package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingSensorDetails.d.ts.map +1 -0
  48. package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingSensorDetails.js +95 -0
  49. package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingSensorDetails.js.map +1 -0
  50. package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingsTools.d.ts.map +1 -1
  51. package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingsTools.js +55 -42
  52. package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingsTools.js.map +1 -1
  53. package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/buildingColourExpression.d.ts +32 -0
  54. package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/buildingColourExpression.d.ts.map +1 -0
  55. package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/buildingColourExpression.js +56 -0
  56. package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/buildingColourExpression.js.map +1 -0
  57. package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/index.d.ts.map +1 -1
  58. package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/index.js +61 -39
  59. package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/index.js.map +1 -1
  60. package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/src/BuildingSensorMarkers.d.ts +18 -0
  61. package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/src/BuildingSensorMarkers.d.ts.map +1 -0
  62. package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/src/BuildingSensorMarkers.js +61 -0
  63. package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/src/BuildingSensorMarkers.js.map +1 -0
  64. package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/index.d.ts.map +1 -1
  65. package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/index.js +36 -19
  66. package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/index.js.map +1 -1
  67. package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/sensorClusterColour.d.ts +22 -0
  68. package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/sensorClusterColour.d.ts.map +1 -0
  69. package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/sensorClusterColour.js +36 -0
  70. package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/sensorClusterColour.js.map +1 -0
  71. package/dist/core/components/viewers/map/src/MapLayers/src/mapLayersUtils.d.ts +5 -1
  72. package/dist/core/components/viewers/map/src/MapLayers/src/mapLayersUtils.d.ts.map +1 -1
  73. package/dist/core/components/viewers/map/src/MapLayers/src/mapLayersUtils.js +6 -2
  74. package/dist/core/components/viewers/map/src/MapLayers/src/mapLayersUtils.js.map +1 -1
  75. package/dist/core/i18n/messages/en.json +11 -1
  76. package/dist/core/i18n/messages/es.json +11 -1
  77. package/dist/core/i18n/messages/fr.json +11 -1
  78. package/dist/core/store/Menus/context.d.ts.map +1 -1
  79. package/dist/core/store/Menus/context.js +4 -2
  80. package/dist/core/store/Menus/context.js.map +1 -1
  81. package/dist/core/store/Menus/reducer.d.ts +15 -26
  82. package/dist/core/store/Menus/reducer.d.ts.map +1 -1
  83. package/dist/core/store/Menus/reducer.js +38 -4
  84. package/dist/core/store/Menus/reducer.js.map +1 -1
  85. package/dist/core/utils/appContent.d.ts +15 -0
  86. package/dist/core/utils/appContent.d.ts.map +1 -0
  87. package/dist/core/utils/appContent.js +24 -0
  88. package/dist/core/utils/appContent.js.map +1 -0
  89. package/dist/core/utils/colourUtils.d.ts +9 -0
  90. package/dist/core/utils/colourUtils.d.ts.map +1 -1
  91. package/dist/core/utils/colourUtils.js +16 -0
  92. package/dist/core/utils/colourUtils.js.map +1 -1
  93. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../../../src/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingsTools.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 LR from \"lucide-react\";\r\nimport { useTranslations } from \"next-intl\";\r\nimport React from \"react\";\r\n\r\nimport { Button, Label, Skeleton, Switch, Checkbox } from \"../../../../../../../../components/ui/\";\r\nimport {\r\n DropdownMenu,\r\n DropdownMenuContent,\r\n DropdownMenuItem,\r\n DropdownMenuTrigger,\r\n} from \"../../../../../../../../components/ui/DropdownMenu\";\r\nimport { useFileUploadHandler } from \"../../../../../../../../components/ui/FilesManager/src/useFileUploadHandler\";\r\nimport { useFilesByBuildingId, useUploadFileToBuilding } from \"../../../../../../../../hooks/files/files\";\r\nimport { usePermissions } from '../../../../../../../../store'\r\nimport { BuildingsContext, BimContext, MapContext, MenusContext, useMenusContext } from \"../../../../../../../../store\";\r\nimport { ViewerNames } from \"../../../../../../../../types/\";\r\nimport { toggleBimToMap as dispatchToggleBimToMap } from '../../../../../utils/toggleBimToMap';\r\nimport Compare from '../../../../compare';\r\n\r\nimport type { Building, DbFile } from \"../../../../../../../../types/dbTypes\";\r\nimport type { Tool } from \"../../../../../../../../types/tools\";\r\nimport type { MapGeoJSONFeature } from \"maplibre-gl\";\r\n\r\ninterface BuildingToolsProps {\r\n isLoading: boolean;\r\n isError: boolean;\r\n building: Building | null;\r\n feature: MapGeoJSONFeature;\r\n onCloseAction: () => void;\r\n}\r\n\r\nexport default function BuildingTools({\r\n isLoading,\r\n isError,\r\n building,\r\n feature,\r\n onCloseAction\r\n}: BuildingToolsProps) {\r\n\r\n const t = useTranslations('BuildingTools')\r\n // Permissions\r\n const { ability } = usePermissions()\r\n\r\n const { dispatch: menusDispatch } = React.useContext(MenusContext);\r\n const { state: mapState, } = React.useContext(MapContext);\r\n const { dispatch: bimDispatch, state: bimState } = React.useContext(BimContext);\r\n const { bimModelsAddedToMap } = bimState.bim;\r\n const { dispatch: buildingsDispatch } = React.useContext(BuildingsContext);\r\n\r\n const fileInputRef = React.useRef<HTMLInputElement>(null);\r\n const { setView } = useMenusContext();\r\n const { setSelectedItem } = useMenusContext();\r\n\r\n const buildingId = React.useMemo(\r\n () => {\r\n\r\n const featureProps = feature?.properties || {};\r\n const id = Number(featureProps.dbId);\r\n return isNaN(id)\r\n ? null\r\n : id;\r\n\r\n },\r\n [feature?.properties],\r\n );\r\n\r\n const { files } = useFilesByBuildingId(buildingId);\r\n\r\n const bimAdded = React.useMemo(\r\n () => (buildingId\r\n ? mapState.map.bimModelsAddedToMap.includes(buildingId)\r\n : false),\r\n [\r\n mapState.map.bimModelsAddedToMap,\r\n buildingId,\r\n ],\r\n );\r\n\r\n const { uploadFile, isMutating: isUploadingFromHook } = useUploadFileToBuilding(building?.id || null);\r\n\r\n // Local state to track the entire upload process from file selection to completion\r\n const [\r\n isLocallyUploading,\r\n setIsLocallyUploading,\r\n ] = React.useState(false);\r\n\r\n // Combined uploading state\r\n const isUploading = isLocallyUploading || isUploadingFromHook;\r\n\r\n // Use the reusable upload handler without passing bimComponents\r\n const { handleFileUpload } = useFileUploadHandler({\r\n buildingId: buildingId || -1,\r\n uploadFile,\r\n onUploadStart: () => setIsLocallyUploading(true),\r\n onUploadEnd: () => setIsLocallyUploading(false),\r\n customMessages: {\r\n success: t('toastFIleUploadSuccess'),\r\n errorPrefix: t('toastFIleUploadError'),\r\n errorSuffix: t('toastUnknownError'),\r\n noIdError: t('buildingIdRequired')\r\n }\r\n });\r\n\r\n const changeViewer = React.useCallback(\r\n (viewer: ViewerNames) => {\r\n\r\n menusDispatch({\r\n type: \"SET_VIEWER\",\r\n payload: { \"currentViewer\": viewer },\r\n });\r\n\r\n buildingsDispatch({\r\n type: \"SET-CURRENT-BUILDING\",\r\n payload: { building },\r\n });\r\n onCloseAction();\r\n\r\n },\r\n [\r\n menusDispatch,\r\n buildingsDispatch,\r\n building,\r\n onCloseAction\r\n ]\r\n );\r\n\r\n const triggerFileInput = React.useCallback(\r\n () => {\r\n\r\n fileInputRef.current?.click();\r\n\r\n },\r\n [],\r\n );\r\n\r\n const toggleBimToMap = React.useCallback(\r\n (bimFile: DbFile) => {\r\n dispatchToggleBimToMap(bimDispatch, bimFile, building);\r\n\r\n },\r\n [\r\n building,\r\n bimDispatch\r\n ]\r\n );\r\n\r\n const onOpenBimViewer = () => {\r\n buildingsDispatch({ type: \"SET-CURRENT-BUILDING\", payload: { building } });\r\n changeViewer(ViewerNames.bim);\r\n setSelectedItem(building);\r\n }\r\n\r\n const buildingFiles = React.useMemo(\r\n () => files || [],\r\n [files],\r\n );\r\n\r\n const bimFiles = React.useMemo(\r\n () => buildingFiles.filter((file: DbFile) => file.extension?.toLowerCase() === \"frag\"),\r\n [buildingFiles],\r\n )\r\n\r\n const pcFiles = React.useMemo(\r\n () => buildingFiles.filter((file: DbFile) => file.type === 'point-cloud-file' || ['laz', 'las'].includes(file.extension || '')),\r\n [buildingFiles],\r\n )\r\n\r\n const buildingButtons: Tool[] = React.useMemo(\r\n () => [\r\n {\r\n id: \"map-compare-buildings\",\r\n icon: LR.Columns3,\r\n title: t('compareTitle'),\r\n component: Compare,\r\n disabled: !ability.can('read', 'Building')\r\n },\r\n {\r\n id: \"open-building-page\",\r\n icon: LR.Building2,\r\n title: t('openBIMTitle'),\r\n onClick: () => {\r\n\r\n changeViewer(ViewerNames.buildings);\r\n setSelectedItem(building);\r\n setView(\"detail\");\r\n\r\n },\r\n disabled: !ability.can('read', 'Building')\r\n },\r\n {\r\n id: \"open-bim-viewer\",\r\n icon: LR.Box,\r\n title: t('OpenBIMViewerTitle'),\r\n onClick: onOpenBimViewer,\r\n disabled: !ability.can('read', 'File')\r\n },\r\n {\r\n id: 'open-pointcloud',\r\n title: t('openPointCloudTitle'),\r\n icon: LR.Grip,\r\n onClick: () => changeViewer(ViewerNames.pointcloud),\r\n disabled: pcFiles.length === 0 || !ability.can('read', 'File')\r\n },\r\n {\r\n id: \"map-add-file\",\r\n icon: isUploading\r\n ? LR.Loader\r\n : LR.FilePlus,\r\n title: t('addFileTitle'),\r\n onClick: triggerFileInput,\r\n disabled: !ability.can('create', 'File')\r\n },\r\n ],\r\n [\r\n changeViewer,\r\n building,\r\n setSelectedItem,\r\n setView,\r\n isUploading,\r\n triggerFileInput\r\n ]\r\n );\r\n\r\n const onLoadBIM = React.useCallback(\r\n (file: DbFile = null) => {\r\n if (bimFiles.length === 0) return;\r\n toggleBimToMap(bimFiles[0]);\r\n },\r\n [\r\n bimFiles,\r\n toggleBimToMap\r\n ]\r\n );\r\n\r\n const handleEditClick = (fileName: string) => {\r\n bimDispatch({\r\n type: \"EDIT_BIM_MODEL_BY_NAME\",\r\n payload: { editingBimModel: fileName }\r\n });\r\n\r\n onCloseAction();\r\n }\r\n\r\n\r\n return (\r\n <div className=\"space-y-4\">\r\n {/* Hidden file input */}\r\n <input\r\n onChange={(e) => { void handleFileUpload(e.target.files?.[0] || null) }}\r\n ref={fileInputRef}\r\n style={{ \"display\": \"none\" }}\r\n type=\"file\"\r\n />\r\n\r\n {/* BIM Controls */}\r\n {!isError &&\r\n <div className=\"flex items-center space-x-2\">\r\n {isLoading\r\n ? <>\r\n <Skeleton className=\"h-4 w-20\" />\r\n\r\n <Skeleton className=\"h-6 w-10\" />\r\n </>\r\n : (\r\n <div className=\"flex items-center justify-between w-full\">\r\n {bimFiles.length > 1 ? (\r\n <div className=\"flex items-center space-x-2\">\r\n <Label className=\"font-semibold\" htmlFor=\"bim-file-dropdown\">\r\n {t('selectBimLabel')}\r\n </Label>\r\n <DropdownMenu>\r\n <DropdownMenuTrigger asChild>\r\n <Button variant=\"outline\" size=\"sm\" id=\"bim-file-dropdown\">\r\n {bimModelsAddedToMap.length > 0\r\n ? `${bimModelsAddedToMap.filter(model => model.bimFile.attachedFilesBuildingId === buildingId).length} ${t('filesSelected')}`\r\n : t('selectFiles')\r\n }\r\n </Button>\r\n </DropdownMenuTrigger>\r\n <DropdownMenuContent>\r\n {bimFiles.map((file: DbFile) => {\r\n const isSelected = bimModelsAddedToMap.some(model => model.bimFile.name === file.name);\r\n return (\r\n <DropdownMenuItem\r\n key={file.name}\r\n onClick={(e) => {\r\n e.preventDefault();\r\n toggleBimToMap(file);\r\n }}\r\n className=\"flex items-center justify-between cursor-pointer\"\r\n >\r\n <div className=\"flex items-center space-x-2\">\r\n <Checkbox\r\n checked={isSelected}\r\n onClick={(e) => e.stopPropagation()}\r\n onCheckedChange={() => {\r\n toggleBimToMap(file);\r\n }}\r\n />\r\n <span>{file.name}</span>\r\n </div>\r\n {isSelected && (\r\n <Button\r\n onClick={(e) => {\r\n e.preventDefault();\r\n e.stopPropagation();\r\n handleEditClick(file.name);\r\n }}\r\n variant=\"ghost\"\r\n size=\"sm\"\r\n className=\"h-6 w-6 p-0\"\r\n title={t('editBimButton')}\r\n >\r\n <LR.LocationEdit className=\"h-3 w-3\" />\r\n </Button>\r\n )}\r\n </DropdownMenuItem>\r\n );\r\n })}\r\n </DropdownMenuContent>\r\n </DropdownMenu>\r\n </div>\r\n ) : (\r\n <div className=\"flex items-center space-x-2\">\r\n <Label\r\n className={`font-semibold ${bimFiles.length === 0 ? 'text-muted-foreground' : ''}`}\r\n htmlFor=\"show-bim\"\r\n >\r\n {bimAdded ? t('hideBIM') : t('showBIM')}\r\n </Label>\r\n <Switch\r\n id=\"show-bim\"\r\n checked={bimFiles.length === 1 && bimModelsAddedToMap.some(model => model.bimFile.name === bimFiles[0]?.name)}\r\n disabled={bimFiles.length === 0 || !ability.can('read', 'File')}\r\n onCheckedChange={() => onLoadBIM()}\r\n />\r\n </div>\r\n )}\r\n {bimFiles.length === 1 && bimModelsAddedToMap.some(model => model.building.id === buildingId) && (() => {\r\n const selectedModel = bimModelsAddedToMap.find(model => model.building.id === buildingId);\r\n return true ? (\r\n <Button\r\n onClick={() => handleEditClick(selectedModel.bimFile.name)}\r\n variant=\"ghost\"\r\n size=\"sm\"\r\n title={t('editBimButton')}\r\n disabled={!ability.can('update', 'File')}\r\n >\r\n <LR.LocationEdit className=\"h-4 w-4\" />\r\n </Button>\r\n ) : null;\r\n })()}\r\n </div>\r\n )\r\n }\r\n </div>}\r\n\r\n {/* Tool Buttons */}\r\n <div className=\"flex items-center gap-3\">\r\n {isLoading\r\n ? Array.from({ \"length\": 4 }).map((_, index) => (<Skeleton\r\n key={index}\r\n className=\"w-8 h-8 rounded-sm\"\r\n />),)\r\n : (!isError && building ? (\r\n buildingButtons.map((button) => {\r\n if (button.component) {\r\n const ButtonComponent = button.component\r\n const shouldAnimateSpin = button.id === 'map-add-file' && isUploading\r\n return (\r\n <div\r\n key={button.id}\r\n className={`w-8 h-8 rounded-sm border-2 border-gray-200 inline-flex justify-center items-center ${shouldAnimateSpin ? 'animate-spin' : ''}`}\r\n >\r\n <ButtonComponent tool={button} building={building} />\r\n </div>\r\n )\r\n }\r\n return (\r\n <Button\r\n key={button.id}\r\n variant=\"ghost\"\r\n className=\"w-8 h-8 rounded-sm border-2 border-gray-200 inline-flex justify-center items-center\"\r\n aria-label={button.title}\r\n onClick={button.onClick}\r\n title={button.title}\r\n disabled={button.disabled}\r\n >\r\n <button.icon className={`w-6 h-6 ${button.id === 'map-add-file' && isUploading ? 'animate-spin' : ''}`} />\r\n </Button>\r\n )\r\n })\r\n ) : null)}\r\n </div>\r\n </div>\r\n );\r\n\r\n}\r\n"],"mappings":";AA4PM,SAWQ,UAXR,KAWQ,YAXR;AAvPN,YAAY,QAAQ;AACpB,SAAS,uBAAuB;AAChC,OAAO,WAAW;AAElB,SAAS,QAAQ,OAAO,UAAU,QAAQ,gBAAgB;AAC1D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,4BAA4B;AACrC,SAAS,sBAAsB,+BAA+B;AAC9D,SAAS,sBAAsB;AAC/B,SAAS,kBAAkB,YAAY,YAAY,cAAc,uBAAuB;AACxF,SAAS,mBAAmB;AAC5B,SAAS,kBAAkB,8BAA8B;AACzD,OAAO,a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AO,OAAO;AAAA,UACd,UAAU,OAAO;AAAA,UAEjB,8BAAC,OAAO,MAAP,EAAY,WAAW,WAAW,OAAO,OAAO,kBAAkB,cAAc,iBAAiB,EAAE,IAAI;AAAA;AAAA,QARnG,OAAO;AAAA,MASd;AAAA,IAEJ,CAAC,IACC,MACR;AAAA,KACF;AAGJ;","names":[]}
1
+ {"version":3,"sources":["../../../../../../../../../../src/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingsTools.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 LR from \"lucide-react\";\r\nimport { useTranslations } from \"next-intl\";\r\nimport React from \"react\";\r\n\r\nimport { Button, Label, Skeleton, Switch, Checkbox } from \"../../../../../../../../components/ui/\";\r\nimport {\r\n DropdownMenu,\r\n DropdownMenuContent,\r\n DropdownMenuItem,\r\n DropdownMenuTrigger,\r\n} from \"../../../../../../../../components/ui/DropdownMenu\";\r\nimport { useFileUploadHandler } from \"../../../../../../../../components/ui/FilesManager/src/useFileUploadHandler\";\r\nimport { useFilesByBuildingId, useUploadFileToBuilding } from \"../../../../../../../../hooks/files/files\";\r\nimport { usePermissions } from '../../../../../../../../store'\r\nimport { AppConfigContext, BuildingsContext, BimContext, MapContext, MenusContext, useMenusContext } from \"../../../../../../../../store\";\r\nimport { ViewerNames } from \"../../../../../../../../types/\";\r\nimport { hasAppContent } from \"../../../../../../../../utils/appContent\";\r\nimport { toggleBimToMap as dispatchToggleBimToMap } from '../../../../../utils/toggleBimToMap';\r\nimport Compare from '../../../../compare';\r\n\r\nimport type { Building, DbFile } from \"../../../../../../../../types/dbTypes\";\r\nimport type { Tool } from \"../../../../../../../../types/tools\";\r\nimport type { MapGeoJSONFeature } from \"maplibre-gl\";\r\n\r\ninterface BuildingToolsProps {\r\n isLoading: boolean;\r\n isError: boolean;\r\n building: Building | null;\r\n feature: MapGeoJSONFeature;\r\n onCloseAction: () => void;\r\n}\r\n\r\nexport default function BuildingTools({\r\n isLoading,\r\n isError,\r\n building,\r\n feature,\r\n onCloseAction\r\n}: BuildingToolsProps) {\r\n\r\n const t = useTranslations('BuildingTools')\r\n // Permissions\r\n const { ability } = usePermissions()\r\n\r\n const { dispatch: menusDispatch } = React.useContext(MenusContext);\r\n const { state: appConfigState } = React.useContext(AppConfigContext);\r\n const { organization } = appConfigState.appConfig;\r\n const { state: mapState, } = React.useContext(MapContext);\r\n const { dispatch: bimDispatch, state: bimState } = React.useContext(BimContext);\r\n const { bimModelsAddedToMap } = bimState.bim;\r\n const { dispatch: buildingsDispatch } = React.useContext(BuildingsContext);\r\n\r\n const fileInputRef = React.useRef<HTMLInputElement>(null);\r\n const { setView } = useMenusContext();\r\n const { setSelectedItem } = useMenusContext();\r\n\r\n const buildingId = React.useMemo(\r\n () => {\r\n\r\n const featureProps = feature?.properties || {};\r\n const id = Number(featureProps.dbId);\r\n return isNaN(id)\r\n ? null\r\n : id;\r\n\r\n },\r\n [feature?.properties],\r\n );\r\n\r\n const { files } = useFilesByBuildingId(buildingId);\r\n\r\n const bimAdded = React.useMemo(\r\n () => (buildingId\r\n ? mapState.map.bimModelsAddedToMap.includes(buildingId)\r\n : false),\r\n [\r\n mapState.map.bimModelsAddedToMap,\r\n buildingId,\r\n ],\r\n );\r\n\r\n const { uploadFile, isMutating: isUploadingFromHook } = useUploadFileToBuilding(building?.id || null);\r\n\r\n // Local state to track the entire upload process from file selection to completion\r\n const [\r\n isLocallyUploading,\r\n setIsLocallyUploading,\r\n ] = React.useState(false);\r\n\r\n // Combined uploading state\r\n const isUploading = isLocallyUploading || isUploadingFromHook;\r\n\r\n // Use the reusable upload handler without passing bimComponents\r\n const { handleFileUpload } = useFileUploadHandler({\r\n buildingId: buildingId || -1,\r\n uploadFile,\r\n onUploadStart: () => setIsLocallyUploading(true),\r\n onUploadEnd: () => setIsLocallyUploading(false),\r\n customMessages: {\r\n success: t('toastFIleUploadSuccess'),\r\n errorPrefix: t('toastFIleUploadError'),\r\n errorSuffix: t('toastUnknownError'),\r\n noIdError: t('buildingIdRequired')\r\n }\r\n });\r\n\r\n const changeViewer = React.useCallback(\r\n (viewer: ViewerNames) => {\r\n\r\n menusDispatch({\r\n type: \"SET_VIEWER\",\r\n payload: { \"currentViewer\": viewer },\r\n });\r\n\r\n buildingsDispatch({\r\n type: \"SET-CURRENT-BUILDING\",\r\n payload: { building },\r\n });\r\n onCloseAction();\r\n\r\n },\r\n [\r\n menusDispatch,\r\n buildingsDispatch,\r\n building,\r\n onCloseAction\r\n ]\r\n );\r\n\r\n const triggerFileInput = React.useCallback(\r\n () => {\r\n\r\n fileInputRef.current?.click();\r\n\r\n },\r\n [],\r\n );\r\n\r\n const toggleBimToMap = React.useCallback(\r\n (bimFile: DbFile) => {\r\n dispatchToggleBimToMap(bimDispatch, bimFile, building);\r\n\r\n },\r\n [\r\n building,\r\n bimDispatch\r\n ]\r\n );\r\n\r\n const onOpenBimViewer = () => {\r\n buildingsDispatch({ type: \"SET-CURRENT-BUILDING\", payload: { building } });\r\n changeViewer(ViewerNames.bim);\r\n setSelectedItem(building);\r\n }\r\n\r\n const buildingFiles = React.useMemo(\r\n () => files || [],\r\n [files],\r\n );\r\n\r\n const bimFiles = React.useMemo(\r\n () => buildingFiles.filter((file: DbFile) => file.extension?.toLowerCase() === \"frag\"),\r\n [buildingFiles],\r\n )\r\n\r\n const pcFiles = React.useMemo(\r\n () => buildingFiles.filter((file: DbFile) => file.type === 'point-cloud-file' || ['laz', 'las'].includes(file.extension || '')),\r\n [buildingFiles],\r\n )\r\n\r\n const buildingButtons: Tool[] = React.useMemo(\r\n () => {\r\n\r\n /** `opensViewer` gates the tool on the organization's app content, not on permissions. */\r\n const tools: (Tool & { opensViewer?: ViewerNames })[] = [\r\n {\r\n id: \"map-compare-buildings\",\r\n icon: LR.Columns3,\r\n title: t('compareTitle'),\r\n component: Compare,\r\n disabled: !ability.can('read', 'Building')\r\n },\r\n {\r\n id: \"open-building-page\",\r\n icon: LR.Building2,\r\n title: t('openBIMTitle'),\r\n onClick: () => {\r\n\r\n changeViewer(ViewerNames.buildings);\r\n setSelectedItem(building);\r\n setView(\"detail\");\r\n\r\n },\r\n disabled: !ability.can('read', 'Building'),\r\n opensViewer: ViewerNames.buildings\r\n },\r\n {\r\n id: \"open-bim-viewer\",\r\n icon: LR.Box,\r\n title: t('OpenBIMViewerTitle'),\r\n onClick: onOpenBimViewer,\r\n disabled: !ability.can('read', 'File'),\r\n opensViewer: ViewerNames.bim\r\n },\r\n {\r\n id: 'open-pointcloud',\r\n title: t('openPointCloudTitle'),\r\n icon: LR.Grip,\r\n onClick: () => changeViewer(ViewerNames.pointcloud),\r\n disabled: pcFiles.length === 0 || !ability.can('read', 'File'),\r\n opensViewer: ViewerNames.pointcloud\r\n },\r\n {\r\n id: \"map-add-file\",\r\n icon: isUploading\r\n ? LR.Loader\r\n : LR.FilePlus,\r\n title: t('addFileTitle'),\r\n onClick: triggerFileInput,\r\n disabled: !ability.can('create', 'File')\r\n },\r\n ];\r\n\r\n // Hidden, not disabled: a tool that navigates somewhere the sidebar does not offer is a\r\n // dead end, so it should not be on screen at all. Same rule the sidebar applies.\r\n return tools.filter(\r\n tool => tool.opensViewer == null || hasAppContent(organization, tool.opensViewer),\r\n );\r\n\r\n },\r\n [\r\n changeViewer,\r\n building,\r\n setSelectedItem,\r\n setView,\r\n isUploading,\r\n triggerFileInput,\r\n organization,\r\n pcFiles.length\r\n ]\r\n );\r\n\r\n const onLoadBIM = React.useCallback(\r\n (file: DbFile = null) => {\r\n if (bimFiles.length === 0) return;\r\n toggleBimToMap(bimFiles[0]);\r\n },\r\n [\r\n bimFiles,\r\n toggleBimToMap\r\n ]\r\n );\r\n\r\n const handleEditClick = (fileName: string) => {\r\n bimDispatch({\r\n type: \"EDIT_BIM_MODEL_BY_NAME\",\r\n payload: { editingBimModel: fileName }\r\n });\r\n\r\n onCloseAction();\r\n }\r\n\r\n\r\n return (\r\n <div className=\"space-y-4\">\r\n {/* Hidden file input */}\r\n <input\r\n onChange={(e) => { void handleFileUpload(e.target.files?.[0] || null) }}\r\n ref={fileInputRef}\r\n style={{ \"display\": \"none\" }}\r\n type=\"file\"\r\n />\r\n\r\n {/* BIM Controls */}\r\n {!isError &&\r\n <div className=\"flex items-center space-x-2\">\r\n {isLoading\r\n ? <>\r\n <Skeleton className=\"h-4 w-20\" />\r\n\r\n <Skeleton className=\"h-6 w-10\" />\r\n </>\r\n : (\r\n <div className=\"flex items-center justify-between w-full\">\r\n {bimFiles.length > 1 ? (\r\n <div className=\"flex items-center space-x-2\">\r\n <Label className=\"font-semibold\" htmlFor=\"bim-file-dropdown\">\r\n {t('selectBimLabel')}\r\n </Label>\r\n <DropdownMenu>\r\n <DropdownMenuTrigger asChild>\r\n <Button variant=\"outline\" size=\"sm\" id=\"bim-file-dropdown\">\r\n {bimModelsAddedToMap.length > 0\r\n ? `${bimModelsAddedToMap.filter(model => model.bimFile.attachedFilesBuildingId === buildingId).length} ${t('filesSelected')}`\r\n : t('selectFiles')\r\n }\r\n </Button>\r\n </DropdownMenuTrigger>\r\n <DropdownMenuContent>\r\n {bimFiles.map((file: DbFile) => {\r\n const isSelected = bimModelsAddedToMap.some(model => model.bimFile.name === file.name);\r\n return (\r\n <DropdownMenuItem\r\n key={file.name}\r\n onClick={(e) => {\r\n e.preventDefault();\r\n toggleBimToMap(file);\r\n }}\r\n className=\"flex items-center justify-between cursor-pointer\"\r\n >\r\n <div className=\"flex items-center space-x-2\">\r\n <Checkbox\r\n checked={isSelected}\r\n onClick={(e) => e.stopPropagation()}\r\n onCheckedChange={() => {\r\n toggleBimToMap(file);\r\n }}\r\n />\r\n <span>{file.name}</span>\r\n </div>\r\n {isSelected && (\r\n <Button\r\n onClick={(e) => {\r\n e.preventDefault();\r\n e.stopPropagation();\r\n handleEditClick(file.name);\r\n }}\r\n variant=\"ghost\"\r\n size=\"sm\"\r\n className=\"h-6 w-6 p-0\"\r\n title={t('editBimButton')}\r\n >\r\n <LR.LocationEdit className=\"h-3 w-3\" />\r\n </Button>\r\n )}\r\n </DropdownMenuItem>\r\n );\r\n })}\r\n </DropdownMenuContent>\r\n </DropdownMenu>\r\n </div>\r\n ) : (\r\n <div className=\"flex items-center space-x-2\">\r\n <Label\r\n className={`font-semibold ${bimFiles.length === 0 ? 'text-muted-foreground' : ''}`}\r\n htmlFor=\"show-bim\"\r\n >\r\n {bimAdded ? t('hideBIM') : t('showBIM')}\r\n </Label>\r\n <Switch\r\n id=\"show-bim\"\r\n checked={bimFiles.length === 1 && bimModelsAddedToMap.some(model => model.bimFile.name === bimFiles[0]?.name)}\r\n disabled={bimFiles.length === 0 || !ability.can('read', 'File')}\r\n onCheckedChange={() => onLoadBIM()}\r\n />\r\n </div>\r\n )}\r\n {bimFiles.length === 1 && bimModelsAddedToMap.some(model => model.building.id === buildingId) && (() => {\r\n const selectedModel = bimModelsAddedToMap.find(model => model.building.id === buildingId);\r\n return true ? (\r\n <Button\r\n onClick={() => handleEditClick(selectedModel.bimFile.name)}\r\n variant=\"ghost\"\r\n size=\"sm\"\r\n title={t('editBimButton')}\r\n disabled={!ability.can('update', 'File')}\r\n >\r\n <LR.LocationEdit className=\"h-4 w-4\" />\r\n </Button>\r\n ) : null;\r\n })()}\r\n </div>\r\n )\r\n }\r\n </div>}\r\n\r\n {/* Tool Buttons */}\r\n <div className=\"flex items-center gap-3\">\r\n {isLoading\r\n ? Array.from({ \"length\": 4 }).map((_, index) => (<Skeleton\r\n key={index}\r\n className=\"w-8 h-8 rounded-sm\"\r\n />),)\r\n : (!isError && building ? (\r\n buildingButtons.map((button) => {\r\n if (button.component) {\r\n const ButtonComponent = button.component\r\n const shouldAnimateSpin = button.id === 'map-add-file' && isUploading\r\n return (\r\n <div\r\n key={button.id}\r\n className={`w-8 h-8 rounded-sm border-2 border-gray-200 inline-flex justify-center items-center ${shouldAnimateSpin ? 'animate-spin' : ''}`}\r\n >\r\n <ButtonComponent tool={button} building={building} />\r\n </div>\r\n )\r\n }\r\n return (\r\n <Button\r\n key={button.id}\r\n variant=\"ghost\"\r\n className=\"w-8 h-8 rounded-sm border-2 border-gray-200 inline-flex justify-center items-center\"\r\n aria-label={button.title}\r\n onClick={button.onClick}\r\n title={button.title}\r\n disabled={button.disabled}\r\n >\r\n <button.icon className={`w-6 h-6 ${button.id === 'map-add-file' && isUploading ? 'animate-spin' : ''}`} />\r\n </Button>\r\n )\r\n })\r\n ) : null)}\r\n </div>\r\n </div>\r\n );\r\n\r\n}\r\n"],"mappings":";AA+QM,SAWQ,UAXR,KAWQ,YAXR;AA1QN,YAAY,QAAQ;AACpB,SAAS,uBAAuB;AAChC,OAAO,WAAW;AAElB,SAAS,QAAQ,OAAO,UAAU,QAAQ,gBAAgB;AAC1D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,4BAA4B;AACrC,SAAS,sBAAsB,+BAA+B;AAC9D,SAAS,sBAAsB;AAC/B,SAAS,kBAAkB,kBAAkB,YAAY,YAAY,cAAc,uBAAuB;AAC1G,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB,8BAA8B;AACzD,OAAO,aAAa;AAcL,SAAR,cAA+B;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAuB;AAErB,QAAM,IAAI,gBAAgB,eAAe;AAEzC,QAAM,EAAE,QAAQ,IAAI,eAAe;AAEnC,QAAM,EAAE,UAAU,cAAc,IAAI,MAAM,WAAW,YAAY;AACjE,QAAM,EAAE,OAAO,eAAe,IAAI,MAAM,WAAW,gBAAgB;AACnE,QAAM,EAAE,aAAa,IAAI,eAAe;AACxC,QAAM,EAAE,OAAO,SAAU,IAAI,MAAM,WAAW,UAAU;AACxD,QAAM,EAAE,UAAU,aAAa,OAAO,SAAS,IAAI,MAAM,WAAW,UAAU;AAC9E,QAAM,EAAE,oBAAoB,IAAI,SA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,OAAO;AAAA,MASd;AAAA,IAEJ,CAAC,IACC,MACR;AAAA,KACF;AAGJ;","names":[]}
@@ -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) : HOVER_COLOUR,\r\n );\r\n }\r\n\r\n if (branches.length === 0) return lookup;\r\n return [\"case\", ...branches, lookup];\r\n}\r\n"],"mappings":"AAGA,SAAS,sBAAsB;AAC/B,SAAS,eAAe;AAYjB,MAAM,4BAA6C,CAAC,YAAY,CAAC,OAAO,QAAQ,GAAG,SAAS;AAE5F,MAAM,eAAe;AAG5B,MAAM,aAAa;AAKnB,MAAM,SAA0B,CAAC,aAAa,CAAC,IAAI,CAAC;AACpD,MAAM,WAA4B,CAAC,aAAa,CAAC,YAAY,CAAC,OAAO,QAAQ,GAAG,EAAE,CAAC;AAGnF,SAAS,WAAW,KAA8B;AAChD,SAAO,CAAC,OAAO,CAAC,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,UAAU,GAAG,CAAC;AAC3D;AAUO,SAAS,iBACd,UACA,WACoB;AA7CtB;AA8CE,QAAM,OAAO,oBAAI,IAAY;AAC7B,QAAM,UAA8B,CAAC;AAErC,aAAW,YAAY,WAAW;AAChC,UAAM,UAAU,SAAS,IAAI,SAAS,EAAE;AACxC,QAAI,CAAC,QAAS;AAGd,UAAM,QAAQ,QAAO,cAAS,kBAAT,YAA0B,EAAE,EAAE,KAAK;AACxD,QAAI,CAAC,SAAS,KAAK,IAAI,KAAK,EAAG;AAC/B,SAAK,IAAI,KAAK;AACd,YAAQ,KAAK,CAAC,OAAO,QAAQ,MAAM,CAAC;AAAA,EACtC;AAEA,SAAO,QAAQ,KAAK,CAAC,GAAG,MAAO,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,IAAI,CAAE;AACxE;AASO,SAAS,yBAAyB;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AACF,GAIoB;AA9EpB;AAiFE,MAAI,SAA0B;AAC9B,MAAI,WAAW,SAAS,GAAG;AACzB,UAAM,QAAQ,WAAW,QAAQ,CAAC,CAAC,OAAO,MAAM,MAAM,CAAC,OAAO,MAAM,CAAC;AACrE,aAAS,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;AAmE/B,wBAAgB,aAAa,sBAyM5B"}
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 { highlightColor } from "../../../../../../../types/martinTypes";
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
- "fill-extrusion-color": ["coalesce", ["get", "colour"], "#cccccc"],
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
- const defaultColorExpr = ["coalesce", ["get", "colour"], "#cccccc"];
215
- const conditionalColorArgs = [];
216
- if ((clickedFeature == null ? void 0 : clickedFeature.id) != null) {
217
- conditionalColorArgs.push(["==", ["id"], clickedFeature.id], highlightColor);
218
- }
219
- if (hoveredFeature != null) {
220
- conditionalColorArgs.push(["==", ["id"], hoveredFeature], "#e0e0e0");
221
- }
222
- const colorExpr = conditionalColorArgs.length > 0 ? ["case", ...conditionalColorArgs, defaultColorExpr] : defaultColorExpr;
223
- map.setPaintProperty(LAYER_ID, "fill-extrusion-color", colorExpr);
224
- }, [map, hoveredFeature, clickedFeature]);
225
- return /* @__PURE__ */ jsx(Fragment, { children: clickedFeature && ((_a = clickedFeature.properties) == null ? void 0 : _a.coordinates) && /* @__PURE__ */ jsx(
226
- Popup,
227
- {
228
- anchor: "bottom",
229
- closeButton: true,
230
- closeOnClick: false,
231
- focusAfterOpen: true,
232
- latitude: clickedFeature.properties.coordinates[1],
233
- longitude: clickedFeature.properties.coordinates[0],
234
- onClose: () => setClickedFeature(null),
235
- children: /* @__PURE__ */ jsx(
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
- `maptiler-${clickedFeature.id}-${clickedFeature.properties._popupNonce}`
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,WAAW;AACvB,SAAS,aAAa;AAEtB,SAAS,oBAAoB;AAC7B,SAAS,2BAA2B;AACpC,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAC/B,SAAS,6BAA6B;AACtC,OAAO,2BAA2B;AAIlC,MAAM,WAAW;AAEjB,SAAS,mBAAmB;AAC1B,SAAO;AAAA,IACL;AAAA,IACA,CAAC,MAAM,CAAC,OAA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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,OAAO,QAAQ,GAAG,EAAE,CAAC,GAAG,CAAC,WAAW,eAAe,CAAC;AAAA,IACzF;AAAA,IACA;AAAA,IACA,CAAC,YAAY,CAAC,OAAO,QAAQ,GAAG,CAAC;AAAA,EACnC;AACF;AAEA,SAAS,iBAAiB,KAAU,iBAA2B,YAA6B;AAC1F,MAAI;AACF,QAAI,CAAC,IAAI,UAAU,cAAc,EAAG;AACpC,QAAI,IAAI,SAAS,Q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A,IACF;AACA,QAAI,GAAG,aAAa,UAAU,WAAW;AACzC,QAAI,GAAG,cAAc,UAAU,gBAAgB;AAE/C,WAAO,MAAM;AACX,sBAAgB,WAAW,QAAQ;AACnC,UAAI,IAAI,aAAa,UAAU,WAAW;AAC1C,UAAI,IAAI,cAAc,UAAU,gBAAgB;AAAA,IAClD;AAAA,EACF,GAAG,CAAC,KAAK,iBAAiB,iBAAiB,eAAe,CAAC;AAK3D,QAAM,UAAU,MAAM;AACpB,QAAI,CAAC,OAAO,CAAC,IAAI,SAAS,QAAQ,EAAG;AACrC,QAAI,iBAAiB,UAAU,wBAAwB,UAAU;AAAA,EACnE,GAAG,CAAC,KAAK,UAAU,CAAC;AAEpB,SACE,iCACE;AAAA,wBAAC,yBAAsB,WAAW,gCAAa,CAAC,GAAG,eAA8B;AAAA,IAChF,oBAAkB,oBAAe,eAAf,mBAA2B,gBAC5C;AAAA,MAAC;AAAA;AAAA,QACC,QAAO;AAAA,QACP,aAAa;AAAA,QACb,cAAc;AAAA,QACd,gBAAgB;AAAA,QAEhB,UAAU,eAAe,WAAW,YAAY,CAAC;AAAA,QACjD,WAAW,eAAe,WAAW,YAAY,CAAC;AAAA,QAClD,SAAS,MAAM,kBAAkB,IAAI;AAAA,QAErC;AAAA,UAAC;AAAA;AAAA,YACC,SAAS;AAAA,YACT,eAAe,MAAM;AACnB,gCAAkB,IAAI;AACtB,8BAAgB,CAAC,CAAC;AAAA,YACpB;AAAA;AAAA,QACF;AAAA;AAAA,MAXK,YAAY,eAAe,EAAE,IAAI,eAAe,WAAW,WAAW;AAAA,IAY7E;AAAA,KAEJ;AAEJ;","names":["_a"]}
@@ -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;AAK/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,CAsDxD"}
@@ -0,0 +1,61 @@
1
+ "use client";
2
+ import { Fragment, jsx } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import { Marker } from "react-map-gl/maplibre";
5
+ import { readableTextColour } from "../../../../../../../../utils/colourUtils";
6
+ function BuildingSensorMarkers({
7
+ buildings,
8
+ sensorColours
9
+ }) {
10
+ const { typeId, sensorType, averages, sensorsByBuilding } = sensorColours;
11
+ const marked = React.useMemo(
12
+ () => buildings.filter((building) => {
13
+ var _a, _b;
14
+ return building.buildingLongitude != null && building.buildingLatitude != null && ((_b = (_a = sensorsByBuilding.get(building.id)) == null ? void 0 : _a.length) != null ? _b : 0) > 0;
15
+ }),
16
+ [buildings, sensorsByBuilding]
17
+ );
18
+ if (typeId == null || !sensorType) return null;
19
+ return /* @__PURE__ */ jsx(Fragment, { children: marked.map((building) => {
20
+ var _a, _b, _c;
21
+ const count = (_b = (_a = sensorsByBuilding.get(building.id)) == null ? void 0 : _a.length) != null ? _b : 0;
22
+ const average = averages.get(building.id);
23
+ const background = (_c = average == null ? void 0 : average.colour) != null ? _c : "hsl(var(--muted))";
24
+ return /* @__PURE__ */ jsx(
25
+ Marker,
26
+ {
27
+ longitude: building.buildingLongitude,
28
+ latitude: building.buildingLatitude,
29
+ anchor: "center",
30
+ style: { pointerEvents: "none" },
31
+ children: /* @__PURE__ */ jsx(
32
+ "div",
33
+ {
34
+ "aria-hidden": "true",
35
+ style: {
36
+ width: "28px",
37
+ height: "28px",
38
+ borderRadius: "50%",
39
+ border: "2px solid white",
40
+ backgroundColor: background,
41
+ color: average ? readableTextColour(average.colour) : "hsl(var(--foreground))",
42
+ boxShadow: "0 1px 4px rgba(0,0,0,0.4)",
43
+ fontSize: "12px",
44
+ fontWeight: 600,
45
+ fontVariantNumeric: "tabular-nums",
46
+ display: "flex",
47
+ alignItems: "center",
48
+ justifyContent: "center"
49
+ },
50
+ children: count
51
+ }
52
+ )
53
+ },
54
+ `sensor-count-${building.id}`
55
+ );
56
+ }) });
57
+ }
58
+ export {
59
+ BuildingSensorMarkers
60
+ };
61
+ //# sourceMappingURL=BuildingSensorMarkers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/BuildingLayers/src/BuildingSensorMarkers.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 React from \"react\";\r\nimport { Marker } from \"react-map-gl/maplibre\";\r\n\r\nimport { readableTextColour } from \"../../../../../../../../utils/colourUtils\";\r\n\r\nimport type { Building } from \"../../../../../../../../types/dbTypes\";\r\nimport type { UseBuildingSensorColoursResult } from \"../../../../../../../ui/Sensors/useBuildingSensorColours\";\r\n\r\nexport interface BuildingSensorMarkersProps {\r\n buildings: Building[];\r\n sensorColours: UseBuildingSensorColoursResult;\r\n}\r\n\r\n/**\r\n * A count badge at the centre of every building that has sensors of the active type, filled with\r\n * the same average colour as its footprint.\r\n *\r\n * Read-only on purpose: it does not swallow the pointer, so clicking it clicks the footprint\r\n * underneath and opens the building popover, which is where the sensor readings are listed.\r\n * The extrusion tint alone says \"warmer than that one\" but not how many readings back it; the\r\n * badge carries that count, and the popover carries the breakdown.\r\n */\r\nexport function BuildingSensorMarkers({\r\n buildings,\r\n sensorColours,\r\n}: BuildingSensorMarkersProps): React.ReactElement | null {\r\n const { typeId, sensorType, averages, sensorsByBuilding } = sensorColours;\r\n\r\n const marked = React.useMemo(\r\n () => buildings.filter(building =>\r\n building.buildingLongitude != null\r\n && building.buildingLatitude != null\r\n && (sensorsByBuilding.get(building.id)?.length ?? 0) > 0),\r\n [buildings, sensorsByBuilding],\r\n );\r\n\r\n if (typeId == null || !sensorType) return null;\r\n\r\n return (\r\n <>\r\n {marked.map(building => {\r\n const count = sensorsByBuilding.get(building.id)?.length ?? 0;\r\n const average = averages.get(building.id);\r\n // No average means no usable domain or nothing reporting yet: the badge still counts the\r\n // sensors, it just cannot claim a colour for them.\r\n const background = average?.colour ?? \"hsl(var(--muted))\";\r\n return (\r\n <Marker\r\n key={`sensor-count-${building.id}`}\r\n longitude={building.buildingLongitude as number}\r\n latitude={building.buildingLatitude as number}\r\n anchor=\"center\"\r\n style={{ pointerEvents: \"none\" }}\r\n >\r\n <div\r\n aria-hidden=\"true\"\r\n style={{\r\n width: \"28px\",\r\n height: \"28px\",\r\n borderRadius: \"50%\",\r\n border: \"2px solid white\",\r\n backgroundColor: background,\r\n color: average ? readableTextColour(average.colour) : \"hsl(var(--foreground))\",\r\n boxShadow: \"0 1px 4px rgba(0,0,0,0.4)\",\r\n fontSize: \"12px\",\r\n fontWeight: 600,\r\n fontVariantNumeric: \"tabular-nums\",\r\n display: \"flex\",\r\n alignItems: \"center\",\r\n justifyContent: \"center\",\r\n }}\r\n >\r\n {count}\r\n </div>\r\n </Marker>\r\n );\r\n })}\r\n </>\r\n );\r\n}\r\n"],"mappings":";AA4CI,mBAeQ,WAfR;AAvCJ,YAAY,WAAW;AACvB,SAAS,cAAc;AAEvB,SAAS,0BAA0B;AAmB5B,SAAS,sBAAsB;AAAA,EACpC;AAAA,EACA;AACF,GAA0D;AACxD,QAAM,EAAE,QAAQ,YAAY,UAAU,kBAAkB,IAAI;AAE5D,QAAM,SAAS,MAAM;AAAA,IACnB,MAAM,UAAU,OAAO,cAAS;AAlCpC;AAmCM,sBAAS,qBAAqB,QAC3B,SAAS,oBAAoB,UAC5B,6BAAkB,IAAI,SAAS,EAAE,MAAjC,mBAAoC,WAApC,YAA8C,KAAK;AAAA,KAAC;AAAA,IAC1D,CAAC,WAAW,iBAAiB;AAAA,EAC/B;AAEA,MAAI,UAAU,QAAQ,CAAC,WAAY,QAAO;AAE1C,SACE,gCACG,iBAAO,IAAI,cAAY;AA7C9B;AA8CQ,UAAM,SAAQ,6BAAkB,IAAI,SAAS,EAAE,MAAjC,mBAAoC,WAApC,YAA8C;AAC5D,UAAM,UAAU,SAAS,IAAI,SAAS,EAAE;AAGxC,UAAM,cAAa,wCAAS,WAAT,YAAmB;AACtC,WACE;AAAA,MAAC;AAAA;AAAA,QAEC,WAAW,SAAS;AAAA,QACpB,UAAU,SAAS;AAAA,QACnB,QAAO;AAAA,QACP,OAAO,EAAE,eAAe,OAAO;AAAA,QAE/B;AAAA,UAAC;AAAA;AAAA,YACC,eAAY;AAAA,YACZ,OAAO;AAAA,cACL,OAAO;AAAA,cACP,QAAQ;AAAA,cACR,cAAc;AAAA,cACd,QAAQ;AAAA,cACR,iBAAiB;AAAA,cACjB,OAAO,UAAU,mBAAmB,QAAQ,MAAM,IAAI;AAAA,cACtD,WAAW;AAAA,cACX,UAAU;AAAA,cACV,YAAY;AAAA,cACZ,oBAAoB;AAAA,cACpB,SAAS;AAAA,cACT,YAAY;AAAA,cACZ,gBAAgB;AAAA,YAClB;AAAA,YAEC;AAAA;AAAA,QACH;AAAA;AAAA,MAzBK,gBAAgB,SAAS,EAAE;AAAA,IA0BlC;AAAA,EAEJ,CAAC,GACH;AAEJ;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/SensorsLayer/index.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAoE9B,eAAO,MAAM,YAAY,yBA8WxB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/SensorsLayer/index.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAuE9B,eAAO,MAAM,YAAY,yBA2XxB,CAAA"}