@octostar/map-component 0.1.25 → 0.1.27
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 +66 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +66 -16
- package/dist/index.mjs.map +1 -1
- package/dist/types/components/map-editor-canvas.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/map-editor-api.d.ts +21 -0
- package/dist/types/lib/map-editor-api.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -5531,6 +5531,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
5531
5531
|
onWorkspaceSave,
|
|
5532
5532
|
getAdditionalSaveState,
|
|
5533
5533
|
onMapStateLoaded,
|
|
5534
|
+
interceptGeoJSONFileLoad,
|
|
5534
5535
|
entityCardProvider,
|
|
5535
5536
|
typePickerProvider,
|
|
5536
5537
|
contextMenuProvider,
|
|
@@ -7878,8 +7879,49 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
7878
7879
|
});
|
|
7879
7880
|
},
|
|
7880
7881
|
addFeatures: (layerId, features) => {
|
|
7882
|
+
var _a;
|
|
7881
7883
|
const layer = layersRef.current.find((l) => l.id === layerId);
|
|
7882
|
-
if (!layer || !
|
|
7884
|
+
if (!layer || !isMapLoadedRef.current) return [];
|
|
7885
|
+
if (layer.readOnly) {
|
|
7886
|
+
const existing = readOnlyFeatures.current.get(layerId) || [];
|
|
7887
|
+
let layerHasTemporal = ((_a = layerTemporalCacheRef.current.get(layerId)) == null ? void 0 : _a.hasTemporal) ?? false;
|
|
7888
|
+
const newFeaturesWithIds = features.map((f) => {
|
|
7889
|
+
const id = f.id ? String(f.id) : crypto.randomUUID();
|
|
7890
|
+
const props = f.properties || {};
|
|
7891
|
+
if (!hasAnyTemporalValue(props)) {
|
|
7892
|
+
return { ...f, id };
|
|
7893
|
+
}
|
|
7894
|
+
const { startDate, endDate } = normalizeTemporalProperties(props);
|
|
7895
|
+
if (startDate || endDate) layerHasTemporal = true;
|
|
7896
|
+
return {
|
|
7897
|
+
...f,
|
|
7898
|
+
id,
|
|
7899
|
+
properties: {
|
|
7900
|
+
...props,
|
|
7901
|
+
startDate: (startDate == null ? void 0 : startDate.toISOString()) || null,
|
|
7902
|
+
endDate: (endDate == null ? void 0 : endDate.toISOString()) || null
|
|
7903
|
+
}
|
|
7904
|
+
};
|
|
7905
|
+
});
|
|
7906
|
+
const combined = [...existing, ...newFeaturesWithIds];
|
|
7907
|
+
readOnlyFeatures.current.set(layerId, combined);
|
|
7908
|
+
layerTemporalCacheRef.current.set(layerId, { featureCount: combined.length, hasTemporal: layerHasTemporal });
|
|
7909
|
+
const addedIds2 = newFeaturesWithIds.map((f) => String(f.id));
|
|
7910
|
+
const updatedLayers2 = layersRef.current.map(
|
|
7911
|
+
(l) => l.id === layerId ? { ...l, featureIds: [...l.featureIds, ...addedIds2] } : l
|
|
7912
|
+
);
|
|
7913
|
+
layersRef.current = updatedLayers2;
|
|
7914
|
+
setLayers(updatedLayers2);
|
|
7915
|
+
updateFeatureCount();
|
|
7916
|
+
if (layerHasTemporal) {
|
|
7917
|
+
scheduleTimelineUpdate();
|
|
7918
|
+
}
|
|
7919
|
+
requestAnimationFrame(() => {
|
|
7920
|
+
syncRef.current();
|
|
7921
|
+
});
|
|
7922
|
+
return addedIds2;
|
|
7923
|
+
}
|
|
7924
|
+
if (!draw.current) return [];
|
|
7883
7925
|
const addedIds = [];
|
|
7884
7926
|
isApiAddingRef.current = true;
|
|
7885
7927
|
try {
|
|
@@ -10933,7 +10975,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
10933
10975
|
const handleFileChange = useCallback((e) => {
|
|
10934
10976
|
var _a;
|
|
10935
10977
|
const file = (_a = e.target.files) == null ? void 0 : _a[0];
|
|
10936
|
-
if (!file
|
|
10978
|
+
if (!file) return;
|
|
10937
10979
|
const requestedTargetLayerId = e.target.dataset.targetLayer || activeEditingLayerId;
|
|
10938
10980
|
const createNewLayer = e.target.dataset.createNewLayer === "true";
|
|
10939
10981
|
delete e.target.dataset.createNewLayer;
|
|
@@ -10954,9 +10996,14 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
10954
10996
|
return;
|
|
10955
10997
|
}
|
|
10956
10998
|
if (rawGeojson["octostar:map"]) {
|
|
10999
|
+
if (interceptGeoJSONFileLoad != null && interceptGeoJSONFileLoad({ kind: "enriched", data: rawGeojson, file }) === true) {
|
|
11000
|
+
return;
|
|
11001
|
+
}
|
|
11002
|
+
if (!draw.current) return;
|
|
10957
11003
|
restoreEnrichedGeoJSON(rawGeojson);
|
|
10958
11004
|
return;
|
|
10959
11005
|
}
|
|
11006
|
+
if (!draw.current) return;
|
|
10960
11007
|
const { features: geojson, reprojected, sourceCRS } = detectAndReprojectGeoJSON(rawGeojson);
|
|
10961
11008
|
saveStateForUndo();
|
|
10962
11009
|
const layerMetadata = (_b = rawGeojson.properties) == null ? void 0 : _b.layerMetadata;
|
|
@@ -10976,6 +11023,15 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
10976
11023
|
};
|
|
10977
11024
|
});
|
|
10978
11025
|
if (createNewLayer) {
|
|
11026
|
+
if (interceptGeoJSONFileLoad != null && interceptGeoJSONFileLoad({
|
|
11027
|
+
kind: "newLayer",
|
|
11028
|
+
data: { type: "FeatureCollection", features: normalizedFeatures },
|
|
11029
|
+
file,
|
|
11030
|
+
reprojected,
|
|
11031
|
+
sourceCRS: sourceCRS ?? void 0
|
|
11032
|
+
}) === true) {
|
|
11033
|
+
return;
|
|
11034
|
+
}
|
|
10979
11035
|
const fileName = file.name.replace(/\.geojson$|\.json$/i, "");
|
|
10980
11036
|
const layerId = `layer-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
10981
11037
|
const newLayer = {
|
|
@@ -11089,11 +11145,14 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
11089
11145
|
};
|
|
11090
11146
|
reader.readAsText(file);
|
|
11091
11147
|
e.target.value = "";
|
|
11092
|
-
}, [layers, activeEditingLayerId, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, restoreEnrichedGeoJSON, toast]);
|
|
11148
|
+
}, [layers, activeEditingLayerId, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, restoreEnrichedGeoJSON, toast, interceptGeoJSONFileLoad]);
|
|
11093
11149
|
const handleDropGeoJSON = useCallback((name, data) => {
|
|
11094
11150
|
var _a;
|
|
11095
11151
|
if (!map.current) return;
|
|
11096
11152
|
if (data["octostar:map"]) {
|
|
11153
|
+
if (interceptGeoJSONFileLoad != null && interceptGeoJSONFileLoad({ kind: "enriched", data, sourceName: name }) === true) {
|
|
11154
|
+
return;
|
|
11155
|
+
}
|
|
11097
11156
|
restoreEnrichedGeoJSON(data);
|
|
11098
11157
|
return;
|
|
11099
11158
|
}
|
|
@@ -11164,7 +11223,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
11164
11223
|
title: "Layer added",
|
|
11165
11224
|
description: `Created "${newLayer.name}" with ${addedIds.length} features${reprojectMsg} (high-performance)`
|
|
11166
11225
|
});
|
|
11167
|
-
}, [saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, restoreEnrichedGeoJSON, toast]);
|
|
11226
|
+
}, [saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, restoreEnrichedGeoJSON, toast, interceptGeoJSONFileLoad]);
|
|
11168
11227
|
const handleTimelineFilterChange = useCallback((visibleIds, hiddenIds, untimedIds) => {
|
|
11169
11228
|
if (!draw.current || !map.current) return;
|
|
11170
11229
|
timelineVisibleIdsRef.current = /* @__PURE__ */ new Set([...visibleIds, ...untimedIds]);
|
|
@@ -11409,18 +11468,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
11409
11468
|
];
|
|
11410
11469
|
});
|
|
11411
11470
|
}
|
|
11412
|
-
const
|
|
11413
|
-
const
|
|
11414
|
-
const
|
|
11415
|
-
const cappedZoom = Math.min(mapStyleMaxZoom, CLUSTER_ZOOM_CAP);
|
|
11416
|
-
let clusterMaxZoom = Math.max(1, Math.floor(cappedZoom) - 1);
|
|
11417
|
-
let geojsonSourceMaxZoom = Math.min(
|
|
11418
|
-
CLUSTER_ZOOM_CAP,
|
|
11419
|
-
Math.max(clusterMaxZoom + 1, Math.ceil(cappedZoom))
|
|
11420
|
-
);
|
|
11421
|
-
if (clusterMaxZoom >= geojsonSourceMaxZoom) {
|
|
11422
|
-
clusterMaxZoom = Math.max(1, geojsonSourceMaxZoom - 1);
|
|
11423
|
-
}
|
|
11471
|
+
const mapStyleMaxZoom = typeof mapInstance.getMaxZoom === "function" ? mapInstance.getMaxZoom() : 24;
|
|
11472
|
+
const clusterMaxZoom = Math.min(24, Math.max(1, mapStyleMaxZoom - 1));
|
|
11473
|
+
const geojsonSourceMaxZoom = Math.min(24, Math.max(clusterMaxZoom + 1, mapStyleMaxZoom));
|
|
11424
11474
|
mapInstance.addSource(sourceId, {
|
|
11425
11475
|
type: "geojson",
|
|
11426
11476
|
data: { type: "FeatureCollection", features: pointFeatures },
|