@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 CHANGED
@@ -5552,6 +5552,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
5552
5552
  onWorkspaceSave,
5553
5553
  getAdditionalSaveState,
5554
5554
  onMapStateLoaded,
5555
+ interceptGeoJSONFileLoad,
5555
5556
  entityCardProvider,
5556
5557
  typePickerProvider,
5557
5558
  contextMenuProvider,
@@ -7899,8 +7900,49 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
7899
7900
  });
7900
7901
  },
7901
7902
  addFeatures: (layerId, features) => {
7903
+ var _a;
7902
7904
  const layer = layersRef.current.find((l) => l.id === layerId);
7903
- if (!layer || !draw.current || !isMapLoadedRef.current) return [];
7905
+ if (!layer || !isMapLoadedRef.current) return [];
7906
+ if (layer.readOnly) {
7907
+ const existing = readOnlyFeatures.current.get(layerId) || [];
7908
+ let layerHasTemporal = ((_a = layerTemporalCacheRef.current.get(layerId)) == null ? void 0 : _a.hasTemporal) ?? false;
7909
+ const newFeaturesWithIds = features.map((f) => {
7910
+ const id = f.id ? String(f.id) : crypto.randomUUID();
7911
+ const props = f.properties || {};
7912
+ if (!hasAnyTemporalValue(props)) {
7913
+ return { ...f, id };
7914
+ }
7915
+ const { startDate, endDate } = normalizeTemporalProperties(props);
7916
+ if (startDate || endDate) layerHasTemporal = true;
7917
+ return {
7918
+ ...f,
7919
+ id,
7920
+ properties: {
7921
+ ...props,
7922
+ startDate: (startDate == null ? void 0 : startDate.toISOString()) || null,
7923
+ endDate: (endDate == null ? void 0 : endDate.toISOString()) || null
7924
+ }
7925
+ };
7926
+ });
7927
+ const combined = [...existing, ...newFeaturesWithIds];
7928
+ readOnlyFeatures.current.set(layerId, combined);
7929
+ layerTemporalCacheRef.current.set(layerId, { featureCount: combined.length, hasTemporal: layerHasTemporal });
7930
+ const addedIds2 = newFeaturesWithIds.map((f) => String(f.id));
7931
+ const updatedLayers2 = layersRef.current.map(
7932
+ (l) => l.id === layerId ? { ...l, featureIds: [...l.featureIds, ...addedIds2] } : l
7933
+ );
7934
+ layersRef.current = updatedLayers2;
7935
+ setLayers(updatedLayers2);
7936
+ updateFeatureCount();
7937
+ if (layerHasTemporal) {
7938
+ scheduleTimelineUpdate();
7939
+ }
7940
+ requestAnimationFrame(() => {
7941
+ syncRef.current();
7942
+ });
7943
+ return addedIds2;
7944
+ }
7945
+ if (!draw.current) return [];
7904
7946
  const addedIds = [];
7905
7947
  isApiAddingRef.current = true;
7906
7948
  try {
@@ -10954,7 +10996,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
10954
10996
  const handleFileChange = react.useCallback((e) => {
10955
10997
  var _a;
10956
10998
  const file = (_a = e.target.files) == null ? void 0 : _a[0];
10957
- if (!file || !draw.current) return;
10999
+ if (!file) return;
10958
11000
  const requestedTargetLayerId = e.target.dataset.targetLayer || activeEditingLayerId;
10959
11001
  const createNewLayer = e.target.dataset.createNewLayer === "true";
10960
11002
  delete e.target.dataset.createNewLayer;
@@ -10975,9 +11017,14 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
10975
11017
  return;
10976
11018
  }
10977
11019
  if (rawGeojson["octostar:map"]) {
11020
+ if (interceptGeoJSONFileLoad != null && interceptGeoJSONFileLoad({ kind: "enriched", data: rawGeojson, file }) === true) {
11021
+ return;
11022
+ }
11023
+ if (!draw.current) return;
10978
11024
  restoreEnrichedGeoJSON(rawGeojson);
10979
11025
  return;
10980
11026
  }
11027
+ if (!draw.current) return;
10981
11028
  const { features: geojson, reprojected, sourceCRS } = detectAndReprojectGeoJSON(rawGeojson);
10982
11029
  saveStateForUndo();
10983
11030
  const layerMetadata = (_b = rawGeojson.properties) == null ? void 0 : _b.layerMetadata;
@@ -10997,6 +11044,15 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
10997
11044
  };
10998
11045
  });
