@octostar/map-component 0.1.33 → 0.1.35

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
@@ -494,7 +494,9 @@ function DrawingToolbar({
494
494
  expandSelectionTools = false,
495
495
  showFilterTool = false,
496
496
  getAllFeatures,
497
- onFlyToFeature
497
+ onFlyToFeature,
498
+ canDeleteSelected = true,
499
+ showUndoRedo = false
498
500
  }) {
499
501
  const { toast } = useToast();
500
502
  const [goToLat, setGoToLat] = react.useState("");
@@ -795,30 +797,32 @@ function DrawingToolbar({
795
797
  });
796
798
  }
797
799
  items.push({ type: "divider" });
798
- items.push({
799
- key: "undo",
800
- label: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between w-full", children: [
801
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex items-center gap-2", children: [
802
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Undo2, { className: "w-4 h-4" }),
803
- "Undo"
800
+ if (showUndoRedo) {
801
+ items.push({
802
+ key: "undo",
803
+ label: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between w-full", children: [
804
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex items-center gap-2", children: [
805
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Undo2, { className: "w-4 h-4" }),
806
+ "Undo"
807
+ ] }),
808
+ showShortcutHints && /* @__PURE__ */ jsxRuntime.jsx("kbd", { className: "px-1.5 py-0.5 text-xs font-mono bg-black/10 dark:bg-white/10 rounded", children: "Ctrl+Z" })
804
809
  ] }),
805
- showShortcutHints && /* @__PURE__ */ jsxRuntime.jsx("kbd", { className: "px-1.5 py-0.5 text-xs font-mono bg-black/10 dark:bg-white/10 rounded", children: "Ctrl+Z" })
806
- ] }),
807
- disabled: disabled || !canUndo,
808
- onClick: onUndo
809
- });
810
- items.push({
811
- key: "redo",
812
- label: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between w-full", children: [
813
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex items-center gap-2", children: [
814
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Redo2, { className: "w-4 h-4" }),
815
- "Redo"
810
+ disabled: disabled || !canUndo,
811
+ onClick: onUndo
812
+ });
813
+ items.push({
814
+ key: "redo",
815
+ label: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between w-full", children: [
816
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex items-center gap-2", children: [
817
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Redo2, { className: "w-4 h-4" }),
818
+ "Redo"
819
+ ] }),
820
+ showShortcutHints && /* @__PURE__ */ jsxRuntime.jsx("kbd", { className: "px-1.5 py-0.5 text-xs font-mono bg-black/10 dark:bg-white/10 rounded", children: "Ctrl+Y" })
816
821
  ] }),
817
- showShortcutHints && /* @__PURE__ */ jsxRuntime.jsx("kbd", { className: "px-1.5 py-0.5 text-xs font-mono bg-black/10 dark:bg-white/10 rounded", children: "Ctrl+Y" })
818
- ] }),
819
- disabled: disabled || !canRedo,
820
- onClick: onRedo
821
- });
822
+ disabled: disabled || !canRedo,
823
+ onClick: onRedo
824
+ });
825
+ }
822
826
  items.push({ type: "divider" });
