@collabdt/core 0.11.2 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/components/ui/FilesManager/src/FileItemComponent.js.map +1 -1
- package/dist/core/components/ui/uploadFile.d.ts +3 -2
- package/dist/core/components/ui/uploadFile.d.ts.map +1 -1
- package/dist/core/components/ui/uploadFile.js +8 -7
- package/dist/core/components/ui/uploadFile.js.map +1 -1
- package/dist/core/components/viewers/bim/src/BimLoadingState/index.js +1 -1
- package/dist/core/components/viewers/bim/src/BimLoadingState/index.js.map +1 -1
- package/dist/core/components/viewers/bim/src/BimSidebar/src/FileTab/src/usePlaceableFileRows.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/src/BimSidebar/src/FileTab/src/usePlaceableFileRows.js +12 -13
- package/dist/core/components/viewers/bim/src/BimSidebar/src/FileTab/src/usePlaceableFileRows.js.map +1 -1
- package/dist/core/components/viewers/bim/src/Splats/splatPlacementStore.d.ts +3 -3
- package/dist/core/components/viewers/bim/src/Splats/splatPlacementStore.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/src/Splats/splatPlacementStore.js +2 -18
- package/dist/core/components/viewers/bim/src/Splats/splatPlacementStore.js.map +1 -1
- package/dist/core/components/viewers/bim/src/lib/applyModelPlacement.d.ts +1 -1
- package/dist/core/components/viewers/bim/src/lib/applyModelPlacement.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/src/lib/applyModelPlacement.js +2 -2
- package/dist/core/components/viewers/bim/src/lib/applyModelPlacement.js.map +1 -1
- package/dist/core/components/viewers/bim/src/lib/useViewerLocation.d.ts +1 -1
- package/dist/core/components/viewers/bim/src/lib/useViewerLocation.js.map +1 -1
- package/dist/core/components/viewers/map/datasets/src/minioDatasets.d.ts.map +1 -1
- package/dist/core/components/viewers/map/datasets/src/minioDatasets.js +16 -8
- package/dist/core/components/viewers/map/datasets/src/minioDatasets.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/FileLayer/FileModelLayer/FileModelLayer.js +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/FileLayer/FileModelLayer/FileModelLayer.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/FileLayer/utils/CustomModelLayer.js +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/FileLayer/utils/CustomModelLayer.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/OpenDataLayer/src/index.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/OpenDataLayer/src/index.js +12 -23
- package/dist/core/components/viewers/map/src/MapLayers/src/OpenDataLayer/src/index.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/OpenDataLayer/src/useDatasetFeatures.d.ts +23 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/OpenDataLayer/src/useDatasetFeatures.d.ts.map +1 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/OpenDataLayer/src/useDatasetFeatures.js +67 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/OpenDataLayer/src/useDatasetFeatures.js.map +1 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/OpenDataLayer/src/useViewportDatasetToast.d.ts +4 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/OpenDataLayer/src/useViewportDatasetToast.d.ts.map +1 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/OpenDataLayer/src/useViewportDatasetToast.js +24 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/OpenDataLayer/src/useViewportDatasetToast.js.map +1 -0
- package/dist/core/components/viewers/map/src/Placement/MapPlacementHost.js +1 -1
- package/dist/core/components/viewers/map/src/Placement/MapPlacementHost.js.map +1 -1
- package/dist/core/components/viewers/map/src/Placement/mapPlacementGeo.d.ts +1 -1
- package/dist/core/components/viewers/map/src/Placement/mapPlacementGeo.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/Placement/mapPlacementGeo.js +2 -2
- package/dist/core/components/viewers/map/src/Placement/mapPlacementGeo.js.map +1 -1
- package/dist/core/components/viewers/map/src/Placement/mapPlacementTarget.js +1 -1
- package/dist/core/components/viewers/map/src/Placement/mapPlacementTarget.js.map +1 -1
- package/dist/core/components/viewers/map/src/Placement/useMapPlacementTarget.js +1 -1
- package/dist/core/components/viewers/map/src/Placement/useMapPlacementTarget.js.map +1 -1
- package/dist/core/components/viewers/shared/intake/useFileIntake.d.ts.map +1 -1
- package/dist/core/components/viewers/shared/intake/useFileIntake.js +3 -26
- package/dist/core/components/viewers/shared/intake/useFileIntake.js.map +1 -1
- package/dist/core/components/viewers/shared/placement/fileTransform.d.ts +9 -0
- package/dist/core/components/viewers/shared/placement/fileTransform.d.ts.map +1 -0
- package/dist/core/components/viewers/shared/placement/fileTransform.js +32 -0
- package/dist/core/components/viewers/shared/placement/fileTransform.js.map +1 -0
- package/dist/core/components/viewers/shared/placement/objectTarget.js +2 -2
- package/dist/core/components/viewers/shared/placement/objectTarget.js.map +1 -1
- package/dist/core/components/viewers/shared/pointcloud/pointCloudPlacementStore.d.ts +2 -3
- package/dist/core/components/viewers/shared/pointcloud/pointCloudPlacementStore.d.ts.map +1 -1
- package/dist/core/components/viewers/shared/pointcloud/pointCloudPlacementStore.js +4 -14
- package/dist/core/components/viewers/shared/pointcloud/pointCloudPlacementStore.js.map +1 -1
- package/dist/core/i18n/messages/en.json +4 -0
- package/dist/core/i18n/messages/es.json +4 -0
- package/dist/core/i18n/messages/fr.json +4 -0
- package/dist/core/types/datasetTypes.d.ts +5 -0
- package/dist/core/types/datasetTypes.d.ts.map +1 -1
- package/dist/core/types/dbTypes.d.ts +40 -0
- package/dist/core/types/dbTypes.d.ts.map +1 -1
- package/dist/core/types/dbTypes.js +18 -0
- package/dist/core/types/dbTypes.js.map +1 -1
- package/dist/core/types/index.d.ts +2 -2
- package/dist/core/types/index.d.ts.map +1 -1
- package/dist/core/types/index.js +7 -1
- package/dist/core/types/index.js.map +1 -1
- package/dist/core/utils/geo/reprojectGeometry.d.ts +14 -0
- package/dist/core/utils/geo/reprojectGeometry.d.ts.map +1 -0
- package/dist/core/utils/geo/reprojectGeometry.js +58 -0
- package/dist/core/utils/geo/reprojectGeometry.js.map +1 -0
- package/dist/core/utils/geo/wktToGeometry.d.ts +5 -0
- package/dist/core/utils/geo/wktToGeometry.d.ts.map +1 -0
- package/dist/core/utils/geo/wktToGeometry.js +34 -0
- package/dist/core/utils/geo/wktToGeometry.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
2
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
3
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
4
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
@@ -16,25 +14,11 @@ var __spreadValues = (a, b) => {
|
|
|
16
14
|
}
|
|
17
15
|
return a;
|
|
18
16
|
};
|
|
19
|
-
|
|
20
|
-
import { parsePlacement } from "../../../shared/pointcloud/pointCloudPlacement";
|
|
17
|
+
import { readFileTransform } from "../../../shared/placement/fileTransform";
|
|
21
18
|
import { DEFAULT_SPLAT_PLACEMENT } from "../../../shared/splat/splatUpAxis";
|
|
22
19
|
import { placementPatch, samePlacement } from "../PointClouds/pointCloudPlacementStore";
|
|
23
20
|
function readSplatPlacement(file) {
|
|
24
|
-
|
|
25
|
-
const stored = typeof file.pointCloudTransform === "string" ? safeParse(file.pointCloudTransform) : file.pointCloudTransform;
|
|
26
|
-
if (stored === null || typeof stored !== "object") return __spreadValues({}, DEFAULT_SPLAT_PLACEMENT);
|
|
27
|
-
const raw = stored;
|
|
28
|
-
return __spreadProps(__spreadValues({}, parsePlacement(stored)), {
|
|
29
|
-
sourceUp: raw.sourceUp === "z" ? "z" : DEFAULT_SPLAT_PLACEMENT.sourceUp
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
function safeParse(raw) {
|
|
33
|
-
try {
|
|
34
|
-
return JSON.parse(raw);
|
|
35
|
-
} catch (e) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
21
|
+
return file ? readFileTransform(file, DEFAULT_SPLAT_PLACEMENT) : __spreadValues({}, DEFAULT_SPLAT_PLACEMENT);
|
|
38
22
|
}
|
|
39
23
|
export {
|
|
40
24
|
readSplatPlacement,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../src/core/components/viewers/bim/src/Splats/splatPlacementStore.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../../../src/core/components/viewers/bim/src/Splats/splatPlacementStore.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport { readFileTransform } from '../../../shared/placement/fileTransform'\nimport { DEFAULT_SPLAT_PLACEMENT } from '../../../shared/splat/splatUpAxis'\nimport { placementPatch, samePlacement } from '../PointClouds/pointCloudPlacementStore'\n\nimport type { FileTransformColumns } from '../../../shared/placement/fileTransform'\nimport type { SplatPlacement } from '../../../shared/splat/splatUpAxis'\n\nexport { placementPatch as splatPlacementPatch, samePlacement as sameSplatPlacement }\n\n/** Splats share the point-cloud transform columns, defaulting to a splat's own up axis. */\nexport function readSplatPlacement(file: FileTransformColumns | undefined): SplatPlacement {\n return file ? readFileTransform(file, DEFAULT_SPLAT_PLACEMENT) : { ...DEFAULT_SPLAT_PLACEMENT }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAGA,SAAS,yBAAyB;AAClC,SAAS,+BAA+B;AACxC,SAAS,gBAAgB,qBAAqB;AAQvC,SAAS,mBAAmB,MAAwD;AACzF,SAAO,OAAO,kBAAkB,MAAM,uBAAuB,IAAI,mBAAK;AACxE;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DbFile } from '../../../../../types/dbTypes';
|
|
2
2
|
import type * as THREE from 'three';
|
|
3
3
|
/** Restores a model's stored placement. `LoadModels.setupModel` resets every load to the origin. */
|
|
4
|
-
export declare function applyModelPlacement(object: THREE.Object3D, file: Pick<DbFile, '
|
|
4
|
+
export declare function applyModelPlacement(object: THREE.Object3D, file: Pick<DbFile, 'fileTransformX' | 'fileTransformY' | 'fileTransformZ' | 'fileRotationY'>): void;
|
|
5
5
|
//# sourceMappingURL=applyModelPlacement.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyModelPlacement.d.ts","sourceRoot":"","sources":["../../../../../../../src/core/components/viewers/bim/src/lib/applyModelPlacement.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AAC1D,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAA;AAEnC,oGAAoG;AACpG,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"applyModelPlacement.d.ts","sourceRoot":"","sources":["../../../../../../../src/core/components/viewers/bim/src/lib/applyModelPlacement.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AAC1D,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAA;AAEnC,oGAAoG;AACpG,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,gBAAgB,GAAG,gBAAgB,GAAG,gBAAgB,GAAG,eAAe,CAAC,QAIvJ"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
function applyModelPlacement(object, file) {
|
|
2
2
|
var _a, _b, _c;
|
|
3
|
-
object.position.set((_a = file.
|
|
4
|
-
if (file.
|
|
3
|
+
object.position.set((_a = file.fileTransformX) != null ? _a : 0, (_b = file.fileTransformY) != null ? _b : 0, (_c = file.fileTransformZ) != null ? _c : 0);
|
|
4
|
+
if (file.fileRotationY != null) object.rotation.y = file.fileRotationY;
|
|
5
5
|
object.updateMatrixWorld(true);
|
|
6
6
|
}
|
|
7
7
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../src/core/components/viewers/bim/src/lib/applyModelPlacement.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport type { DbFile } from '../../../../../types/dbTypes'\nimport type * as THREE from 'three'\n\n/** Restores a model's stored placement. `LoadModels.setupModel` resets every load to the origin. */\nexport function applyModelPlacement(object: THREE.Object3D, file: Pick<DbFile, '
|
|
1
|
+
{"version":3,"sources":["../../../../../../../src/core/components/viewers/bim/src/lib/applyModelPlacement.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport type { DbFile } from '../../../../../types/dbTypes'\nimport type * as THREE from 'three'\n\n/** Restores a model's stored placement. `LoadModels.setupModel` resets every load to the origin. */\nexport function applyModelPlacement(object: THREE.Object3D, file: Pick<DbFile, 'fileTransformX' | 'fileTransformY' | 'fileTransformZ' | 'fileRotationY'>) {\n object.position.set(file.fileTransformX ?? 0, file.fileTransformY ?? 0, file.fileTransformZ ?? 0)\n if (file.fileRotationY != null) object.rotation.y = file.fileRotationY\n object.updateMatrixWorld(true)\n}\n"],"mappings":"AAOO,SAAS,oBAAoB,QAAwB,MAA8F;AAP1J;AAQE,SAAO,SAAS,KAAI,UAAK,mBAAL,YAAuB,IAAG,UAAK,mBAAL,YAAuB,IAAG,UAAK,mBAAL,YAAuB,CAAC;AAChG,MAAI,KAAK,iBAAiB,KAAM,QAAO,SAAS,IAAI,KAAK;AACzD,SAAO,kBAAkB,IAAI;AAC/B;","names":[]}
|
|
@@ -5,7 +5,7 @@ export interface ViewerLocation {
|
|
|
5
5
|
label: string;
|
|
6
6
|
/**
|
|
7
7
|
* Degrees the map places the site at, from `building.rotation`. This is the only link between
|
|
8
|
-
* the model and geographic north; `
|
|
8
|
+
* the model and geographic north; `fileRotationY` is project north and never contributes.
|
|
9
9
|
*/
|
|
10
10
|
northOffset: number;
|
|
11
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../src/core/components/viewers/bim/src/lib/useViewerLocation.ts"],"sourcesContent":["'use client'\n\n// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport { useSearchParams } from 'next/navigation'\nimport * as React from 'react'\n\nimport { BuildingsContext } from '../../../../../store'\n\nexport interface ViewerLocation {\n latitude: number\n longitude: number\n /** Human-readable source of the coordinates, for showing which place a sun study is using. */\n label: string\n /**\n * Degrees the map places the site at, from `building.rotation`. This is the only link between\n * the model and geographic north; `
|
|
1
|
+
{"version":3,"sources":["../../../../../../../src/core/components/viewers/bim/src/lib/useViewerLocation.ts"],"sourcesContent":["'use client'\n\n// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport { useSearchParams } from 'next/navigation'\nimport * as React from 'react'\n\nimport { BuildingsContext } from '../../../../../store'\n\nexport interface ViewerLocation {\n latitude: number\n longitude: number\n /** Human-readable source of the coordinates, for showing which place a sun study is using. */\n label: string\n /**\n * Degrees the map places the site at, from `building.rotation`. This is the only link between\n * the model and geographic north; `fileRotationY` is project north and never contributes.\n */\n northOffset: number\n}\n\n/** Ottawa, so a sun study still has somewhere to stand when nothing has been selected yet. */\nexport const FALLBACK_LOCATION: ViewerLocation = {\n latitude: 45.4215,\n longitude: -75.6972,\n label: 'Ottawa, ON',\n northOffset: 0,\n}\n\nfunction describe(name: string | undefined, latitude: number, longitude: number) {\n return name ?? `${latitude.toFixed(4)}, ${longitude.toFixed(4)}`\n}\n\n/**\n * Where the viewer currently stands on the globe: the selected building first, then the URL\n * params the map writes, then a fallback. Sun studies read this.\n */\nexport function useViewerLocation(): ViewerLocation {\n const { state } = React.useContext(BuildingsContext)\n const building = state.buildings.building\n const searchParams = useSearchParams()\n\n return React.useMemo(() => {\n const { buildingLatitude, buildingLongitude } = building ?? {}\n // `rotation` is the map placement angle, the same one `extractPositionAndRotation` reads.\n const northOffset = building?.rotation ?? 0\n if (typeof buildingLatitude === 'number' && typeof buildingLongitude === 'number') {\n return {\n latitude: buildingLatitude,\n longitude: buildingLongitude,\n label: describe(building?.buildingName ?? building?.buildingAddress, buildingLatitude, buildingLongitude),\n northOffset,\n }\n }\n\n const lat = Number(searchParams?.get('lat'))\n const lng = Number(searchParams?.get('lng'))\n if (Number.isFinite(lat) && Number.isFinite(lng) && (lat !== 0 || lng !== 0)) {\n const municipality = searchParams?.get('municipality') ?? undefined\n return { latitude: lat, longitude: lng, label: describe(municipality, lat, lng), northOffset }\n }\n\n return FALLBACK_LOCATION\n }, [building, searchParams])\n}\n"],"mappings":";AAKA,SAAS,uBAAuB;AAChC,YAAY,WAAW;AAEvB,SAAS,wBAAwB;AAe1B,MAAM,oBAAoC;AAAA,EAC7C,UAAU;AAAA,EACV,WAAW;AAAA,EACX,OAAO;AAAA,EACP,aAAa;AACjB;AAEA,SAAS,SAAS,MAA0B,UAAkB,WAAmB;AAC7E,SAAO,sBAAQ,GAAG,SAAS,QAAQ,CAAC,CAAC,KAAK,UAAU,QAAQ,CAAC,CAAC;AAClE;AAMO,SAAS,oBAAoC;AAChD,QAAM,EAAE,MAAM,IAAI,MAAM,WAAW,gBAAgB;AACnD,QAAM,WAAW,MAAM,UAAU;AACjC,QAAM,eAAe,gBAAgB;AAErC,SAAO,MAAM,QAAQ,MAAM;AA3C/B;AA4CQ,UAAM,EAAE,kBAAkB,kBAAkB,IAAI,8BAAY,CAAC;AAE7D,UAAM,eAAc,0CAAU,aAAV,YAAsB;AAC1C,QAAI,OAAO,qBAAqB,YAAY,OAAO,sBAAsB,UAAU;AAC/E,aAAO;AAAA,QACH,UAAU;AAAA,QACV,WAAW;AAAA,QACX,OAAO,UAAS,0CAAU,iBAAV,YAA0B,qCAAU,iBAAiB,kBAAkB,iBAAiB;AAAA,QACxG;AAAA,MACJ;AAAA,IACJ;AAEA,UAAM,MAAM,OAAO,6CAAc,IAAI,MAAM;AAC3C,UAAM,MAAM,OAAO,6CAAc,IAAI,MAAM;AAC3C,QAAI,OAAO,SAAS,GAAG,KAAK,OAAO,SAAS,GAAG,MAAM,QAAQ,KAAK,QAAQ,IAAI;AAC1E,YAAM,gBAAe,kDAAc,IAAI,oBAAlB,YAAqC;AAC1D,aAAO,EAAE,UAAU,KAAK,WAAW,KAAK,OAAO,SAAS,cAAc,KAAK,GAAG,GAAG,YAAY;AAAA,IACjG;AAEA,WAAO;AAAA,EACX,GAAG,CAAC,UAAU,YAAY,CAAC;AAC/B;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"minioDatasets.d.ts","sourceRoot":"","sources":["../../../../../../../src/core/components/viewers/map/datasets/src/minioDatasets.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAA;
|
|
1
|
+
{"version":3,"file":"minioDatasets.d.ts","sourceRoot":"","sources":["../../../../../../../src/core/components/viewers/map/datasets/src/minioDatasets.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAA;AAkDhE,wBAAsB,gCAAgC,CACpD,cAAc,EAAE,MAAM,EACtB,uBAAuB,GAAE,WAAW,CAAC,MAAM,CAAa,GACvD,OAAO,CAAC,OAAO,EAAE,CAAC,CA2FpB"}
|
|
@@ -10,8 +10,11 @@ function parseDescription(value) {
|
|
|
10
10
|
return null;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
+
function withBbox(url, bbox) {
|
|
14
|
+
return `${url}${url.includes("?") ? "&" : "?"}bbox=${bbox.map((value) => value.toFixed(6)).join(",")}`;
|
|
15
|
+
}
|
|
13
16
|
async function fetchOrganizationalMinioDatasets(organizationId, publishedTilesInCatalog = /* @__PURE__ */ new Set()) {
|
|
14
|
-
var _a, _b;
|
|
17
|
+
var _a, _b, _c, _d;
|
|
15
18
|
let rows = [];
|
|
16
19
|
try {
|
|
17
20
|
const res = await fetch("/api/files");
|
|
@@ -35,14 +38,18 @@ async function fetchOrganizationalMinioDatasets(organizationId, publishedTilesIn
|
|
|
35
38
|
if (!sourceUrl) continue;
|
|
36
39
|
const name = ((_a = row.name) == null ? void 0 : _a.replace(/\.geojson$/i, "")) || `Dataset ${row.id}`;
|
|
37
40
|
const id = `org-minio-${row.id}`;
|
|
41
|
+
const viewport = typeof (meta == null ? void 0 : meta.minZoom) === "number" ? { minZoom: meta.minZoom } : void 0;
|
|
38
42
|
let cached = null;
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
const response = await fetch(sourceUrl);
|
|
43
|
+
const fetchGeoJson = async (url) => {
|
|
44
|
+
const response = await fetch(url);
|
|
42
45
|
if (!response.ok) {
|
|
43
|
-
throw new Error(`Failed to fetch GeoJSON from ${
|
|
46
|
+
throw new Error(`Failed to fetch GeoJSON from ${url}: ${response.status}`);
|
|
44
47
|
}
|
|
45
|
-
|
|
48
|
+
return await response.json();
|
|
49
|
+
};
|
|
50
|
+
const getFeatures = async (options) => {
|
|
51
|
+
if (viewport && (options == null ? void 0 : options.bbox)) return fetchGeoJson(withBbox(sourceUrl, options.bbox));
|
|
52
|
+
cached != null ? cached : cached = await fetchGeoJson(sourceUrl);
|
|
46
53
|
return cached;
|
|
47
54
|
};
|
|
48
55
|
const getFields = async () => [];
|
|
@@ -59,14 +66,15 @@ async function fetchOrganizationalMinioDatasets(organizationId, publishedTilesIn
|
|
|
59
66
|
description: `Uploaded ${(_b = row.uploadedAt) != null ? _b : ""}`.trim(),
|
|
60
67
|
dateReleased: typeof row.uploadedAt === "string" ? row.uploadedAt : "",
|
|
61
68
|
dateUpdated: typeof row.uploadedAt === "string" ? row.uploadedAt : "",
|
|
62
|
-
countrySubdivision: "",
|
|
63
|
-
municipality: "",
|
|
69
|
+
countrySubdivision: (_c = row.countrySubdivision) != null ? _c : "",
|
|
70
|
+
municipality: (_d = row.municipality) != null ? _d : "",
|
|
64
71
|
sourceUrl,
|
|
65
72
|
url: sourceUrl,
|
|
66
73
|
clickable: true,
|
|
67
74
|
properties: {},
|
|
68
75
|
getFeatures,
|
|
69
76
|
getFields,
|
|
77
|
+
viewport,
|
|
70
78
|
dataManagementSystem: "other",
|
|
71
79
|
datasetType: "GeoJSON",
|
|
72
80
|
group: DatasetGroup.Organizational,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../src/core/components/viewers/map/datasets/src/minioDatasets.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport { DatasetGroup } from '../../../../../types/dbTypes'\nimport { layerColorByName } from '../../utils/stringToColour'\n\nimport type { Dataset } from '../../../../../types/datasetTypes'\nimport type { AllGeoJSON } from '@turf/turf'\n\n/**\n * Hydrates uploaded GeoJSON datasets persisted via \"Add Dataset\". Looks up File\n * rows tagged `organizational-dataset` and builds Dataset entries whose\n * `getFeatures` lazy-loads the GeoJSON on first render.\n */\n\ninterface OrgDatasetDescription {\n bucket?: string\n geometryType?: 'points' | 'lines' | 'polygons'\n layerStyles?: Record<string, Record<string, string | number>>\n tiledTable?: string\n tiledAt?: string\n featuresIngested?: number\n featuresSkipped?: number\n}\n\ninterface RawFileRow {\n id: number\n type?: string | null\n tag?: string | null\n name?: string | null\n /** Presigned, expiring download URL minted per request by /api/files. */\n url?: string | null\n description?: string | null\n uploadedAt?: string | Date | null\n}\n\nconst TAG = 'organizational-dataset'\n\nfunction parseDescription(value: string | null | undefined): OrgDatasetDescription | null {\n if (!value) return null\n try {\n const parsed = JSON.parse(value)\n return typeof parsed === 'object' && parsed !== null ? parsed as OrgDatasetDescription : null\n }\n catch {\n return null\n }\n}\n\nexport async function fetchOrganizationalMinioDatasets(\n organizationId: number,\n publishedTilesInCatalog: ReadonlySet<string> = new Set(),\n): Promise<Dataset[]> {\n let rows: RawFileRow[] = []\n try {\n const res = await fetch('/api/files')\n if (!res.ok) {\n console.warn(`fetchOrganizationalMinioDatasets: /api/files returned ${res.status}`)\n return []\n }\n const body = await res.json()\n rows = Array.isArray(body?.files) ? body.files : []\n }\n catch (err) {\n console.warn('fetchOrganizationalMinioDatasets: /api/files request failed', err)\n return []\n }\n\n const datasets: Dataset[] = []\n for (const row of rows) {\n if (row.type !== 'map-file') continue\n if (row.tag !== TAG) continue\n\n const meta = parseDescription(row.description)\n // Suppress the MinIO entry only once Martin actually serves the published\n // table — otherwise the file appears to vanish during the publish→restart\n // gap. Un-publish drops the table immediately, so the MinIO row reappears\n // on next reload with no extra plumbing.\n if (meta?.tiledTable && publishedTilesInCatalog.has(meta.tiledTable)) continue\n\n // Only ever the presigned URL the server minted for this session. Rebuilding\n // the object path here would require the bucket to allow anonymous reads.\n const sourceUrl = row.url\n if (!sourceUrl) continue\n\n const name = row.name?.replace(/\\.geojson$/i, '') || `Dataset ${row.id}`\n const id = `org-minio-${row.id}`\n let cached: AllGeoJSON | null = null\n\n const
|
|
1
|
+
{"version":3,"sources":["../../../../../../../src/core/components/viewers/map/datasets/src/minioDatasets.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport { DatasetGroup } from '../../../../../types/dbTypes'\nimport { layerColorByName } from '../../utils/stringToColour'\n\nimport type { Dataset } from '../../../../../types/datasetTypes'\nimport type { AllGeoJSON } from '@turf/turf'\n\n/**\n * Hydrates uploaded GeoJSON datasets persisted via \"Add Dataset\". Looks up File\n * rows tagged `organizational-dataset` and builds Dataset entries whose\n * `getFeatures` lazy-loads the GeoJSON on first render.\n */\n\ninterface OrgDatasetDescription {\n bucket?: string\n geometryType?: 'points' | 'lines' | 'polygons'\n layerStyles?: Record<string, Record<string, string | number>>\n tiledTable?: string\n tiledAt?: string\n featuresIngested?: number\n featuresSkipped?: number\n minZoom?: number\n}\n\ninterface RawFileRow {\n id: number\n type?: string | null\n tag?: string | null\n name?: string | null\n /** Presigned, expiring download URL minted per request by /api/files. */\n url?: string | null\n description?: string | null\n uploadedAt?: string | Date | null\n countrySubdivision?: string | null\n municipality?: string | null\n}\n\nconst TAG = 'organizational-dataset'\n\nfunction parseDescription(value: string | null | undefined): OrgDatasetDescription | null {\n if (!value) return null\n try {\n const parsed = JSON.parse(value)\n return typeof parsed === 'object' && parsed !== null ? parsed as OrgDatasetDescription : null\n }\n catch {\n return null\n }\n}\n\nfunction withBbox(url: string, bbox: [number, number, number, number]): string {\n return `${url}${url.includes('?') ? '&' : '?'}bbox=${bbox.map(value => value.toFixed(6)).join(',')}`\n}\n\nexport async function fetchOrganizationalMinioDatasets(\n organizationId: number,\n publishedTilesInCatalog: ReadonlySet<string> = new Set(),\n): Promise<Dataset[]> {\n let rows: RawFileRow[] = []\n try {\n const res = await fetch('/api/files')\n if (!res.ok) {\n console.warn(`fetchOrganizationalMinioDatasets: /api/files returned ${res.status}`)\n return []\n }\n const body = await res.json()\n rows = Array.isArray(body?.files) ? body.files : []\n }\n catch (err) {\n console.warn('fetchOrganizationalMinioDatasets: /api/files request failed', err)\n return []\n }\n\n const datasets: Dataset[] = []\n for (const row of rows) {\n if (row.type !== 'map-file') continue\n if (row.tag !== TAG) continue\n\n const meta = parseDescription(row.description)\n // Suppress the MinIO entry only once Martin actually serves the published\n // table — otherwise the file appears to vanish during the publish→restart\n // gap. Un-publish drops the table immediately, so the MinIO row reappears\n // on next reload with no extra plumbing.\n if (meta?.tiledTable && publishedTilesInCatalog.has(meta.tiledTable)) continue\n\n // Only ever the presigned URL the server minted for this session. Rebuilding\n // the object path here would require the bucket to allow anonymous reads.\n const sourceUrl = row.url\n if (!sourceUrl) continue\n\n const name = row.name?.replace(/\\.geojson$/i, '') || `Dataset ${row.id}`\n const id = `org-minio-${row.id}`\n const viewport = typeof meta?.minZoom === 'number' ? { minZoom: meta.minZoom } : undefined\n let cached: AllGeoJSON | null = null\n\n const fetchGeoJson = async (url: string): Promise<AllGeoJSON> => {\n const response = await fetch(url)\n if (!response.ok) {\n throw new Error(`Failed to fetch GeoJSON from ${url}: ${response.status}`)\n }\n return await response.json() as AllGeoJSON\n }\n\n const getFeatures: Dataset['getFeatures'] = async (options) => {\n if (viewport && options?.bbox) return fetchGeoJson(withBbox(sourceUrl, options.bbox))\n cached ??= await fetchGeoJson(sourceUrl)\n return cached\n }\n\n const getFields = async () => []\n\n datasets.push({\n id,\n // Stamped so the map's org-visibility filter can tell whose dataset this\n // is. Without it every rebuilt dataset is dropped for non-admin viewers.\n organization: organizationId,\n name,\n type: 'Organizational',\n publisher: 'Organizational',\n license: 'Unknown',\n contact: 'Unknown',\n description: `Uploaded ${row.uploadedAt ?? ''}`.trim(),\n dateReleased: typeof row.uploadedAt === 'string' ? row.uploadedAt : '',\n dateUpdated: typeof row.uploadedAt === 'string' ? row.uploadedAt : '',\n countrySubdivision: row.countrySubdivision ?? '',\n municipality: row.municipality ?? '',\n sourceUrl,\n url: sourceUrl,\n clickable: true,\n properties: {},\n getFeatures,\n getFields,\n viewport,\n dataManagementSystem: 'other',\n datasetType: 'GeoJSON',\n group: DatasetGroup.Organizational,\n layerColor: layerColorByName(id),\n layerType: meta?.geometryType === 'lines'\n ? 'line'\n : meta?.geometryType === 'points'\n ? 'circle'\n : meta?.geometryType === 'polygons'\n ? 'fill'\n : undefined,\n })\n }\n\n return datasets\n}\n"],"mappings":"AAGA,SAAS,oBAAoB;AAC7B,SAAS,wBAAwB;AAmCjC,MAAM,MAAM;AAEZ,SAAS,iBAAiB,OAAgE;AACxF,MAAI,CAAC,MAAO,QAAO;AACnB,MAAI;AACF,UAAM,SAAS,KAAK,MAAM,KAAK;AAC/B,WAAO,OAAO,WAAW,YAAY,WAA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;AAChB,cAAM,IAAI,MAAM,gCAAgC,GAAG,KAAK,SAAS,MAAM,EAAE;AAAA,MAC3E;AACA,aAAO,MAAM,SAAS,KAAK;AAAA,IAC7B;AAEA,UAAM,cAAsC,OAAO,YAAY;AAC7D,UAAI,aAAY,mCAAS,MAAM,QAAO,aAAa,SAAS,WAAW,QAAQ,IAAI,CAAC;AACpF,yCAAW,MAAM,aAAa,SAAS;AACvC,aAAO;AAAA,IACT;AAEA,UAAM,YAAY,YAAY,CAAC;AAE/B,aAAS,KAAK;AAAA,MACZ;AAAA;AAAA;AAAA,MAGA,cAAc;AAAA,MACd;AAAA,MACA,MAAM;AAAA,MACN,WAAW;AAAA,MACX,SAAS;AAAA,MACT,SAAS;AAAA,MACT,aAAa,aAAY,SAAI,eAAJ,YAAkB,EAAE,GAAG,KAAK;AAAA,MACrD,cAAc,OAAO,IAAI,eAAe,WAAW,IAAI,aAAa;AAAA,MACpE,aAAa,OAAO,IAAI,eAAe,WAAW,IAAI,aAAa;AAAA,MACnE,qBAAoB,SAAI,uBAAJ,YAA0B;AAAA,MAC9C,eAAc,SAAI,iBAAJ,YAAoB;AAAA,MAClC;AAAA,MACA,KAAK;AAAA,MACL,WAAW;AAAA,MACX,YAAY,CAAC;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,MACA,sBAAsB;AAAA,MACtB,aAAa;AAAA,MACb,OAAO,aAAa;AAAA,MACpB,YAAY,iBAAiB,EAAE;AAAA,MAC/B,YAAW,6BAAM,kBAAiB,UAC9B,UACA,6BAAM,kBAAiB,WACrB,YACA,6BAAM,kBAAiB,aACrB,SACA;AAAA,IACV,CAAC;AAAA,EACH;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -53,7 +53,7 @@ const FileModelLayer = ({
|
|
|
53
53
|
const modelsWithChangedCoords = loadedModels.filter((model) => {
|
|
54
54
|
if (!currentFileIds.has(model.file.id)) return false;
|
|
55
55
|
const updated = currentModelFiles.find((f) => f.id === model.file.id);
|
|
56
|
-
return updated && (updated.lat !== model.file.lat || updated.lng !== model.file.lng || updated.rotation !== model.file.rotation || updated.elevation !== model.file.elevation || updated.
|
|
56
|
+
return updated && (updated.lat !== model.file.lat || updated.lng !== model.file.lng || updated.rotation !== model.file.rotation || updated.elevation !== model.file.elevation || updated.fileScale !== model.file.fileScale);
|
|
57
57
|
});
|
|
58
58
|
for (const model of [...modelsToRemove, ...modelsWithChangedCoords]) {
|
|
59
59
|
model.cleanUpFunction();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/FileLayer/FileModelLayer/FileModelLayer.tsx"],"sourcesContent":["\"use client\"\n\n// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport * as React from 'react'\nimport * as THREE from 'three'\n\nimport { MapContext, FilesContext } from '../../../../../../../../store'\nimport { ndcOfEvent } from '../../../../../utils/layerRaycast'\nimport { CustomModelLayer } from '../utils/CustomModelLayer'\n\nimport type { DbFile } from '../../../../../../../../types/dbTypes'\nimport type { ModelAnimationControls } from '../utils/CustomModelLayer'\n\ntype LoadedModelFiles = {\n file: DbFile\n cleanUpFunction: () => void\n hitTest: (ndcX: number, ndcY: number) => boolean\n animation: ModelAnimationControls\n}\n\ninterface FileModelLayerProps {\n tempPositionsRef?: React.MutableRefObject<Record<string, { lat: number; lng: number }>>\n editingFileIdRef?: React.MutableRefObject<string | null>\n tempRotationsRef?: React.MutableRefObject<Record<string, number>>\n tempElevationsRef?: React.MutableRefObject<Record<string, number>>\n tempScalesRef?: React.MutableRefObject<Record<string, number>>\n /** Called when the user right-clicks on a rendered 3D mesh, with the model's playback if it has clips. */\n onContextMenu?: (file: DbFile, clientX: number, clientY: number, animation: ModelAnimationControls) => void\n}\n\nexport const FileModelLayer = ({\n tempPositionsRef,\n editingFileIdRef,\n tempRotationsRef,\n tempElevationsRef,\n tempScalesRef,\n onContextMenu,\n}: FileModelLayerProps) => {\n const { state: mapState } = React.useContext(MapContext)\n const { map } = mapState.map\n const { state: fileState } = React.useContext(FilesContext)\n const { files: globalFileState, mapFileIds } = fileState.files\n\n const is3DModelFile = (extension?: string | null): boolean => {\n if (!extension) return false\n const ext = extension.toLowerCase()\n return ['glb', 'gltf', 'fbx', 'obj', 'collada'].includes(ext)\n }\n\n const mapFiles = React.useMemo(\n () => globalFileState.filter(file => is3DModelFile(file.extension) && mapFileIds.includes(file.id) && !!file.url),\n [globalFileState, mapFileIds]\n )\n\n const [loadedModels, setLoadedModels] = React.useState<LoadedModelFiles[]>([])\n const rendererRef = React.useRef<THREE.WebGLRenderer | null>(null)\n\n // Stable refs so the canvas listener never needs to be re-registered\n const loadedModelsRef = React.useRef<LoadedModelFiles[]>([])\n const onContextMenuRef = React.useRef(onContextMenu)\n loadedModelsRef.current = loadedModels\n onContextMenuRef.current = onContextMenu\n\n // ── Layer management ───────────────────────────────────────────────────────\n React.useEffect(() => {\n if (!map) return\n if (!rendererRef.current) {\n rendererRef.current = new THREE.WebGLRenderer({\n canvas: map.getCanvas(),\n context: map.getCanvas().getContext('webgl') as WebGLRenderingContext,\n antialias: true,\n })\n }\n const currentModelFiles = mapFiles.filter(file => {\n const ext = file.extension?.toLowerCase()\n return ext === 'glb' || ext === 'gltf' || ext === 'fbx' || ext === 'obj' || ext === 'collada'\n })\n const loadedIds = new Set(loadedModels.map(model => model.file.id))\n const currentFileIds = new Set(currentModelFiles.map(f => f.id))\n\n const modelsToRemove = loadedModels.filter(model => !currentFileIds.has(model.file.id))\n\n const modelsWithChangedCoords = loadedModels.filter(model => {\n if (!currentFileIds.has(model.file.id)) return false\n const updated = currentModelFiles.find(f => f.id === model.file.id)\n return updated && (\n updated.lat !== model.file.lat ||\n updated.lng !== model.file.lng ||\n updated.rotation !== model.file.rotation ||\n updated.elevation !== model.file.elevation ||\n updated.
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/FileLayer/FileModelLayer/FileModelLayer.tsx"],"sourcesContent":["\"use client\"\n\n// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport * as React from 'react'\nimport * as THREE from 'three'\n\nimport { MapContext, FilesContext } from '../../../../../../../../store'\nimport { ndcOfEvent } from '../../../../../utils/layerRaycast'\nimport { CustomModelLayer } from '../utils/CustomModelLayer'\n\nimport type { DbFile } from '../../../../../../../../types/dbTypes'\nimport type { ModelAnimationControls } from '../utils/CustomModelLayer'\n\ntype LoadedModelFiles = {\n file: DbFile\n cleanUpFunction: () => void\n hitTest: (ndcX: number, ndcY: number) => boolean\n animation: ModelAnimationControls\n}\n\ninterface FileModelLayerProps {\n tempPositionsRef?: React.MutableRefObject<Record<string, { lat: number; lng: number }>>\n editingFileIdRef?: React.MutableRefObject<string | null>\n tempRotationsRef?: React.MutableRefObject<Record<string, number>>\n tempElevationsRef?: React.MutableRefObject<Record<string, number>>\n tempScalesRef?: React.MutableRefObject<Record<string, number>>\n /** Called when the user right-clicks on a rendered 3D mesh, with the model's playback if it has clips. */\n onContextMenu?: (file: DbFile, clientX: number, clientY: number, animation: ModelAnimationControls) => void\n}\n\nexport const FileModelLayer = ({\n tempPositionsRef,\n editingFileIdRef,\n tempRotationsRef,\n tempElevationsRef,\n tempScalesRef,\n onContextMenu,\n}: FileModelLayerProps) => {\n const { state: mapState } = React.useContext(MapContext)\n const { map } = mapState.map\n const { state: fileState } = React.useContext(FilesContext)\n const { files: globalFileState, mapFileIds } = fileState.files\n\n const is3DModelFile = (extension?: string | null): boolean => {\n if (!extension) return false\n const ext = extension.toLowerCase()\n return ['glb', 'gltf', 'fbx', 'obj', 'collada'].includes(ext)\n }\n\n const mapFiles = React.useMemo(\n () => globalFileState.filter(file => is3DModelFile(file.extension) && mapFileIds.includes(file.id) && !!file.url),\n [globalFileState, mapFileIds]\n )\n\n const [loadedModels, setLoadedModels] = React.useState<LoadedModelFiles[]>([])\n const rendererRef = React.useRef<THREE.WebGLRenderer | null>(null)\n\n // Stable refs so the canvas listener never needs to be re-registered\n const loadedModelsRef = React.useRef<LoadedModelFiles[]>([])\n const onContextMenuRef = React.useRef(onContextMenu)\n loadedModelsRef.current = loadedModels\n onContextMenuRef.current = onContextMenu\n\n // ── Layer management ───────────────────────────────────────────────────────\n React.useEffect(() => {\n if (!map) return\n if (!rendererRef.current) {\n rendererRef.current = new THREE.WebGLRenderer({\n canvas: map.getCanvas(),\n context: map.getCanvas().getContext('webgl') as WebGLRenderingContext,\n antialias: true,\n })\n }\n const currentModelFiles = mapFiles.filter(file => {\n const ext = file.extension?.toLowerCase()\n return ext === 'glb' || ext === 'gltf' || ext === 'fbx' || ext === 'obj' || ext === 'collada'\n })\n const loadedIds = new Set(loadedModels.map(model => model.file.id))\n const currentFileIds = new Set(currentModelFiles.map(f => f.id))\n\n const modelsToRemove = loadedModels.filter(model => !currentFileIds.has(model.file.id))\n\n const modelsWithChangedCoords = loadedModels.filter(model => {\n if (!currentFileIds.has(model.file.id)) return false\n const updated = currentModelFiles.find(f => f.id === model.file.id)\n return updated && (\n updated.lat !== model.file.lat ||\n updated.lng !== model.file.lng ||\n updated.rotation !== model.file.rotation ||\n updated.elevation !== model.file.elevation ||\n updated.fileScale !== model.file.fileScale\n )\n })\n\n for (const model of [...modelsToRemove, ...modelsWithChangedCoords]) {\n model.cleanUpFunction()\n }\n\n const staleIds = new Set(modelsWithChangedCoords.map(m => m.file.id))\n\n const filesNotLoaded = currentModelFiles.filter(\n file => !loadedIds.has(file.id) || staleIds.has(file.id)\n )\n\n const newLoadedModels = loadedModels\n .filter(model => currentFileIds.has(model.file.id) && !staleIds.has(model.file.id))\n\n for (const file of filesNotLoaded) {\n const { cleanup, hitTest, animation } = CustomModelLayer(\n file,\n map,\n rendererRef.current,\n tempPositionsRef,\n editingFileIdRef,\n tempRotationsRef,\n tempElevationsRef,\n tempScalesRef,\n )\n newLoadedModels.push({ file, cleanUpFunction: cleanup, hitTest, animation })\n }\n\n setLoadedModels(newLoadedModels)\n }, [mapFiles, map])\n\n // ── Canvas right-click → raycasting ───────────────────────────────────────\n React.useEffect(() => {\n if (!map) return\n const canvas = map.getCanvas()\n\n const handleContextMenu = (e: MouseEvent) => {\n // Only handle clicks that land directly on the WebGL canvas (not on HTML\n // marker overlays — those have their own onContextMenu handlers)\n if (e.target !== canvas) return\n\n const models = loadedModelsRef.current\n if (models.length === 0) return\n\n const { ndcX, ndcY } = ndcOfEvent(e, canvas.getBoundingClientRect())\n\n for (const model of models) {\n if (model.hitTest(ndcX, ndcY)) {\n e.preventDefault()\n e.stopPropagation()\n onContextMenuRef.current?.(model.file, e.clientX, e.clientY, model.animation)\n break\n }\n }\n }\n\n // Use capture phase so we see the event before MapLibre's own handlers\n canvas.addEventListener('contextmenu', handleContextMenu, true)\n return () => canvas.removeEventListener('contextmenu', handleContextMenu, true)\n }, [map])\n\n // Teardown: remove model layers + dispose the shared renderer on unmount / map\n // change, else the WebGLRenderer + its scenes leak across viewer switches.\n React.useEffect(() => {\n return () => {\n for (const model of loadedModelsRef.current) {\n try { model.cleanUpFunction() } catch { /* layer or map may already be gone */ }\n }\n if (rendererRef.current) {\n rendererRef.current.dispose()\n rendererRef.current = null\n }\n }\n }, [map])\n\n return null\n}\n"],"mappings":";AAKA,YAAY,WAAW;AACvB,YAAY,WAAW;AAEvB,SAAS,YAAY,oBAAoB;AACzC,SAAS,kBAAkB;AAC3B,SAAS,wBAAwB;AAsB1B,MAAM,iBAAiB,CAAC;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAA2B;AACzB,QAAM,EAAE,OAAO,SAAS,IAAI,MAAM,WAAW,UAAU;AACvD,QAAM,EAAE,IAAI,IAAI,SAAS;AACzB,QAAM,EAAE,OAAO,UAAU,IAAI,MAAM,WAAW,YAAY;AAC1D,QAAM,EAAE,OAAO,iBAAiB,WAAW,IAAI,UAAU;AAEzD,QAAM,gBAAgB,CAAC,cAAuC;AAC5D,QA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AAI,OAAO,WAAW,EAAG;AAEzB,YAAM,EAAE,MAAM,KAAK,IAAI,WAAW,GAAG,OAAO,sBAAsB,CAAC;AAEnE,iBAAW,SAAS,QAAQ;AAC1B,YAAI,MAAM,QAAQ,MAAM,IAAI,GAAG;AAC7B,YAAE,eAAe;AACjB,YAAE,gBAAgB;AAClB,iCAAiB,YAAjB,0CAA2B,MAAM,MAAM,EAAE,SAAS,EAAE,SAAS,MAAM;AACnE;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAGA,WAAO,iBAAiB,eAAe,mBAAmB,IAAI;AAC9D,WAAO,MAAM,OAAO,oBAAoB,eAAe,mBAAmB,IAAI;AAAA,EAChF,GAAG,CAAC,GAAG,CAAC;AAIR,QAAM,UAAU,MAAM;AACpB,WAAO,MAAM;AACX,iBAAW,SAAS,gBAAgB,SAAS;AAC3C,YAAI;AAAE,gBAAM,gBAAgB;AAAA,QAAE,SAAQ;AAAA,QAAyC;AAAA,MACjF;AACA,UAAI,YAAY,SAAS;AACvB,oBAAY,QAAQ,QAAQ;AAC5B,oBAAY,UAAU;AAAA,MACxB;AAAA,IACF;AAAA,EACF,GAAG,CAAC,GAAG,CAAC;AAER,SAAO;AACT;","names":[]}
|
package/dist/core/components/viewers/map/src/MapLayers/src/FileLayer/utils/CustomModelLayer.js
CHANGED
|
@@ -161,7 +161,7 @@ const CustomModelLayer = (modelFile, map, renderer, tempPositionsRef, editingFil
|
|
|
161
161
|
const modelOrigin = [lng, lat];
|
|
162
162
|
const terrainAltitude = isEditing ? (_c = map.queryTerrainElevation([lng, lat])) != null ? _c : cachedTerrainElev : cachedTerrainElev;
|
|
163
163
|
const altitude = terrainAltitude + fileElevation;
|
|
164
|
-
const fileScale = isEditing && (tempScalesRef == null ? void 0 : tempScalesRef.current[modelFileKey]) !== void 0 ? tempScalesRef.current[modelFileKey] : (_d = modelFile.
|
|
164
|
+
const fileScale = isEditing && (tempScalesRef == null ? void 0 : tempScalesRef.current[modelFileKey]) !== void 0 ? tempScalesRef.current[modelFileKey] : (_d = modelFile.fileScale) != null ? _d : 1;
|
|
165
165
|
_m.fromArray(args.defaultProjectionData.mainMatrix);
|
|
166
166
|
writeModelMatrix(_l, modelOrigin, altitude).scale(_scaleVec.setScalar(fileScale));
|
|
167
167
|
this.camera.projectionMatrix.multiplyMatrices(_m, _l);
|
package/dist/core/components/viewers/map/src/MapLayers/src/FileLayer/utils/CustomModelLayer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/FileLayer/utils/CustomModelLayer.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport { type CustomLayerInterface, type LngLatLike, type Map } from 'maplibre-gl'\nimport * as THREE from 'three'\nimport { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'\n\nimport { applyAnimationTo, initialState, withClip, withPlaying, withSpeed } from '../../../../../../shared/placement/modelAnimation'\nimport { hitTestLayerScene } from '../../../../../utils/layerRaycast'\nimport { writeModelMatrix } from '../../../../../utils/modelMatrix'\nimport { disposeThreeScene } from '../../disposeThreeScene'\n\nimport type { DbFile } from '../../../../../../../../types/dbTypes'\nimport type { AnimationState } from '../../../../../../shared/placement/modelAnimation'\n\ntype TempPositionsRef = React.MutableRefObject<Record<string, { lat: number; lng: number }>>\ntype TempRotationsRef = React.MutableRefObject<Record<string, number>>\ntype TempElevationsRef = React.MutableRefObject<Record<string, number>>\ntype TempScalesRef = React.MutableRefObject<Record<string, number>>\ntype EditingFileIdRef = React.MutableRefObject<string | null>\n\nfunction resolveModelCoordinates(file: DbFile): { lng: number, lat: number } {\n if (typeof file.lng === 'number' && typeof file.lat === 'number') {\n return { lng: file.lng, lat: file.lat }\n }\n\n const rawPosition = file.position as unknown\n if (rawPosition && typeof rawPosition === 'object') {\n const pos = rawPosition as { lng?: number, lat?: number }\n if (typeof pos.lng === 'number' && typeof pos.lat === 'number') {\n return { lng: pos.lng, lat: pos.lat }\n }\n }\n\n if (typeof rawPosition === 'string') {\n try {\n const parsed = JSON.parse(rawPosition) as { lng?: number, lat?: number }\n if (typeof parsed.lng === 'number' && typeof parsed.lat === 'number') {\n return { lng: parsed.lng, lat: parsed.lat }\n }\n }\n catch {\n // Ignore malformed legacy position payloads.\n }\n }\n\n return { lng: 0, lat: 0 }\n}\n\n/** Playback for a loaded model's clips, so the map's animation card drives the same state the BIM one does. */\nexport interface ModelAnimationControls {\n getClips(): string[]\n getAnimation(): AnimationState | null\n setClip(clipIndex: number): void\n setPlaying(playing: boolean): void\n setSpeed(speed: number): void\n}\n\nexport interface ModelLayerHandle {\n cleanup: () => void\n remove: () => void\n hitTest: (ndcX: number, ndcY: number) => boolean\n animation: ModelAnimationControls\n}\n\nexport const CustomModelLayer = (\n modelFile: DbFile,\n map: Map,\n renderer: THREE.WebGLRenderer,\n tempPositionsRef?: TempPositionsRef,\n editingFileIdRef?: EditingFileIdRef,\n tempRotationsRef?: TempRotationsRef,\n tempElevationsRef?: TempElevationsRef,\n tempScalesRef?: TempScalesRef,\n): ModelLayerHandle => {\n let components = null\n let customLayer: CustomLayerInterface | null = null\n let clips: THREE.AnimationClip[] = []\n let animation: AnimationState | null = null\n let mixerRef: THREE.AnimationMixer | null = null\n\n const noControls: ModelAnimationControls = {\n getClips: () => [],\n getAnimation: () => null,\n setClip: () => {},\n setPlaying: () => {},\n setSpeed: () => {},\n }\n\n if (!map || !modelFile) {\n return { cleanup: () => {}, remove: () => {}, hitTest: () => false, animation: noControls }\n }\n\n const modelFileKey = String(modelFile.id)\n\n // Refs into the layer's camera and scene so raycasting can read the last\n // rendered frame's transform without entering the render loop.\n let cameraRef: THREE.Camera | null = null\n let sceneRef: THREE.Scene | null = null\n\n\n const createCustomLayer = (): CustomLayerInterface => {\n // Track last applied rotation so we can apply delta increments (same as BimLayer)\n let lastAppliedRotation = modelFile.rotation ?? 0\n // Layer-removed-mid-load guard + reused per-frame matrices\n let disposed = false\n const _m = new THREE.Matrix4()\n const _l = new THREE.Matrix4()\n const _scaleVec = new THREE.Vector3()\n // Render-on-demand: cache terrain elevation off the per-frame path and only\n // keep repainting while the camera recently moved or an animation is playing,\n // so an idle map with a placed model stops re-rendering instead of pinning the\n // main thread (this was the freeze after a flyTo to high zoom).\n let cachedTerrainElev = 0\n let lastMoveTime = performance.now()\n const SETTLE_MS = 1000\n let onMapMove: (() => void) | undefined\n let onMapMoveEnd: (() => void) | undefined\n const recomputeTerrainElev = () => {\n const { lng, lat } = resolveModelCoordinates(modelFile)\n if (!(lng === 0 && lat === 0)) {\n const e = map.queryTerrainElevation([lng, lat])\n if (e !== null && e !== undefined) cachedTerrainElev = e\n }\n }\n\n return {\n id: `model-${modelFile.id}`,\n type: 'custom',\n renderingMode: '3d',\n onAdd(map, gl) {\n this.camera = new THREE.Camera()\n this.scene = new THREE.Scene()\n this.renderer = renderer\n\n // Expose to closure for raycasting\n cameraRef = this.camera as THREE.Camera\n sceneRef = this.scene as THREE.Scene\n\n const scene = this.scene as THREE.Scene\n\n // Apply initial rotation\n if (lastAppliedRotation !== 0) {\n scene.rotateY(lastAppliedRotation * (Math.PI / 180))\n }\n\n // Lighting to match OBC library setup\n scene.background = null\n scene.fog = new THREE.Fog(0x20_29_32, 10, 200)\n scene.add(new THREE.AmbientLight(0xFF_FF_FF, 1))\n scene.add(new THREE.HemisphereLight(0xFF_FF_BB, 0x08_08_20, 0.5))\n\n const sun = new THREE.DirectionalLight(0xFF_FF_FF, 1.5)\n sun.position.set(0, -70, 100).normalize()\n sun.castShadow = true\n sun.shadow.mapSize.set(2048, 2048)\n scene.add(sun)\n\n const fill = new THREE.DirectionalLight(0xFF_FF_FF, 1)\n fill.position.set(0, 70, 100).normalize()\n scene.add(fill)\n\n this.renderer.toneMapping = THREE.ACESFilmicToneMapping\n this.renderer.autoClear = false\n this.clock = new THREE.Clock()\n\n const loader = new GLTFLoader()\n loader.load(\n modelFile.url!,\n (gltf) => {\n // Layer was removed before the async load resolved — don't attach to a\n // dead scene; let the gltf be GC'd (no GPU upload happened yet).\n if (disposed) return\n gltf.scene.scale.setScalar(1)\n\n clips = gltf.animations ?? []\n animation = initialState(clips.length)\n if (animation) {\n this.mixer = new THREE.AnimationMixer(gltf.scene)\n mixerRef = this.mixer\n applyAnimationTo(this.mixer, clips, animation)\n }\n\n scene.add(gltf.scene)\n // Open the settle window so the just-loaded model paints, then idle.\n lastMoveTime = performance.now()\n recomputeTerrainElev()\n map.triggerRepaint()\n },\n undefined,\n (error) => { console.error('Error loading model:', error) },\n )\n\n // Track camera movement for render-on-demand: keep repainting only\n // during/just-after movement; refresh cached terrain elevation on settle.\n onMapMove = () => { lastMoveTime = performance.now() }\n onMapMoveEnd = () => {\n lastMoveTime = performance.now()\n recomputeTerrainElev()\n map.triggerRepaint()\n }\n map.on('move', onMapMove)\n map.on('moveend', onMapMoveEnd)\n },\n\n render(gl, args) {\n if (map.getZoom() < 15.5) return\n\n const isEditing = editingFileIdRef?.current === modelFileKey\n\n // ── Position ──────────────────────────────────────────────────────────\n let lng: number\n let lat: number\n if (isEditing && tempPositionsRef?.current[modelFileKey]) {\n const tp = tempPositionsRef.current[modelFileKey]\n lng = tp.lng\n lat = tp.lat\n } else {\n const coords = resolveModelCoordinates(modelFile)\n lng = coords.lng\n lat = coords.lat\n }\n\n if (lng === 0 && lat === 0) return\n\n // ── Rotation (delta-increment, same pattern as BimLayer) ──────────────\n const targetRotation = (isEditing && tempRotationsRef?.current[modelFileKey] !== undefined)\n ? tempRotationsRef.current[modelFileKey]\n : (modelFile.rotation ?? 0)\n\n if (targetRotation !== lastAppliedRotation) {\n ;(this.scene as THREE.Scene).rotateY(\n (targetRotation - lastAppliedRotation) * (Math.PI / 180)\n )\n lastAppliedRotation = targetRotation\n }\n\n // ── Elevation ─────────────────────────────────────────────────────────\n const fileElevation = (isEditing && tempElevationsRef?.current[modelFileKey] !== undefined)\n ? tempElevationsRef.current[modelFileKey]\n : (modelFile.elevation ?? 0)\n\n const modelOrigin = [lng, lat] as LngLatLike\n // Cached terrain elevation (refreshed on moveend); query live only while\n // editing this model's position. Keeps queryTerrainElevation off the hot\n // path — the per-frame query drove the high-zoom freeze.\n const terrainAltitude = isEditing\n ? (map.queryTerrainElevation([lng, lat]) ?? cachedTerrainElev)\n : cachedTerrainElev\n const altitude = terrainAltitude + fileElevation\n\n const fileScale = (isEditing && tempScalesRef?.current[modelFileKey] !== undefined)\n ? tempScalesRef.current[modelFileKey]\n : (modelFile.scale ?? 1)\n\n _m.fromArray(args.defaultProjectionData.mainMatrix)\n writeModelMatrix(_l, modelOrigin, altitude).scale(_scaleVec.setScalar(fileScale))\n this.camera.projectionMatrix.multiplyMatrices(_m, _l)\n\n if (this.mixer) {\n this.mixer.update((this.clock as THREE.Clock).getDelta())\n }\n\n this.renderer.resetState()\n this.renderer.render(this.scene, this.camera)\n\n // Render-on-demand: keep the frame loop alive only while an animation is\n // playing, the camera recently moved (settle window), or this model is\n // being edited. Idle static model ⇒ no self-scheduled repaints ⇒ no freeze.\n if (animation?.playing || isEditing || performance.now() - lastMoveTime < SETTLE_MS) {\n map.triggerRepaint()\n }\n },\n\n onRemove() {\n disposed = true\n if (onMapMove) map.off('move', onMapMove)\n if (onMapMoveEnd) map.off('moveend', onMapMoveEnd)\n // Stop + release the animation mixer so it isn't left running/holding the\n // scene after removal.\n if (this.mixer) {\n ;(this.mixer as THREE.AnimationMixer).stopAllAction()\n this.mixer = null\n }\n mixerRef = null\n clips = []\n animation = null\n if (this.scene) disposeThreeScene(this.scene as THREE.Scene)\n cameraRef = null\n sceneRef = null\n this.renderer = null\n this.camera = null\n this.scene = null\n },\n }\n }\n\n const hitTest = (ndcX: number, ndcY: number): boolean => hitTestLayerScene(cameraRef, sceneRef, ndcX, ndcY)\n\n customLayer = createCustomLayer()\n\n if (!map.getLayer(customLayer.id)) {\n map.addLayer(customLayer)\n }\n\n const removeLayer = () => {\n if (customLayer && map.getLayer(customLayer.id)) {\n map.removeLayer(customLayer.id)\n }\n }\n\n const cleanup = () => {\n removeLayer()\n components = null\n customLayer = null\n }\n\n const commit = (next: AnimationState | null) => {\n if (!next || !mixerRef) return\n animation = next\n applyAnimationTo(mixerRef, clips, next)\n map.triggerRepaint()\n }\n\n const controls: ModelAnimationControls = {\n getClips: () => clips.map((clip, index) => clip.name || `Clip ${index + 1}`),\n getAnimation: () => animation,\n setClip: clipIndex => commit(animation && withClip(animation, clipIndex, clips.length)),\n setPlaying: playing => commit(animation && withPlaying(animation, playing)),\n setSpeed: speed => commit(animation && withSpeed(animation, speed)),\n }\n\n return { cleanup, remove: removeLayer, hitTest, animation: controls }\n}\n"],"mappings":"AAIA,YAAY,WAAW;AACvB,SAAS,kBAAkB;AAE3B,SAAS,kBAAkB,cAAc,UAAU,aAAa,iBAAiB;AACjF,SAAS,yBAAyB;AAClC,SAAS,wBAAwB;AACjC,SAAS,yBAAyB;AAWlC,SAAS,wBAAwB,MAA4C;AAC3E,MAAI,OAAO,KAAK,QAAQ,YAAY,OAAO,KAAK,QAAQ,UAAU;AAChE,WAAO,EAAE,KAAK,KAAK,KAAK,KAAK,KAAK,IAAI;AAAA,EACxC;AAEA,QAAM,cAAc,KAAK;AACzB,MAAI,eAAe,OAAO,gBAAgB,UAAU;AAClD,UAAM,MAAM;AACZ,QAAI,OAAO,IAAI,QAAQ,YAAY,OAAO,IAAI,QAAQ,UAAU;AAC9D,aAAO,EAAE,KAAK,IAAI,KAAK,KAAK,IAAI,IAAI;AAAA,IACtC;AAAA,EACF;AAEA,MAAI,OAAO,gBAAgB,UAAU;AACnC,QAAI;AACF,YAAM,SAAS,KAAK,MAAM,WAAW;AACrC,UAAI,OAAO,OAAO,QAAQ,YAAY,OAAO,OAAO,QAAQ,UAAU;AACpE,eAAO,EAAE,KAAK,OAAO,KAAK,KAAK,OAAO,IAAI;AAAA,MAC5C;AAAA,IACF,SACM;AAAA,IAEN;AAAA,EACF;AAEA,SAAO,EAAE,KAAK,GAAG,KAAK,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I,SAAS,YAAY,EAAE,GAAG;AACjC,QAAI,SAAS,WAAW;AAAA,EAC1B;AAEA,QAAM,cAAc,MAAM;AACxB,QAAI,eAAe,IAAI,SAAS,YAAY,EAAE,GAAG;AAC/C,UAAI,YAAY,YAAY,EAAE;AAAA,IAChC;AAAA,EACF;AAEA,QAAM,UAAU,MAAM;AACpB,gBAAY;AACZ,iBAAa;AACb,kBAAc;AAAA,EAChB;AAEA,QAAM,SAAS,CAAC,SAAgC;AAC9C,QAAI,CAAC,QAAQ,CAAC,SAAU;AACxB,gBAAY;AACZ,qBAAiB,UAAU,OAAO,IAAI;AACtC,QAAI,eAAe;AAAA,EACrB;AAEA,QAAM,WAAmC;AAAA,IACvC,UAAU,MAAM,MAAM,IAAI,CAAC,MAAM,UAAU,KAAK,QAAQ,QAAQ,QAAQ,CAAC,EAAE;AAAA,IAC3E,cAAc,MAAM;AAAA,IACpB,SAAS,eAAa,OAAO,aAAa,SAAS,WAAW,WAAW,MAAM,MAAM,CAAC;AAAA,IACtF,YAAY,aAAW,OAAO,aAAa,YAAY,WAAW,OAAO,CAAC;AAAA,IAC1E,UAAU,WAAS,OAAO,aAAa,UAAU,WAAW,KAAK,CAAC;AAAA,EACpE;AAEA,SAAO,EAAE,SAAS,QAAQ,aAAa,SAAS,WAAW,SAAS;AACtE;","names":["map","_a"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/FileLayer/utils/CustomModelLayer.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport { type CustomLayerInterface, type LngLatLike, type Map } from 'maplibre-gl'\nimport * as THREE from 'three'\nimport { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'\n\nimport { applyAnimationTo, initialState, withClip, withPlaying, withSpeed } from '../../../../../../shared/placement/modelAnimation'\nimport { hitTestLayerScene } from '../../../../../utils/layerRaycast'\nimport { writeModelMatrix } from '../../../../../utils/modelMatrix'\nimport { disposeThreeScene } from '../../disposeThreeScene'\n\nimport type { DbFile } from '../../../../../../../../types/dbTypes'\nimport type { AnimationState } from '../../../../../../shared/placement/modelAnimation'\n\ntype TempPositionsRef = React.MutableRefObject<Record<string, { lat: number; lng: number }>>\ntype TempRotationsRef = React.MutableRefObject<Record<string, number>>\ntype TempElevationsRef = React.MutableRefObject<Record<string, number>>\ntype TempScalesRef = React.MutableRefObject<Record<string, number>>\ntype EditingFileIdRef = React.MutableRefObject<string | null>\n\nfunction resolveModelCoordinates(file: DbFile): { lng: number, lat: number } {\n if (typeof file.lng === 'number' && typeof file.lat === 'number') {\n return { lng: file.lng, lat: file.lat }\n }\n\n const rawPosition = file.position as unknown\n if (rawPosition && typeof rawPosition === 'object') {\n const pos = rawPosition as { lng?: number, lat?: number }\n if (typeof pos.lng === 'number' && typeof pos.lat === 'number') {\n return { lng: pos.lng, lat: pos.lat }\n }\n }\n\n if (typeof rawPosition === 'string') {\n try {\n const parsed = JSON.parse(rawPosition) as { lng?: number, lat?: number }\n if (typeof parsed.lng === 'number' && typeof parsed.lat === 'number') {\n return { lng: parsed.lng, lat: parsed.lat }\n }\n }\n catch {\n // Ignore malformed legacy position payloads.\n }\n }\n\n return { lng: 0, lat: 0 }\n}\n\n/** Playback for a loaded model's clips, so the map's animation card drives the same state the BIM one does. */\nexport interface ModelAnimationControls {\n getClips(): string[]\n getAnimation(): AnimationState | null\n setClip(clipIndex: number): void\n setPlaying(playing: boolean): void\n setSpeed(speed: number): void\n}\n\nexport interface ModelLayerHandle {\n cleanup: () => void\n remove: () => void\n hitTest: (ndcX: number, ndcY: number) => boolean\n animation: ModelAnimationControls\n}\n\nexport const CustomModelLayer = (\n modelFile: DbFile,\n map: Map,\n renderer: THREE.WebGLRenderer,\n tempPositionsRef?: TempPositionsRef,\n editingFileIdRef?: EditingFileIdRef,\n tempRotationsRef?: TempRotationsRef,\n tempElevationsRef?: TempElevationsRef,\n tempScalesRef?: TempScalesRef,\n): ModelLayerHandle => {\n let components = null\n let customLayer: CustomLayerInterface | null = null\n let clips: THREE.AnimationClip[] = []\n let animation: AnimationState | null = null\n let mixerRef: THREE.AnimationMixer | null = null\n\n const noControls: ModelAnimationControls = {\n getClips: () => [],\n getAnimation: () => null,\n setClip: () => {},\n setPlaying: () => {},\n setSpeed: () => {},\n }\n\n if (!map || !modelFile) {\n return { cleanup: () => {}, remove: () => {}, hitTest: () => false, animation: noControls }\n }\n\n const modelFileKey = String(modelFile.id)\n\n // Refs into the layer's camera and scene so raycasting can read the last\n // rendered frame's transform without entering the render loop.\n let cameraRef: THREE.Camera | null = null\n let sceneRef: THREE.Scene | null = null\n\n\n const createCustomLayer = (): CustomLayerInterface => {\n // Track last applied rotation so we can apply delta increments (same as BimLayer)\n let lastAppliedRotation = modelFile.rotation ?? 0\n // Layer-removed-mid-load guard + reused per-frame matrices\n let disposed = false\n const _m = new THREE.Matrix4()\n const _l = new THREE.Matrix4()\n const _scaleVec = new THREE.Vector3()\n // Render-on-demand: cache terrain elevation off the per-frame path and only\n // keep repainting while the camera recently moved or an animation is playing,\n // so an idle map with a placed model stops re-rendering instead of pinning the\n // main thread (this was the freeze after a flyTo to high zoom).\n let cachedTerrainElev = 0\n let lastMoveTime = performance.now()\n const SETTLE_MS = 1000\n let onMapMove: (() => void) | undefined\n let onMapMoveEnd: (() => void) | undefined\n const recomputeTerrainElev = () => {\n const { lng, lat } = resolveModelCoordinates(modelFile)\n if (!(lng === 0 && lat === 0)) {\n const e = map.queryTerrainElevation([lng, lat])\n if (e !== null && e !== undefined) cachedTerrainElev = e\n }\n }\n\n return {\n id: `model-${modelFile.id}`,\n type: 'custom',\n renderingMode: '3d',\n onAdd(map, gl) {\n this.camera = new THREE.Camera()\n this.scene = new THREE.Scene()\n this.renderer = renderer\n\n // Expose to closure for raycasting\n cameraRef = this.camera as THREE.Camera\n sceneRef = this.scene as THREE.Scene\n\n const scene = this.scene as THREE.Scene\n\n // Apply initial rotation\n if (lastAppliedRotation !== 0) {\n scene.rotateY(lastAppliedRotation * (Math.PI / 180))\n }\n\n // Lighting to match OBC library setup\n scene.background = null\n scene.fog = new THREE.Fog(0x20_29_32, 10, 200)\n scene.add(new THREE.AmbientLight(0xFF_FF_FF, 1))\n scene.add(new THREE.HemisphereLight(0xFF_FF_BB, 0x08_08_20, 0.5))\n\n const sun = new THREE.DirectionalLight(0xFF_FF_FF, 1.5)\n sun.position.set(0, -70, 100).normalize()\n sun.castShadow = true\n sun.shadow.mapSize.set(2048, 2048)\n scene.add(sun)\n\n const fill = new THREE.DirectionalLight(0xFF_FF_FF, 1)\n fill.position.set(0, 70, 100).normalize()\n scene.add(fill)\n\n this.renderer.toneMapping = THREE.ACESFilmicToneMapping\n this.renderer.autoClear = false\n this.clock = new THREE.Clock()\n\n const loader = new GLTFLoader()\n loader.load(\n modelFile.url!,\n (gltf) => {\n // Layer was removed before the async load resolved — don't attach to a\n // dead scene; let the gltf be GC'd (no GPU upload happened yet).\n if (disposed) return\n gltf.scene.scale.setScalar(1)\n\n clips = gltf.animations ?? []\n animation = initialState(clips.length)\n if (animation) {\n this.mixer = new THREE.AnimationMixer(gltf.scene)\n mixerRef = this.mixer\n applyAnimationTo(this.mixer, clips, animation)\n }\n\n scene.add(gltf.scene)\n // Open the settle window so the just-loaded model paints, then idle.\n lastMoveTime = performance.now()\n recomputeTerrainElev()\n map.triggerRepaint()\n },\n undefined,\n (error) => { console.error('Error loading model:', error) },\n )\n\n // Track camera movement for render-on-demand: keep repainting only\n // during/just-after movement; refresh cached terrain elevation on settle.\n onMapMove = () => { lastMoveTime = performance.now() }\n onMapMoveEnd = () => {\n lastMoveTime = performance.now()\n recomputeTerrainElev()\n map.triggerRepaint()\n }\n map.on('move', onMapMove)\n map.on('moveend', onMapMoveEnd)\n },\n\n render(gl, args) {\n if (map.getZoom() < 15.5) return\n\n const isEditing = editingFileIdRef?.current === modelFileKey\n\n // ── Position ──────────────────────────────────────────────────────────\n let lng: number\n let lat: number\n if (isEditing && tempPositionsRef?.current[modelFileKey]) {\n const tp = tempPositionsRef.current[modelFileKey]\n lng = tp.lng\n lat = tp.lat\n } else {\n const coords = resolveModelCoordinates(modelFile)\n lng = coords.lng\n lat = coords.lat\n }\n\n if (lng === 0 && lat === 0) return\n\n // ── Rotation (delta-increment, same pattern as BimLayer) ──────────────\n const targetRotation = (isEditing && tempRotationsRef?.current[modelFileKey] !== undefined)\n ? tempRotationsRef.current[modelFileKey]\n : (modelFile.rotation ?? 0)\n\n if (targetRotation !== lastAppliedRotation) {\n ;(this.scene as THREE.Scene).rotateY(\n (targetRotation - lastAppliedRotation) * (Math.PI / 180)\n )\n lastAppliedRotation = targetRotation\n }\n\n // ── Elevation ─────────────────────────────────────────────────────────\n const fileElevation = (isEditing && tempElevationsRef?.current[modelFileKey] !== undefined)\n ? tempElevationsRef.current[modelFileKey]\n : (modelFile.elevation ?? 0)\n\n const modelOrigin = [lng, lat] as LngLatLike\n // Cached terrain elevation (refreshed on moveend); query live only while\n // editing this model's position. Keeps queryTerrainElevation off the hot\n // path — the per-frame query drove the high-zoom freeze.\n const terrainAltitude = isEditing\n ? (map.queryTerrainElevation([lng, lat]) ?? cachedTerrainElev)\n : cachedTerrainElev\n const altitude = terrainAltitude + fileElevation\n\n const fileScale = (isEditing && tempScalesRef?.current[modelFileKey] !== undefined)\n ? tempScalesRef.current[modelFileKey]\n : (modelFile.fileScale ?? 1)\n\n _m.fromArray(args.defaultProjectionData.mainMatrix)\n writeModelMatrix(_l, modelOrigin, altitude).scale(_scaleVec.setScalar(fileScale))\n this.camera.projectionMatrix.multiplyMatrices(_m, _l)\n\n if (this.mixer) {\n this.mixer.update((this.clock as THREE.Clock).getDelta())\n }\n\n this.renderer.resetState()\n this.renderer.render(this.scene, this.camera)\n\n // Render-on-demand: keep the frame loop alive only while an animation is\n // playing, the camera recently moved (settle window), or this model is\n // being edited. Idle static model ⇒ no self-scheduled repaints ⇒ no freeze.\n if (animation?.playing || isEditing || performance.now() - lastMoveTime < SETTLE_MS) {\n map.triggerRepaint()\n }\n },\n\n onRemove() {\n disposed = true\n if (onMapMove) map.off('move', onMapMove)\n if (onMapMoveEnd) map.off('moveend', onMapMoveEnd)\n // Stop + release the animation mixer so it isn't left running/holding the\n // scene after removal.\n if (this.mixer) {\n ;(this.mixer as THREE.AnimationMixer).stopAllAction()\n this.mixer = null\n }\n mixerRef = null\n clips = []\n animation = null\n if (this.scene) disposeThreeScene(this.scene as THREE.Scene)\n cameraRef = null\n sceneRef = null\n this.renderer = null\n this.camera = null\n this.scene = null\n },\n }\n }\n\n const hitTest = (ndcX: number, ndcY: number): boolean => hitTestLayerScene(cameraRef, sceneRef, ndcX, ndcY)\n\n customLayer = createCustomLayer()\n\n if (!map.getLayer(customLayer.id)) {\n map.addLayer(customLayer)\n }\n\n const removeLayer = () => {\n if (customLayer && map.getLayer(customLayer.id)) {\n map.removeLayer(customLayer.id)\n }\n }\n\n const cleanup = () => {\n removeLayer()\n components = null\n customLayer = null\n }\n\n const commit = (next: AnimationState | null) => {\n if (!next || !mixerRef) return\n animation = next\n applyAnimationTo(mixerRef, clips, next)\n map.triggerRepaint()\n }\n\n const controls: ModelAnimationControls = {\n getClips: () => clips.map((clip, index) => clip.name || `Clip ${index + 1}`),\n getAnimation: () => animation,\n setClip: clipIndex => commit(animation && withClip(animation, clipIndex, clips.length)),\n setPlaying: playing => commit(animation && withPlaying(animation, playing)),\n setSpeed: speed => commit(animation && withSpeed(animation, speed)),\n }\n\n return { cleanup, remove: removeLayer, hitTest, animation: controls }\n}\n"],"mappings":"AAIA,YAAY,WAAW;AACvB,SAAS,kBAAkB;AAE3B,SAAS,kBAAkB,cAAc,UAAU,aAAa,iBAAiB;AACjF,SAAS,yBAAyB;AAClC,SAAS,wBAAwB;AACjC,SAAS,yBAAyB;AAWlC,SAAS,wBAAwB,MAA4C;AAC3E,MAAI,OAAO,KAAK,QAAQ,YAAY,OAAO,KAAK,QAAQ,UAAU;AAChE,WAAO,EAAE,KAAK,KAAK,K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1E,UAAU,WAAS,OAAO,aAAa,UAAU,WAAW,KAAK,CAAC;AAAA,EACpE;AAEA,SAAO,EAAE,SAAS,QAAQ,aAAa,SAAS,WAAW,SAAS;AACtE;","names":["map","_a"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../../../src/core/components/viewers/map/src/MapLayers/src/OpenDataLayer/src/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/OpenDataLayer/src/index.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAkc/B,eAAO,MAAM,cAAc,yBA8K1B,CAAC"}
|
|
@@ -31,6 +31,8 @@ import { fetchWmsFrames, buildWmsTimeUrl, wmsLegendUrl } from "../../../../../da
|
|
|
31
31
|
import { MapLayerClickPriority } from "../../../../../utils/MapEventManager/MapClickManager";
|
|
32
32
|
import MapFeaturePopoverMenu from "../../../../MapFeaturePopoverMenu";
|
|
33
33
|
import { groupFeaturesByGeometry } from "./geometryGroups";
|
|
34
|
+
import { useDatasetFeatures } from "./useDatasetFeatures";
|
|
35
|
+
import { useViewportDatasetToast } from "./useViewportDatasetToast";
|
|
34
36
|
import { WmsTimeControl } from "./WmsTimeControl";
|
|
35
37
|
const isBuildingDataset = (dataset) => {
|
|
36
38
|
return dataset.type === "buildings" && "data" in dataset;
|
|
@@ -57,30 +59,20 @@ const computeMinMax = (features, fieldName) => {
|
|
|
57
59
|
if (!found) return null;
|
|
58
60
|
return { min, max: max === min ? min + 1 : max };
|
|
59
61
|
};
|
|
62
|
+
function useOverlaySlot(enabled) {
|
|
63
|
+
const [slot, setSlot] = React.useState(null);
|
|
64
|
+
React.useEffect(() => {
|
|
65
|
+
setSlot(enabled ? document.getElementById("wms-time-slot") : null);
|
|
66
|
+
}, [enabled]);
|
|
67
|
+
return slot;
|
|
68
|
+
}
|
|
60
69
|
const GeoJsonDatasetLayer = React.memo(({ dataset, index, onLayerReady, onLayerRemoved }) => {
|
|
61
70
|
var _a;
|
|
62
71
|
const { state: mapState } = React.useContext(MapContext);
|
|
63
72
|
const { map } = mapState.map;
|
|
64
|
-
const [featureCollection, setFeatureCollection] = React.useState(null);
|
|
65
73
|
const fitBoundsAppliedRef = React.useRef(false);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
let cancelled = false;
|
|
69
|
-
const load = async () => {
|
|
70
|
-
try {
|
|
71
|
-
const fetched = await dataset.getFeatures();
|
|
72
|
-
if (cancelled) return;
|
|
73
|
-
const fc = (fetched == null ? void 0 : fetched.type) === "FeatureCollection" ? fetched : { type: "FeatureCollection", features: [] };
|
|
74
|
-
setFeatureCollection(fc);
|
|
75
|
-
} catch (error) {
|
|
76
|
-
console.error(`OpenDataLayers: Error fetching features for "${dataset.name}":`, error);
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
void load();
|
|
80
|
-
return () => {
|
|
81
|
-
cancelled = true;
|
|
82
|
-
};
|
|
83
|
-
}, [map, dataset.name]);
|
|
74
|
+
const { featureCollection, status } = useDatasetFeatures(map, dataset);
|
|
75
|
+
useViewportDatasetToast(dataset.name, status);
|
|
84
76
|
const layerContent = React.useMemo(() => {
|
|
85
77
|
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
86
78
|
if (!featureCollection || featureCollection.features.length === 0) return null;
|
|
@@ -354,10 +346,7 @@ const WMSDatasetLayer = React.memo(({ dataset, index, onLayerReady, onLayerRemov
|
|
|
354
346
|
const timeEnabled = !!dataset.timeEnabled && !!dataset.wms;
|
|
355
347
|
const [frames, setFrames] = React.useState([]);
|
|
356
348
|
const [activeTime, setActiveTime] = React.useState(null);
|
|
357
|
-
const
|
|
358
|
-
React.useEffect(() => {
|
|
359
|
-
if (timeEnabled) setControlSlot(document.getElementById("wms-time-slot"));
|
|
360
|
-
}, [timeEnabled]);
|
|
349
|
+
const controlSlot = useOverlaySlot(timeEnabled);
|
|
361
350
|
React.useEffect(() => {
|
|
362
351
|
onLayerReady(dataset.name, []);
|
|
363
352
|
return () => {
|