10999
11046
  if (createNewLayer) {
11047
+ if (interceptGeoJSONFileLoad != null && interceptGeoJSONFileLoad({
11048
+ kind: "newLayer",
11049
+ data: { type: "FeatureCollection", features: normalizedFeatures },
11050
+ file,
11051
+ reprojected,
11052
+ sourceCRS: sourceCRS ?? void 0
11053
+ }) === true) {
11054
+ return;
11055
+ }
11000
11056
  const fileName = file.name.replace(/\.geojson$|\.json$/i, "");
11001
11057
  const layerId = `layer-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
11002
11058
  const newLayer = {
@@ -11110,11 +11166,14 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11110
11166
  };
11111
11167
  reader.readAsText(file);
11112
11168
  e.target.value = "";
11113
- }, [layers, activeEditingLayerId, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, restoreEnrichedGeoJSON, toast]);
11169
+ }, [layers, activeEditingLayerId, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, restoreEnrichedGeoJSON, toast, interceptGeoJSONFileLoad]);
11114
11170
  const handleDropGeoJSON = react.useCallback((name, data) => {
11115
11171
  var _a;
11116
11172
  if (!map.current) return;
11117
11173
  if (data["octostar:map"]) {
11174
+ if (interceptGeoJSONFileLoad != null && interceptGeoJSONFileLoad({ kind: "enriched", data, sourceName: name }) === true) {
11175
+ return;
11176
+ }
11118
11177
  restoreEnrichedGeoJSON(data);
11119
11178
  return;
11120
11179
  }
@@ -11185,7 +11244,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11185
11244
  title: "Layer added",
11186
11245
  description: `Created "${newLayer.name}" with ${addedIds.length} features${reprojectMsg} (high-performance)`
11187
11246
  });
11188
- }, [saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, restoreEnrichedGeoJSON, toast]);
11247
+ }, [saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, restoreEnrichedGeoJSON, toast, interceptGeoJSONFileLoad]);
11189
11248
  const handleTimelineFilterChange = react.useCallback((visibleIds, hiddenIds, untimedIds) => {
11190
11249
  if (!draw.current || !map.current) return;
11191
11250
  timelineVisibleIdsRef.current = /* @__PURE__ */ new Set([...visibleIds, ...untimedIds]);
@@ -11430,18 +11489,9 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11430
11489
  ];
11431
11490
  });
11432
11491
  }
11433
- const rawMaxZoom = typeof mapInstance.getMaxZoom === "function" ? mapInstance.getMaxZoom() : 24;
11434
- const mapStyleMaxZoom = Number.isFinite(rawMaxZoom) && rawMaxZoom > 0 ? rawMaxZoom : 24;
11435
- const CLUSTER_ZOOM_CAP = 24;
11436
- const cappedZoom = Math.min(mapStyleMaxZoom, CLUSTER_ZOOM_CAP);
11437
- let clusterMaxZoom = Math.max(1, Math.floor(cappedZoom) - 1);
11438
- let geojsonSourceMaxZoom = Math.min(
11439
- CLUSTER_ZOOM_CAP,
11440
- Math.max(clusterMaxZoom + 1, Math.ceil(cappedZoom))
11441
- );
11442
- if (clusterMaxZoom >= geojsonSourceMaxZoom) {
11443
- clusterMaxZoom = Math.max(1, geojsonSourceMaxZoom - 1);
11444
- }
11492
+ const mapStyleMaxZoom = typeof mapInstance.getMaxZoom === "function" ? mapInstance.getMaxZoom() : 24;
11493
+ const clusterMaxZoom = Math.min(24, Math.max(1, mapStyleMaxZoom - 1));
11494
+ const geojsonSourceMaxZoom = Math.min(24, Math.max(clusterMaxZoom + 1, mapStyleMaxZoom));
11445
11495
  mapInstance.addSource(sourceId, {
11446
11496
  type: "geojson",
11447
11497
  data: { type: "FeatureCollection", features: pointFeatures },