823
827
  items.push({
824
828
  key: "delete",
@@ -1149,7 +1153,20 @@ function DrawingToolbar({
1149
1153
  showShortcutHint: showShortcutHints
1150
1154
  }
1151
1155
  ),
1152
- !hiddenDrawingTools.includes("polygon") && /* @__PURE__ */ jsxRuntime.jsx(
1156
+ !hiddenDrawingTools.includes("polygon") && hiddenDrawingTools.includes("rectangle") && /* @__PURE__ */ jsxRuntime.jsx(
1157
+ ToolButton,
1158
+ {
1159
+ mode: "draw_polygon",
1160
+ activeMode,
1161
+ onModeChange,
1162
+ icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Pentagon, { className: "w-5 h-5" }),
1163
+ label: "Draw Polygon",
1164
+ shortcut: "G",
1165
+ disabled: drawingDisabled,
1166
+ showShortcutHint: showShortcutHints
1167
+ }
1168
+ ),
1169
+ !hiddenDrawingTools.includes("polygon") && !hiddenDrawingTools.includes("rectangle") && /* @__PURE__ */ jsxRuntime.jsx(
1153
1170
  antd.Dropdown,
1154
1171
  {
1155
1172
  menu: {
@@ -1247,55 +1264,57 @@ function DrawingToolbar({
1247
1264
  showShortcutHint: showShortcutHints
1248
1265
  }
1249
1266
  ),
1250
- /* @__PURE__ */ jsxRuntime.jsx(antd.Divider, { className: "!my-0 !min-w-0" }),
1251
- /* @__PURE__ */ jsxRuntime.jsx(
1252
- antd.Tooltip,
1253
- {
1254
- title: showShortcutHints ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex items-center gap-2", children: [
1255
- "Undo",
1256
- /* @__PURE__ */ jsxRuntime.jsx("kbd", { className: "px-1.5 py-0.5 text-xs font-mono bg-black/20 rounded", children: "Ctrl+Z" })
1257
- ] }) : "Undo",
1258
- placement: "right",
1259
- children: /* @__PURE__ */ jsxRuntime.jsx(
1260
- antd.Button,
1261
- {
1262
- type: "text",
1263
- onClick: onUndo,
1264
- disabled: disabled || !canUndo,
1265
- "aria-label": "Undo",
1266
- "data-testid": "button-undo",
1267
- className: "flex items-center justify-center !w-9 !h-9 !min-w-0 !p-0",
1268
- icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Undo2, { className: "w-5 h-5" })
1269
- }
1270
- )
1271
- }
1272
- ),
1273
- /* @__PURE__ */ jsxRuntime.jsx(
1274
- antd.Tooltip,
1275
- {
1276
- title: showShortcutHints ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex items-center gap-2", children: [
1277
- "Redo",
1278
- /* @__PURE__ */ jsxRuntime.jsx("kbd", { className: "px-1.5 py-0.5 text-xs font-mono bg-black/20 rounded", children: "Ctrl+Y" })
1279
- ] }) : "Redo",
1280
- placement: "right",
1281
- children: /* @__PURE__ */ jsxRuntime.jsx(
1282
- antd.Button,
1283
- {
1284
- type: "text",
1285
- onClick: onRedo,
1286
- disabled: disabled || !canRedo,
1287
- "aria-label": "Redo",
1288
- "data-testid": "button-redo",
1289
- className: "flex items-center justify-center !w-9 !h-9 !min-w-0 !p-0",
1290
- icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Redo2, { className: "w-5 h-5" })
1291
- }
1292
- )
1293
- }
1294
- )
1267
+ showUndoRedo && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1268
+ /* @__PURE__ */ jsxRuntime.jsx(antd.Divider, { className: "!my-0 !min-w-0" }),
1269
+ /* @__PURE__ */ jsxRuntime.jsx(
1270
+ antd.Tooltip,
1271
+ {
1272
+ title: showShortcutHints ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex items-center gap-2", children: [
1273
+ "Undo",
1274
+ /* @__PURE__ */ jsxRuntime.jsx("kbd", { className: "px-1.5 py-0.5 text-xs font-mono bg-black/20 rounded", children: "Ctrl+Z" })
1275
+ ] }) : "Undo",
1276
+ placement: "right",
1277
+ children: /* @__PURE__ */ jsxRuntime.jsx(
1278
+ antd.Button,
1279
+ {
1280
+ type: "text",
1281
+ onClick: onUndo,
1282
+ disabled: disabled || !canUndo,
1283
+ "aria-label": "Undo",
1284
+ "data-testid": "button-undo",
1285
+ className: "flex items-center justify-center !w-9 !h-9 !min-w-0 !p-0",
1286
+ icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Undo2, { className: "w-5 h-5" })
1287
+ }
1288
+ )
1289
+ }
1290
+ ),
1291
+ /* @__PURE__ */ jsxRuntime.jsx(
1292
+ antd.Tooltip,
1293
+ {
1294
+ title: showShortcutHints ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex items-center gap-2", children: [
1295
+ "Redo",
1296
+ /* @__PURE__ */ jsxRuntime.jsx("kbd", { className: "px-1.5 py-0.5 text-xs font-mono bg-black/20 rounded", children: "Ctrl+Y" })
1297
+ ] }) : "Redo",
1298
+ placement: "right",
1299
+ children: /* @__PURE__ */ jsxRuntime.jsx(
1300
+ antd.Button,
1301
+ {
1302
+ type: "text",
1303
+ onClick: onRedo,
1304
+ disabled: disabled || !canRedo,
1305
+ "aria-label": "Redo",
1306
+ "data-testid": "button-redo",
1307
+ className: "flex items-center justify-center !w-9 !h-9 !min-w-0 !p-0",
1308
+ icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Redo2, { className: "w-5 h-5" })
1309
+ }
1310
+ )
1311
+ }
1312
+ )
1313
+ ] })
1295
1314
  ] }),
