@octostar/map-component 0.2.15 → 0.2.16
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.cjs
CHANGED
|
@@ -1092,6 +1092,30 @@ function downloadBlob(blob, filename) {
|
|
|
1092
1092
|
anchor.remove();
|
|
1093
1093
|
setTimeout(() => URL.revokeObjectURL(url), 0);
|
|
1094
1094
|
}
|
|
1095
|
+
function collectLayerFeatures(layer, sources) {
|
|
1096
|
+
const features = [];
|
|
1097
|
+
if (layer.visible) {
|
|
1098
|
+
for (const id of layer.featureIds) {
|
|
1099
|
+
const f = sources.getDrawFeature(id);
|
|
1100
|
+
if (f) features.push(f);
|
|
1101
|
+
}
|
|
1102
|
+
} else {
|
|
1103
|
+
pushAll(features, sources.hiddenFeatures.get(layer.id) ?? []);
|
|
1104
|
+
}
|
|
1105
|
+
const readOnly = sources.readOnlyFeatures.get(layer.id);
|
|
1106
|
+
if (readOnly) pushAll(features, readOnly);
|
|
1107
|
+
return features;
|
|
1108
|
+
}
|
|
1109
|
+
function stripInternalProperties(features, keep) {
|
|
1110
|
+
return features.map((f) => ({
|
|
1111
|
+
...f,
|
|
1112
|
+
properties: Object.fromEntries(
|
|
1113
|
+
Object.entries(f.properties ?? {}).filter(
|
|
1114
|
+
([key]) => !key.startsWith("_") || ((keep == null ? void 0 : keep.has(key)) ?? false)
|
|
1115
|
+
)
|
|
1116
|
+
)
|
|
1117
|
+
}));
|
|
1118
|
+
}
|
|
1095
1119
|
const ToastContext = react.createContext(null);
|
|
1096
1120
|
function useToast() {
|
|
1097
1121
|
const externalToast = react.useContext(ToastContext);
|
|
@@ -7376,6 +7400,7 @@ const CustomSimpleSelect = {
|
|
|
7376
7400
|
startBoxSelect() {
|
|
7377
7401
|
}
|
|
7378
7402
|
};
|
|
7403
|
+
const ENRICHED_EXPORT_KEEP_KEYS = /* @__PURE__ */ new Set(["_layerIndex"]);
|
|
7379
7404
|
function createFlightPath3DLayer(layerId, mapInstance, flightPaths) {
|
|
7380
7405
|
let camera;
|
|
7381
7406
|
let scene;
|
|
@@ -13170,29 +13195,22 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13170
13195
|
}, [measurePoints, measureMode, isMapLoaded]);
|
|
13171
13196
|
const handleSaveLayerGeoJSON = react.useCallback((layerId) => {
|
|
13172
13197
|
const layer = layers.find((l) => l.id === layerId);
|
|
13173
|
-
if (!layer
|
|
13174
|
-
const features =
|
|
13175
|
-
|
|
13176
|
-
|
|
13177
|
-
|
|
13178
|
-
|
|
13179
|
-
|
|
13180
|
-
|
|
13181
|
-
|
|
13182
|
-
pushAll(features, hidden);
|
|
13183
|
-
}
|
|
13198
|
+
if (!layer) return;
|
|
13199
|
+
const features = collectLayerFeatures(layer, {
|
|
13200
|
+
getDrawFeature: (id) => {
|
|
13201
|
+
var _a;
|
|
13202
|
+
return (_a = draw.current) == null ? void 0 : _a.get(id);
|
|
13203
|
+
},
|
|
13204
|
+
hiddenFeatures: hiddenFeatures.current,
|
|
13205
|
+
readOnlyFeatures: readOnlyFeatures.current
|
|
13206
|
+
});
|
|
13184
13207
|
const layerMetadata = {
|
|
13185
13208
|
name: layer.name
|
|
13186
13209
|
};
|
|
13187
13210
|
if (layer.traceConfig) layerMetadata.traceConfig = layer.traceConfig;
|
|
13188
13211
|
if (layer.heatmapConfig) layerMetadata.heatmapConfig = layer.heatmapConfig;
|
|
13189
13212
|
if (layer.visualConfig) layerMetadata.visualConfig = layer.visualConfig;
|
|
13190
|
-
const cleanedFeatures = features
|
|
13191
|
-
...f,
|
|
13192
|
-
properties: Object.fromEntries(
|
|
13193
|
-
Object.entries(f.properties || {}).filter(([key]) => !key.startsWith("_"))
|
|
13194
|
-
)
|
|
13195
|
-
}));
|
|
13213
|
+
const cleanedFeatures = stripInternalProperties(features);
|
|
13196
13214
|
const geojson = {
|
|
13197
13215
|
type: "FeatureCollection",
|
|
13198
13216
|
features: cleanedFeatures,
|
|
@@ -13224,18 +13242,14 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13224
13242
|
var _a;
|
|
13225
13243
|
const isDataViewing = ((_a = layer.metadata) == null ? void 0 : _a.dataViewing) === true;
|
|
13226
13244
|
if (!isDataViewing) {
|
|
13227
|
-
const layerFeatures =
|
|
13228
|
-
|
|
13229
|
-
|
|
13230
|
-
|
|
13231
|
-
|
|
13232
|
-
|
|
13233
|
-
|
|
13234
|
-
|
|
13235
|
-
pushAll(layerFeatures, hidden);
|
|
13236
|
-
}
|
|
13237
|
-
const roFeatures = readOnlyFeatures.current.get(layer.id);
|
|
13238
|
-
if (roFeatures) pushAll(layerFeatures, roFeatures);
|
|
13245
|
+
const layerFeatures = collectLayerFeatures(layer, {
|
|
13246
|
+
getDrawFeature: (id) => {
|
|
13247
|
+
var _a2;
|
|
13248
|
+
return (_a2 = draw.current) == null ? void 0 : _a2.get(id);
|
|
13249
|
+
},
|
|
13250
|
+
hiddenFeatures: hiddenFeatures.current,
|
|
13251
|
+
readOnlyFeatures: readOnlyFeatures.current
|
|
13252
|
+
});
|
|
13239
13253
|
layerFeatures.forEach((f) => {
|
|
13240
13254
|
allFeatures.push({
|
|
13241
13255
|
...f,
|
|
@@ -13246,14 +13260,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13246
13260
|
const { id: _id, featureIds: _fids, hasAltitudeData: _alt, ...persistable } = layer;
|
|
13247
13261
|
layerStates.push({ index: idx, ...persistable });
|
|
13248
13262
|
});
|
|
13249
|
-
const cleanedFeatures = allFeatures
|
|
13250
|
-
...f,
|
|
13251
|
-
properties: Object.fromEntries(
|
|
13252
|
-
Object.entries(f.properties || {}).filter(
|
|
13253
|
-
([key]) => !key.startsWith("_") || key === "_layerIndex"
|
|
13254
|
-
)
|
|
13255
|
-
)
|
|
13256
|
-
}));
|
|
13263
|
+
const cleanedFeatures = stripInternalProperties(allFeatures, ENRICHED_EXPORT_KEEP_KEYS);
|
|
13257
13264
|
let viewport;
|
|
13258
13265
|
if (map.current && isMapLoaded) {
|
|
13259
13266
|
const c = map.current.getCenter();
|
|
@@ -13584,6 +13591,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13584
13591
|
}
|
|
13585
13592
|
}, [ingestProgressStore]);
|
|
13586
13593
|
const loadGeoJSONFile = react.useCallback(async (file, requestedTargetLayerId, createNewLayer) => {
|
|
13594
|
+
var _a;
|
|
13587
13595
|
let result;
|
|
13588
13596
|
try {
|
|
13589
13597
|
result = await ingestWithProgress(file.name, file, {
|
|
@@ -13672,14 +13680,49 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13672
13680
|
return;
|
|
13673
13681
|
}
|
|
13674
13682
|
const currentLayers = layersRef.current;
|
|
13675
|
-
let targetLayer = currentLayers.find((l) => l.id === requestedTargetLayerId
|
|
13683
|
+
let targetLayer = currentLayers.find((l) => l.id === requestedTargetLayerId);
|
|
13684
|
+
if (((_a = targetLayer == null ? void 0 : targetLayer.metadata) == null ? void 0 : _a.dataViewing) === true) {
|
|
13685
|
+
toast({
|
|
13686
|
+
title: "Can't load into a data-viewing layer",
|
|
13687
|
+
description: "Its features are fetched from data and aren't saved with the map. Load the file into another layer.",
|
|
13688
|
+
variant: "destructive"
|
|
13689
|
+
});
|
|
13690
|
+
return;
|
|
13691
|
+
}
|
|
13676
13692
|
if (!targetLayer) {
|
|
13677
13693
|
targetLayer = currentLayers.find((l) => l.visible && !l.readOnly);
|
|
13678
13694
|
}
|
|
13679
13695
|
if (!targetLayer) {
|
|
13680
13696
|
targetLayer = currentLayers.find((l) => !l.readOnly);
|
|
13681
13697
|
}
|
|
13682
|
-
if (targetLayer
|
|
13698
|
+
if (!targetLayer) {
|
|
13699
|
+
toast({
|
|
13700
|
+
title: "No layer to load into",
|
|
13701
|
+
description: "Create a layer first, then load the file again.",
|
|
13702
|
+
variant: "destructive"
|
|
13703
|
+
});
|
|
13704
|
+
return;
|
|
13705
|
+
}
|
|
13706
|
+
const targetId = targetLayer.id;
|
|
13707
|
+
const withLayerMetadata = (l, addedIds) => ({
|
|
13708
|
+
...l,
|
|
13709
|
+
featureIds: [...l.featureIds, ...addedIds],
|
|
13710
|
+
...(layerMetadata == null ? void 0 : layerMetadata.traceConfig) && { traceConfig: layerMetadata.traceConfig },
|
|
13711
|
+
...(layerMetadata == null ? void 0 : layerMetadata.heatmapConfig) && { heatmapConfig: layerMetadata.heatmapConfig },
|
|
13712
|
+
...(layerMetadata == null ? void 0 : layerMetadata.visualConfig) && { visualConfig: layerMetadata.visualConfig }
|
|
13713
|
+
});
|
|
13714
|
+
if (targetLayer.readOnly) {
|
|
13715
|
+
const addedFeatures = normalizedFeatures.map((f) => ({ ...f, id: crypto.randomUUID() }));
|
|
13716
|
+
const addedIds = addedFeatures.map((f) => String(f.id));
|
|
13717
|
+
const existing = readOnlyFeatures.current.get(targetId) || [];
|
|
13718
|
+
readOnlyFeatures.current.set(targetId, [...existing, ...addedFeatures]);
|
|
13719
|
+
const cached = layerTemporalCacheRef.current.get(targetId);
|
|
13720
|
+
layerTemporalCacheRef.current.set(targetId, {
|
|
13721
|
+
featureCount: ((cached == null ? void 0 : cached.featureCount) ?? existing.length) + addedFeatures.length,
|
|
13722
|
+
hasTemporal: ((cached == null ? void 0 : cached.hasTemporal) ?? false) || fileHasTemporal
|
|
13723
|
+
});
|
|
13724
|
+
setLayers((prev) => prev.map((l) => l.id === targetId ? withLayerMetadata(l, addedIds) : l));
|
|
13725
|
+
} else if (targetLayer.visible) {
|
|
13683
13726
|
const addedIds = [];
|
|
13684
13727
|
isApiAddingRef.current = true;
|
|
13685
13728
|
try {
|
|
@@ -13690,32 +13733,12 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13690
13733
|
} finally {
|
|
13691
13734
|
isApiAddingRef.current = false;
|
|
13692
13735
|
}
|
|
13693
|
-
|
|
13694
|
-
|
|
13695
|
-
if (l.id !== targetId) return l;
|
|
13696
|
-
return {
|
|
13697
|
-
...l,
|
|
13698
|
-
featureIds: [...l.featureIds, ...addedIds],
|
|
13699
|
-
...(layerMetadata == null ? void 0 : layerMetadata.traceConfig) && { traceConfig: layerMetadata.traceConfig },
|
|
13700
|
-
...(layerMetadata == null ? void 0 : layerMetadata.heatmapConfig) && { heatmapConfig: layerMetadata.heatmapConfig },
|
|
13701
|
-
...(layerMetadata == null ? void 0 : layerMetadata.visualConfig) && { visualConfig: layerMetadata.visualConfig }
|
|
13702
|
-
};
|
|
13703
|
-
}));
|
|
13704
|
-
} else if (targetLayer) {
|
|
13705
|
-
const targetId = targetLayer.id;
|
|
13736
|
+
setLayers((prev) => prev.map((l) => l.id === targetId ? withLayerMetadata(l, addedIds) : l));
|
|
13737
|
+
} else {
|
|
13706
13738
|
const addedIds = normalizedFeatures.map((f) => String(f.id));
|
|
13707
13739
|
const existing = hiddenFeatures.current.get(targetId) || [];
|
|
13708
13740
|
hiddenFeatures.current.set(targetId, [...existing, ...normalizedFeatures]);
|
|
13709
|
-
setLayers((prev) => prev.map((l) =>
|
|
13710
|
-
if (l.id !== targetId) return l;
|
|
13711
|
-
return {
|
|
13712
|
-
...l,
|
|
13713
|
-
featureIds: [...l.featureIds, ...addedIds],
|
|
13714
|
-
...(layerMetadata == null ? void 0 : layerMetadata.traceConfig) && { traceConfig: layerMetadata.traceConfig },
|
|
13715
|
-
...(layerMetadata == null ? void 0 : layerMetadata.heatmapConfig) && { heatmapConfig: layerMetadata.heatmapConfig },
|
|
13716
|
-
...(layerMetadata == null ? void 0 : layerMetadata.visualConfig) && { visualConfig: layerMetadata.visualConfig }
|
|
13717
|
-
};
|
|
13718
|
-
}));
|
|
13741
|
+
setLayers((prev) => prev.map((l) => l.id === targetId ? withLayerMetadata(l, addedIds) : l));
|
|
13719
13742
|
}
|
|
13720
13743
|
updateFeatureCount();
|
|
13721
13744
|
scheduleTimelineUpdate();
|