@octostar/map-component 0.2.15 → 0.2.17
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/index.cjs +85 -62
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +85 -62
- package/dist/index.mjs.map +1 -1
- package/dist/types/components/map-editor-canvas.d.ts.map +1 -1
- package/dist/types/lib/layer-features.d.ts +27 -0
- package/dist/types/lib/layer-features.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1071,6 +1071,30 @@ function downloadBlob(blob, filename) {
|
|
|
1071
1071
|
anchor.remove();
|
|
1072
1072
|
setTimeout(() => URL.revokeObjectURL(url), 0);
|
|
1073
1073
|
}
|
|
1074
|
+
function collectLayerFeatures(layer, sources) {
|
|
1075
|
+
const features = [];
|
|
1076
|
+
if (layer.visible) {
|
|
1077
|
+
for (const id of layer.featureIds) {
|
|
1078
|
+
const f = sources.getDrawFeature(id);
|
|
1079
|
+
if (f) features.push(f);
|
|
1080
|
+
}
|
|
1081
|
+
} else {
|
|
1082
|
+
pushAll(features, sources.hiddenFeatures.get(layer.id) ?? []);
|
|
1083
|
+
}
|
|
1084
|
+
const readOnly = sources.readOnlyFeatures.get(layer.id);
|
|
1085
|
+
if (readOnly) pushAll(features, readOnly);
|
|
1086
|
+
return features;
|
|
1087
|
+
}
|
|
1088
|
+
function stripInternalProperties(features, keep) {
|
|
1089
|
+
return features.map((f) => ({
|
|
1090
|
+
...f,
|
|
1091
|
+
properties: Object.fromEntries(
|
|
1092
|
+
Object.entries(f.properties ?? {}).filter(
|
|
1093
|
+
([key]) => !key.startsWith("_") || ((keep == null ? void 0 : keep.has(key)) ?? false)
|
|
1094
|
+
)
|
|
1095
|
+
)
|
|
1096
|
+
}));
|
|
1097
|
+
}
|
|
1074
1098
|
const ToastContext = createContext(null);
|
|
1075
1099
|
function useToast() {
|
|
1076
1100
|
const externalToast = useContext(ToastContext);
|
|
@@ -7355,6 +7379,7 @@ const CustomSimpleSelect = {
|
|
|
7355
7379
|
startBoxSelect() {
|
|
7356
7380
|
}
|
|
7357
7381
|
};
|
|
7382
|
+
const ENRICHED_EXPORT_KEEP_KEYS = /* @__PURE__ */ new Set(["_layerIndex"]);
|
|
7358
7383
|
function createFlightPath3DLayer(layerId, mapInstance, flightPaths) {
|
|
7359
7384
|
let camera;
|
|
7360
7385
|
let scene;
|
|
@@ -13149,29 +13174,22 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
13149
13174
|
}, [measurePoints, measureMode, isMapLoaded]);
|
|
13150
13175
|
const handleSaveLayerGeoJSON = useCallback((layerId) => {
|
|
13151
13176
|
const layer = layers.find((l) => l.id === layerId);
|
|
13152
|
-
if (!layer
|
|
13153
|
-
const features =
|
|
13154
|
-
|
|
13155
|
-
|
|
13156
|
-
|
|
13157
|
-
|
|
13158
|
-
|
|
13159
|
-
|
|
13160
|
-
|
|
13161
|
-
pushAll(features, hidden);
|
|
13162
|
-
}
|
|
13177
|
+
if (!layer) return;
|
|
13178
|
+
const features = collectLayerFeatures(layer, {
|
|
13179
|
+
getDrawFeature: (id) => {
|
|
13180
|
+
var _a;
|
|
13181
|
+
return (_a = draw.current) == null ? void 0 : _a.get(id);
|
|
13182
|
+
},
|
|
13183
|
+
hiddenFeatures: hiddenFeatures.current,
|
|
13184
|
+
readOnlyFeatures: readOnlyFeatures.current
|
|
13185
|
+
});
|
|
13163
13186
|
const layerMetadata = {
|
|
13164
13187
|
name: layer.name
|
|
13165
13188
|
};
|
|
13166
13189
|
if (layer.traceConfig) layerMetadata.traceConfig = layer.traceConfig;
|
|
13167
13190
|
if (layer.heatmapConfig) layerMetadata.heatmapConfig = layer.heatmapConfig;
|
|
13168
13191
|
if (layer.visualConfig) layerMetadata.visualConfig = layer.visualConfig;
|
|
13169
|
-
const cleanedFeatures = features
|
|
13170
|
-
...f,
|
|
13171
|
-
properties: Object.fromEntries(
|
|
13172
|
-
Object.entries(f.properties || {}).filter(([key]) => !key.startsWith("_"))
|
|
13173
|
-
)
|
|
13174
|
-
}));
|
|
13192
|
+
const cleanedFeatures = stripInternalProperties(features);
|
|
13175
13193
|
const geojson = {
|
|
13176
13194
|
type: "FeatureCollection",
|
|
13177
13195
|
features: cleanedFeatures,
|
|
@@ -13203,18 +13221,14 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
13203
13221
|
var _a;
|
|
13204
13222
|
const isDataViewing = ((_a = layer.metadata) == null ? void 0 : _a.dataViewing) === true;
|
|
13205
13223
|
if (!isDataViewing) {
|
|
13206
|
-
const layerFeatures =
|
|
13207
|
-
|
|
13208
|
-
|
|
13209
|
-
|
|
13210
|
-
|
|
13211
|
-
|
|
13212
|
-
|
|
13213
|
-
|
|
13214
|
-
pushAll(layerFeatures, hidden);
|
|
13215
|
-
}
|
|
13216
|
-
const roFeatures = readOnlyFeatures.current.get(layer.id);
|
|
13217
|
-
if (roFeatures) pushAll(layerFeatures, roFeatures);
|
|
13224
|
+
const layerFeatures = collectLayerFeatures(layer, {
|
|
13225
|
+
getDrawFeature: (id) => {
|
|
13226
|
+
var _a2;
|
|
13227
|
+
return (_a2 = draw.current) == null ? void 0 : _a2.get(id);
|
|
13228
|
+
},
|
|
13229
|
+
hiddenFeatures: hiddenFeatures.current,
|
|
13230
|
+
readOnlyFeatures: readOnlyFeatures.current
|
|
13231
|
+
});
|
|
13218
13232
|
layerFeatures.forEach((f) => {
|
|
13219
13233
|
allFeatures.push({
|
|
13220
13234
|
...f,
|
|
@@ -13225,14 +13239,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
13225
13239
|
const { id: _id, featureIds: _fids, hasAltitudeData: _alt, ...persistable } = layer;
|
|
13226
13240
|
layerStates.push({ index: idx, ...persistable });
|
|
13227
13241
|
});
|
|
13228
|
-
const cleanedFeatures = allFeatures
|
|
13229
|
-
...f,
|
|
13230
|
-
properties: Object.fromEntries(
|
|
13231
|
-
Object.entries(f.properties || {}).filter(
|
|
13232
|
-
([key]) => !key.startsWith("_") || key === "_layerIndex"
|
|
13233
|
-
)
|
|
13234
|
-
)
|
|
13235
|
-
}));
|
|
13242
|
+
const cleanedFeatures = stripInternalProperties(allFeatures, ENRICHED_EXPORT_KEEP_KEYS);
|
|
13236
13243
|
let viewport;
|
|
13237
13244
|
if (map.current && isMapLoaded) {
|
|
13238
13245
|
const c = map.current.getCenter();
|
|
@@ -13563,6 +13570,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
13563
13570
|
}
|
|
13564
13571
|
}, [ingestProgressStore]);
|
|
13565
13572
|
const loadGeoJSONFile = useCallback(async (file, requestedTargetLayerId, createNewLayer) => {
|
|
13573
|
+
var _a;
|
|
13566
13574
|
let result;
|
|
13567
13575
|
try {
|
|
13568
13576
|
result = await ingestWithProgress(file.name, file, {
|
|
@@ -13651,14 +13659,49 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
13651
13659
|
return;
|
|
13652
13660
|
}
|
|
13653
13661
|
const currentLayers = layersRef.current;
|
|
13654
|
-
let targetLayer = currentLayers.find((l) => l.id === requestedTargetLayerId
|
|
13662
|
+
let targetLayer = currentLayers.find((l) => l.id === requestedTargetLayerId);
|
|
13663
|
+
if (((_a = targetLayer == null ? void 0 : targetLayer.metadata) == null ? void 0 : _a.dataViewing) === true) {
|
|
13664
|
+
toast({
|
|
13665
|
+
title: "Can't load into a data-viewing layer",
|
|
13666
|
+
description: "Its features are fetched from data and aren't saved with the map. Load the file into another layer.",
|
|
13667
|
+
variant: "destructive"
|
|
13668
|
+
});
|
|
13669
|
+
return;
|
|
13670
|
+
}
|
|
13655
13671
|
if (!targetLayer) {
|
|
13656
13672
|
targetLayer = currentLayers.find((l) => l.visible && !l.readOnly);
|
|
13657
13673
|
}
|
|
13658
13674
|
if (!targetLayer) {
|
|
13659
13675
|
targetLayer = currentLayers.find((l) => !l.readOnly);
|
|
13660
13676
|
}
|
|
13661
|
-
if (targetLayer
|
|
13677
|
+
if (!targetLayer) {
|
|
13678
|
+
toast({
|
|
13679
|
+
title: "No layer to load into",
|
|
13680
|
+
description: "Create a layer first, then load the file again.",
|
|
13681
|
+
variant: "destructive"
|
|
13682
|
+
});
|
|
13683
|
+
return;
|
|
13684
|
+
}
|
|
13685
|
+
const targetId = targetLayer.id;
|
|
13686
|
+
const withLayerMetadata = (l, addedIds) => ({
|
|
13687
|
+
...l,
|
|
13688
|
+
featureIds: [...l.featureIds, ...addedIds],
|
|
13689
|
+
...(layerMetadata == null ? void 0 : layerMetadata.traceConfig) && { traceConfig: layerMetadata.traceConfig },
|
|
13690
|
+
...(layerMetadata == null ? void 0 : layerMetadata.heatmapConfig) && { heatmapConfig: layerMetadata.heatmapConfig },
|
|
13691
|
+
...(layerMetadata == null ? void 0 : layerMetadata.visualConfig) && { visualConfig: layerMetadata.visualConfig }
|
|
13692
|
+
});
|
|
13693
|
+
if (targetLayer.readOnly) {
|
|
13694
|
+
const addedFeatures = normalizedFeatures.map((f) => ({ ...f, id: crypto.randomUUID() }));
|
|
13695
|
+
const addedIds = addedFeatures.map((f) => String(f.id));
|
|
13696
|
+
const existing = readOnlyFeatures.current.get(targetId) || [];
|
|
13697
|
+
readOnlyFeatures.current.set(targetId, [...existing, ...addedFeatures]);
|
|
13698
|
+
const cached = layerTemporalCacheRef.current.get(targetId);
|
|
13699
|
+
layerTemporalCacheRef.current.set(targetId, {
|
|
13700
|
+
featureCount: ((cached == null ? void 0 : cached.featureCount) ?? existing.length) + addedFeatures.length,
|
|
13701
|
+
hasTemporal: ((cached == null ? void 0 : cached.hasTemporal) ?? false) || fileHasTemporal
|
|
13702
|
+
});
|
|
13703
|
+
setLayers((prev) => prev.map((l) => l.id === targetId ? withLayerMetadata(l, addedIds) : l));
|
|
13704
|
+
} else if (targetLayer.visible) {
|
|
13662
13705
|
const addedIds = [];
|
|
13663
13706
|
isApiAddingRef.current = true;
|
|
13664
13707
|
try {
|
|
@@ -13669,32 +13712,12 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
13669
13712
|
} finally {
|
|
13670
13713
|
isApiAddingRef.current = false;
|
|
13671
13714
|
}
|
|
13672
|
-
|
|
13673
|
-
|
|
13674
|
-
if (l.id !== targetId) return l;
|
|
13675
|
-
return {
|
|
13676
|
-
...l,
|
|
13677
|
-
featureIds: [...l.featureIds, ...addedIds],
|
|
13678
|
-
...(layerMetadata == null ? void 0 : layerMetadata.traceConfig) && { traceConfig: layerMetadata.traceConfig },
|
|
13679
|
-
...(layerMetadata == null ? void 0 : layerMetadata.heatmapConfig) && { heatmapConfig: layerMetadata.heatmapConfig },
|
|
13680
|
-
...(layerMetadata == null ? void 0 : layerMetadata.visualConfig) && { visualConfig: layerMetadata.visualConfig }
|
|
13681
|
-
};
|
|
13682
|
-
}));
|
|
13683
|
-
} else if (targetLayer) {
|
|
13684
|
-
const targetId = targetLayer.id;
|
|
13715
|
+
setLayers((prev) => prev.map((l) => l.id === targetId ? withLayerMetadata(l, addedIds) : l));
|
|
13716
|
+
} else {
|
|
13685
13717
|
const addedIds = normalizedFeatures.map((f) => String(f.id));
|
|
13686
13718
|
const existing = hiddenFeatures.current.get(targetId) || [];
|
|
13687
13719
|
hiddenFeatures.current.set(targetId, [...existing, ...normalizedFeatures]);
|
|
13688
|
-
setLayers((prev) => prev.map((l) =>
|
|
13689
|
-
if (l.id !== targetId) return l;
|
|
13690
|
-
return {
|
|
13691
|
-
...l,
|
|
13692
|
-
featureIds: [...l.featureIds, ...addedIds],
|
|
13693
|
-
...(layerMetadata == null ? void 0 : layerMetadata.traceConfig) && { traceConfig: layerMetadata.traceConfig },
|
|
13694
|
-
...(layerMetadata == null ? void 0 : layerMetadata.heatmapConfig) && { heatmapConfig: layerMetadata.heatmapConfig },
|
|
13695
|
-
...(layerMetadata == null ? void 0 : layerMetadata.visualConfig) && { visualConfig: layerMetadata.visualConfig }
|
|
13696
|
-
};
|
|
13697
|
-
}));
|
|
13720
|
+
setLayers((prev) => prev.map((l) => l.id === targetId ? withLayerMetadata(l, addedIds) : l));
|
|
13698
13721
|
}
|
|
13699
13722
|
updateFeatureCount();
|
|
13700
13723
|
scheduleTimelineUpdate();
|