1296
1315
  compactOverflowItems
1297
1316
  ] }),
1298
- selectedCount > 0 && /* @__PURE__ */ jsxRuntime.jsx(
1317
+ selectedCount > 0 && canDeleteSelected && /* @__PURE__ */ jsxRuntime.jsx(
1299
1318
  antd.Tooltip,
1300
1319
  {
1301
1320
  title: showShortcutHints ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex items-center gap-2", children: [
@@ -5789,6 +5808,19 @@ const EXTERNAL_STYLE_URLS = {
5789
5808
  streets: "https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json",
5790
5809
  dark: "https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json"
5791
5810
  };
5811
+ function computeUndoRedoEvent(fromState, toState) {
5812
+ const fromIds = new Set(fromState.features.map((f) => f.id));
5813
+ const toIds = new Set(toState.features.map((f) => f.id));
5814
+ const restoredFeatures = toState.features.filter((f) => !fromIds.has(f.id)).map((f) => {
5815
+ var _a;
5816
+ return {
5817
+ feature: f,
5818
+ layerId: ((_a = toState.layers.find((l) => l.featureIds.includes(f.id))) == null ? void 0 : _a.id) ?? null
5819
+ };
5820
+ });
5821
+ const removedFeatureIds = fromState.features.filter((f) => !toIds.has(f.id)).map((f) => f.id);
5822
+ return { restoredFeatures, removedFeatureIds };
5823
+ }
5792
5824
  const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
5793
5825
  className,
5794
5826
  enableDrawing = true,
@@ -5816,10 +5848,13 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
5816
5848
  onFeatureCreate,
5817
5849
  onFeatureUpdate,
5818
5850
  onFeatureDelete,
5851
+ onUndo,
5852
+ onRedo,
5819
5853
  onLayerChange,
5820
5854
  onActiveEditingLayerChange,
5821
5855
  onTimelineChange,
5822
5856
  onMapReady,
5857
+ onMapLoad,
5823
5858
  onViewportChange,
5824
5859
  showClearFilter = false,
5825
5860
  onClearFilter,
@@ -5930,6 +5965,8 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
5930
5965
  const [rectangleDrawCorner, setRectangleDrawCorner] = react.useState(null);
5931
5966
  const [rectangleDrawPreview, setRectangleDrawPreview] = react.useState(null);
5932
5967
  const isDrawingRectangle = react.useRef(false);
5968
+ const rectangleCornerPointRef = react.useRef(null);
5969
+ const justCreatedRectangleRef = react.useRef(false);
5933
5970
  const [autoLabelConfig, setAutoLabelConfig] = react.useState({ enabled: true, threshold: 220 });
5934
5971
  const [visibleFeatureCount, setVisibleFeatureCount] = react.useState(Infinity);
5935
5972
  const lastLabelVisibility = react.useRef(false);
@@ -6051,6 +6088,27 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
6051
6088
  }
6052
6089
  return null;
6053
6090
  }, []);
6091
+ const canDeleteSelected = react.useMemo(() => {
6092
+ if (selectedFeatureIds.length === 0) return false;
6093
+ return selectedFeatureIds.some((id) => {
6094
+ var _a;
6095
+ const feature = getFeatureById(id);
6096
+ if (!feature) return false;
6097
+ const geom = feature.geometry.type;
6098
+ const kind = (_a = feature.properties) == null ? void 0 : _a.kind;
6099
+ const isArrow = kind === "arrow" || arrowFeatureIdsRef.current.has(id);
6100
+ if (geom === "Point") {
6101
+ return kind === "text" ? !hiddenDrawingTools.includes("text") : !hiddenDrawingTools.includes("point");
6102
+ }
6103
+ if (geom === "LineString" || geom === "MultiLineString") {
6104
+ return isArrow ? !hiddenDrawingTools.includes("arrow") : !hiddenDrawingTools.includes("line");
6105
+ }
6106
+ if (geom === "Polygon" || geom === "MultiPolygon") {
6107
+ return kind === "circle" ? !hiddenDrawingTools.includes("circle") : !hiddenDrawingTools.includes("polygon");
6108
+ }
6109
+ return true;
6110
+ });
6111
+ }, [selectedFeatureIds, hiddenDrawingTools, getFeatureById]);
6054
6112
  const applySelectionState = react.useCallback((nextIds, options) => {
6055
6113
  if (!isMapLoaded || !draw.current) {
6056
6114
  setSelectedFeatureIds(nextIds);
@@ -6095,12 +6153,12 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
6095
6153
  if (!draw.current) return;
6096
6154
  const currentState = {
6097
6155
  features: draw.current.getAll().features,
6098
- layers: JSON.parse(JSON.stringify(layers)),
6156
+ layers: JSON.parse(JSON.stringify(layersRef.current)),
6099
6157
  selectedIds: [...selectedFeatureIds]
6100
6158
  };
6101
6159
  setUndoStack((prev) => [...prev.slice(-49), currentState]);
6102
6160
  setRedoStack([]);
6103
- }, [layers, selectedFeatureIds]);
6161
+ }, [selectedFeatureIds]);
6104
6162
  const updateFeatureCount = react.useCallback(() => {
6105
6163
  const drawFeatureCount = draw.current ? draw.current.getAll().features.length : 0;
6106
6164
  let hiddenCount = 0;
@@ -7623,6 +7681,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
7623
7681
  setActiveMode(initialDrawingMode);
7624
7682
  }
7625
7683
  onMapReady == null ? void 0 : onMapReady();
7684
+ onMapLoad == null ? void 0 : onMapLoad(mapInstance);
7626
7685
  if (baseMapStyle !== "satellite") {
7627
7686
  const customDef = customBasemaps == null ? void 0 : customBasemaps[baseMapStyle];
7628
7687
  const styleUrl = (customDef == null ? void 0 : customDef.type) === "vector" && typeof customDef.style === "string" ? customDef.style : EXTERNAL_STYLE_URLS[baseMapStyle];
@@ -7803,25 +7862,20 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
7803
7862
  }
7804
7863
  if (!isApiAddingRef.current) {
7805
7864
  const currentActiveEditingLayerId = activeEditingLayerIdRef.current;
7806
- setLayers((prev) => {
7807
- let targetLayer = prev.find((l) => l.id === currentActiveEditingLayerId && l.visible && !l.readOnly);
7808
- if (!targetLayer) {
7809
- targetLayer = prev.find((l) => l.visible && !l.readOnly);
7810
- }
7811
- if (!targetLayer) {
7812
- targetLayer = prev.find((l) => !l.readOnly);
7813
- }
7814
- if (!targetLayer) return prev;
7815
- return prev.map((layer) => {
7816
- if (layer.id === targetLayer.id) {
7817
- return {
7818
- ...layer,
7819
- featureIds: [...layer.featureIds, ...newFeatures.map((f) => f.id)]
7820
- };
7821
- }
7822
- return layer;
7823
- });
7824
- });
7865
+ const currentLayers = layersRef.current;
7866
+ const newIds = newFeatures.map((f) => f.id);
7867
+ let targetLayer = currentLayers.find((l) => l.id === currentActiveEditingLayerId && l.visible && !l.readOnly);
7868
+ if (!targetLayer) targetLayer = currentLayers.find((l) => l.visible && !l.readOnly);
7869
+ if (!targetLayer) targetLayer = currentLayers.find((l) => !l.readOnly);
7870
+ if (targetLayer) {
7871
+ const targetId = targetLayer.id;
7872
+ setLayers((prev) => prev.map(
7873
+ (layer) => layer.id === targetId ? { ...layer, featureIds: [...layer.featureIds, ...newIds] } : layer
7874
+ ));
7875
+ layersRef.current = currentLayers.map(
7876
+ (layer) => layer.id === targetId ? { ...layer, featureIds: [...layer.featureIds, ...newIds] } : layer
7877
+ );
7878
+ }
7825
7879
  }
7826
7880
  updateFeatureCount();
7827
7881
  scheduleTimelineUpdate();
@@ -7903,6 +7957,10 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
7903
7957
  return;
7904
7958
  }
7905
7959
  const ids = e.features.map((f) => f.id);
7960
+ if (justCreatedRectangleRef.current && ids.length === 0) {
7961
+ justCreatedRectangleRef.current = false;
7962
+ return;
7963
+ }
7906
7964
  e.features.forEach((feature) => {
7907
7965
  const fid = feature.id;
7908
7966
  if (!originalGeometriesRef.current.has(fid)) {
@@ -7917,7 +7975,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
7917
7975
  });
7918
7976
  setSelectedFeatureIds(ids);
7919
7977
  selectedFeatureIdsRef.current = ids;
7920
- setShowProperties(ids.length > 0);
7978
+ if (enableProperties) setShowProperties(ids.length > 0);
7921
7979
  syncRef.current();
7922
7980
  onFeatureSelect == null ? void 0 : onFeatureSelect(e.features);
7923
7981
  });
@@ -8502,9 +8560,9 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
8502
8560
  onTimelineChange == null ? void 0 : onTimelineChange(start, end);
8503
8561
  },
8504
8562
  exportGeoJSON: (layerIds) => {
8505
- const targetLayerIds = layerIds ?? layers.map((l) => l.id);
8563
+ const targetLayerIds = layerIds ?? layersRef.current.map((l) => l.id);
8506
8564
  const allFeatures = [];
8507
- layers.filter((l) => targetLayerIds.includes(l.id)).forEach((layer) => {
8565
+ layersRef.current.filter((l) => targetLayerIds.includes(l.id)).forEach((layer) => {
8508
8566
  const readOnly = readOnlyFeatures.current.get(layer.id);
8509
8567
  if (readOnly) {
8510
8568
  allFeatures.push(...readOnly);
@@ -8906,7 +8964,9 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
8906
8964
  layerTemporalCacheRef.current.clear();
8907
8965
  scheduleTimelineUpdate();
8908
8966
  syncFeaturesToCustomLayers();
8909
- }, [undoStack, layers, selectedFeatureIds, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, applySelectionState]);
8967
+ layersRef.current = prevState.layers;
8968
+ onUndo == null ? void 0 : onUndo(computeUndoRedoEvent(currentState, prevState));
8969
+ }, [undoStack, layers, selectedFeatureIds, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, applySelectionState, onUndo]);
8910
8970
  const handleRedo = react.useCallback(() => {
8911
8971
  if (redoStack.length === 0 || !draw.current) return;
8912
8972
  const currentState = {
@@ -8931,7 +8991,9 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
8931
8991
  layerTemporalCacheRef.current.clear();
8932
8992
  scheduleTimelineUpdate();
8933
8993
  syncFeaturesToCustomLayers();
8934
- }, [redoStack, layers, selectedFeatureIds, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, applySelectionState]);
8994
+ layersRef.current = nextState.layers;
8995
+ onRedo == null ? void 0 : onRedo(computeUndoRedoEvent(currentState, nextState));
8996
+ }, [redoStack, layers, selectedFeatureIds, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, applySelectionState, onRedo]);
8935
8997
  const handleClear = react.useCallback(() => {
8936
8998
  if (!draw.current) return;
8937
8999
  const activeLayer = layersRef.current.find((l) => l.id === activeEditingLayerId);
@@ -9087,7 +9149,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9087
9149
  handleToggleEditMode();
9088
9150
  return;
9089
9151
  }
9090
- if ((key === "delete" || key === "backspace") && !isCtrlOrCmd && selectedFeatureIds.length > 0) {
9152
+ if ((key === "delete" || key === "backspace") && !isCtrlOrCmd && selectedFeatureIds.length > 0 && canDeleteSelected) {
9091
9153
  e.preventDefault();
9092
9154
  handleDeleteSelected();
9093
9155
  return;
@@ -9108,6 +9170,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9108
9170
  handleModeChange(activeMode === "draw_polygon" ? "simple_select" : "draw_polygon");
9109
9171
  break;
9110
9172
  case "b":
9173
+ if (hiddenDrawingTools.includes("rectangle")) break;
9111
9174
  e.preventDefault();
9112
9175
  handleModeChange(activeMode === "draw_rectangle" ? "simple_select" : "draw_rectangle");
9113
9176
  break;
@@ -9130,7 +9193,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9130
9193
  };
9131
9194
  container.addEventListener("keydown", handleKeyDown);
9132
9195
  return () => container.removeEventListener("keydown", handleKeyDown);
9133
- }, [isMapLoaded, enableKeyboardShortcuts, isEditMode, activeMode, handleToggleEditMode, handleUndo, handleRedo, handleModeChange, selectedFeatureIds, handleDeleteSelected]);
9196
+ }, [isMapLoaded, enableKeyboardShortcuts, isEditMode, activeMode, handleToggleEditMode, handleUndo, handleRedo, handleModeChange, selectedFeatureIds, handleDeleteSelected, canDeleteSelected, hiddenDrawingTools]);
9134
9197
  const createPointAtCoords = react.useCallback((lng, lat) => {
9135
9198
  if (!draw.current || !isMapLoaded) return;
9136
9199
  if (!isEditModeRef.current) {
@@ -9162,13 +9225,13 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9162
9225
  });
9163
9226
  draw.current.changeMode("simple_select", { featureIds: [id] });
9164
9227
  setSelectedFeatureIds([id]);
9165
- setShowProperties(true);
9228
+ if (enableProperties) setShowProperties(true);
9166
9229
  updateFeatureCount();
9167
9230
  scheduleTimelineUpdate();
9168
9231
  saveStateForUndo();
9169
9232
  syncFeaturesToCustomLayers();
9170
9233
  onFeatureCreate == null ? void 0 : onFeatureCreate(feature);
9171
- }, [isMapLoaded, externalPersistence, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, onFeatureCreate]);
9234
+ }, [isMapLoaded, externalPersistence, enableProperties, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, onFeatureCreate]);
9172
9235
  const handleFeatureContextMenu = react.useCallback((e) => {
9173
9236
  var _a, _b;
9174
9237
  contextMenuFiredRef.current = true;
@@ -9257,7 +9320,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9257
9320
  return;
9258
9321
  }
9259
9322
  }
9260
- if (features.length === 0) {
9323
+ if (features.length === 0 && !hiddenDrawingTools.includes("point")) {
9261
9324
  e.preventDefault();
9262
9325
  const canCreate = hasEditableLayer;
9263
9326
  const items = [
@@ -9272,7 +9335,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9272
9335
  ];
9273
9336
  setContextMenu({ x: e.clientX, y: e.clientY, items });
9274
9337
  }
9275
- }, [contextMenuProvider, isEditMode, hasEditableLayer, onEntityContextMenu, createPointAtCoords]);
9338
+ }, [contextMenuProvider, isEditMode, hasEditableLayer, onEntityContextMenu, createPointAtCoords, hiddenDrawingTools]);
9276
9339
  react.useEffect(() => {
9277
9340
  if (!isMapLoaded || !map.current) return;
9278
9341
  const canvas = map.current.getCanvas();
@@ -10870,10 +10933,11 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
10870
10933
  map.current.getCanvas().style.cursor = "";
10871
10934
  }
10872
10935
  };
10873
- }, [activeMode, isMapLoaded, onFeatureCreate]);
10936
+ }, [activeMode, isMapLoaded, onFeatureCreate, enableProperties]);
10874
10937
  react.useEffect(() => {
10875
10938
  if (!map.current || !isMapLoaded || !draw.current) return;
10876
10939
  if (activeMode !== "draw_rectangle") {
10940
+ rectangleCornerPointRef.current = null;
10877
10941
  setRectangleDrawCorner(null);
10878
10942
  setRectangleDrawPreview(null);
10879
10943
  isDrawingRectangle.current = false;
@@ -10884,18 +10948,18 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
10884
10948
  const canvas = mapInstance.getCanvas();
10885
10949
  mapInstance.dragPan.disable();
10886
10950
  canvas.style.cursor = "crosshair";
10887
- let cornerPoint = null;
10888
10951
  const handleMouseDown = (e) => {
10889
10952
  if (e.button !== 0) return;
10890
10953
  const lngLat = mapInstance.unproject([e.offsetX, e.offsetY]);
10891
- cornerPoint = { lngLat: [lngLat.lng, lngLat.lat] };
10954
+ rectangleCornerPointRef.current = { lngLat: [lngLat.lng, lngLat.lat] };
10892
10955
  isDrawingRectangle.current = true;
10893
10956
  setRectangleDrawCorner([lngLat.lng, lngLat.lat]);
10894
10957
  };
10895
10958
  const handleMouseMove = (e) => {
10896
- if (!isDrawingRectangle.current || !cornerPoint) return;
10897
- const oppositeCorner = mapInstance.unproject([e.offsetX, e.offsetY]);
10898
- const [x1, y1] = cornerPoint.lngLat;
10959
+ if (!isDrawingRectangle.current || !rectangleCornerPointRef.current) return;
10960
+ const rect = canvas.getBoundingClientRect();
10961
+ const oppositeCorner = mapInstance.unproject([e.clientX - rect.left, e.clientY - rect.top]);
10962
+ const [x1, y1] = rectangleCornerPointRef.current.lngLat;
10899
10963
  const [x2, y2] = [oppositeCorner.lng, oppositeCorner.lat];
10900
10964
  const rectCoords = [
10901
10965
  [x1, y1],
@@ -10912,9 +10976,10 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
10912
10976
  setRectangleDrawPreview(rectCoords);
10913
10977
  };
10914
10978
  const handleMouseUp = (e) => {
10915
- if (!isDrawingRectangle.current || !cornerPoint) return;
10916
- const oppositeCorner = mapInstance.unproject([e.offsetX, e.offsetY]);
10917
- const [x1, y1] = cornerPoint.lngLat;
10979
+ if (!isDrawingRectangle.current || !rectangleCornerPointRef.current) return;
10980
+ const rect = canvas.getBoundingClientRect();
10981
+ const oppositeCorner = mapInstance.unproject([e.clientX - rect.left, e.clientY - rect.top]);
10982
+ const [x1, y1] = rectangleCornerPointRef.current.lngLat;
10918
10983
  const [x2, y2] = [oppositeCorner.lng, oppositeCorner.lat];
10919
10984
  const width = Math.abs(x2 - x1);
10920
10985
  const height = Math.abs(y2 - y1);
@@ -10959,6 +11024,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
10959
11024
  layers: layersRef.current
10960
11025
  }]);
10961
11026
  setRedoStack([]);
11027
+ justCreatedRectangleRef.current = true;
10962
11028
  drawInstance.changeMode("simple_select", { featureIds: [featureId] });
10963
11029
  setActiveMode("simple_select");
10964
11030
  setSelectedFeatureIds([featureId]);
@@ -10967,14 +11033,14 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
10967
11033
  onFeatureCreate(rectFeature);
10968
11034
  }
10969
11035
  }
10970
- cornerPoint = null;
11036
+ rectangleCornerPointRef.current = null;
10971
11037
  isDrawingRectangle.current = false;
10972
11038
  setRectangleDrawCorner(null);
10973
11039
  setRectangleDrawPreview(null);
10974
11040
  };
10975
11041
  const handleKeyDown = (e) => {
10976
11042
  if (e.key === "Escape") {
10977
- cornerPoint = null;
11043
+ rectangleCornerPointRef.current = null;
10978
11044
  isDrawingRectangle.current = false;
10979
11045
  setRectangleDrawCorner(null);
10980
11046
  setRectangleDrawPreview(null);
@@ -10982,20 +11048,20 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
10982
11048
  }
10983
11049
  };
10984
11050
  canvas.addEventListener("mousedown", handleMouseDown);
10985
- canvas.addEventListener("mousemove", handleMouseMove);
10986
- canvas.addEventListener("mouseup", handleMouseUp);
11051
+ window.addEventListener("mousemove", handleMouseMove);
11052
+ window.addEventListener("mouseup", handleMouseUp);
10987
11053
  window.addEventListener("keydown", handleKeyDown);
10988
11054
  return () => {
10989
11055
  canvas.removeEventListener("mousedown", handleMouseDown);
10990
- canvas.removeEventListener("mousemove", handleMouseMove);
10991
- canvas.removeEventListener("mouseup", handleMouseUp);
11056
+ window.removeEventListener("mousemove", handleMouseMove);
11057
+ window.removeEventListener("mouseup", handleMouseUp);
10992
11058
  window.removeEventListener("keydown", handleKeyDown);
10993
11059
  if (map.current) {
10994
11060
  map.current.dragPan.enable();
10995
11061
  map.current.getCanvas().style.cursor = "";
10996
11062
  }
10997
11063
  };
10998
- }, [activeMode, isMapLoaded, onFeatureCreate]);
11064
+ }, [activeMode, isMapLoaded, onFeatureCreate, enableProperties]);
10999
11065
  const measurePointsRef = react.useRef([]);
11000
11066
  react.useEffect(() => {
11001
11067
  measurePointsRef.current = measurePoints;
@@ -12174,7 +12240,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
12174
12240
  ] }) });
12175
12241
  }
12176
12242
  const toastContextValue = toastProvider ?? null;
12177
- return /* @__PURE__ */ jsxRuntime.jsx(ToastContext.Provider, { value: toastContextValue, children: /* @__PURE__ */ jsxRuntime.jsx(MapDropZone, { onDrop: handleDropGeoJSON, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `map-container w-full h-full min-w-0 relative ${className || ""}`, "data-testid": "map-editor-canvas", children: [
12243
+ return /* @__PURE__ */ jsxRuntime.jsx(ToastContext.Provider, { value: toastContextValue, children: /* @__PURE__ */ jsxRuntime.jsx(MapDropZone, { onDrop: handleDropGeoJSON, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `map-container w-full h-full min-w-0 relative overflow-hidden isolate ${className || ""}`, "data-testid": "map-editor-canvas", children: [
12178
12244
  /* @__PURE__ */ jsxRuntime.jsx(
12179
12245
  "div",
12180
12246
  {
@@ -12398,6 +12464,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
12398
12464
  onRedo: handleRedo,
12399
12465
  featureCount,
12400
12466
  selectedCount: selectedFeatureIds.length,
12467
+ canDeleteSelected,
12401
12468
  canUndo: undoStack.length > 0,
12402
12469
  canRedo: redoStack.length > 0,
12403
12470
  disabled: !isMapLoaded,
@@ -13402,7 +13469,7 @@ function DraggableDroneFlight({ item }) {
13402
13469
  }
13403
13470
  );
13404
13471
  }
13405
- function DebugSidebar({ onAddRandomPoints, onImportKML, canAddFeatures = true, className, onCloseMap }) {
13472
+ function DebugSidebar({ onAddRandomPoints, onImportKML, onAddDomMarkers, onRemoveDomMarkers, canAddFeatures = true, className, onCloseMap }) {
13406
13473
  const [isGenerating, setIsGenerating] = react.useState(false);
13407
13474
  const [isDragOver, setIsDragOver] = react.useState(false);
13408
13475
  const [wizardOpen, setWizardOpen] = react.useState(false);
@@ -13570,6 +13637,32 @@ function DebugSidebar({ onAddRandomPoints, onImportKML, canAddFeatures = true, c
13570
13637
  "Add 100k NYC Points"
13571
13638
  ]
13572
13639
  }
13640
+ ),
13641
+ onAddDomMarkers && /* @__PURE__ */ jsxRuntime.jsxs(
13642
+ antd.Button,
13643
+ {
13644
+ type: "default",
13645
+ size: "small",
13646
+ onClick: onAddDomMarkers,
13647
+ className: "w-full flex items-center justify-center",
13648
+ "data-testid": "button-add-dom-markers",
13649
+ children: [
13650
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Plus, { className: "w-4 h-4 mr-2" }),
13651
+ "Add DOM Markers (test)"
13652
+ ]
13653
+ }
13654
+ ),
13655
+ onRemoveDomMarkers && /* @__PURE__ */ jsxRuntime.jsx(
13656
+ antd.Button,
13657
+ {
13658
+ type: "default",
13659
+ size: "small",
13660
+ danger: true,
13661
+ onClick: onRemoveDomMarkers,
13662
+ className: "w-full flex items-center justify-center",
13663
+ "data-testid": "button-remove-dom-markers",
13664
+ children: "Remove DOM Markers"
13665
+ }
13573
13666
  )
13574
13667
  ] }),
13575
13668
  /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground mt-2", children: "Sequential: 10 points going east, 1 day apart. NYC: points clustered around Manhattan. People: 5 people moving for 6 hours. 100k: Performance test." })