@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 +213 -120
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +213 -120
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +1 -0
- package/dist/types/components/debug-sidebar.d.ts +3 -1
- package/dist/types/components/debug-sidebar.d.ts.map +1 -1
- package/dist/types/components/demos/standalone-demo.d.ts.map +1 -1
- package/dist/types/components/drawing-toolbar.d.ts +6 -2
- package/dist/types/components/drawing-toolbar.d.ts.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 +17 -1
- package/dist/types/lib/map-editor-api.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -473,7 +473,9 @@ function DrawingToolbar({
|
|
|
473
473
|
expandSelectionTools = false,
|
|
474
474
|
showFilterTool = false,
|
|
475
475
|
getAllFeatures,
|
|
476
|
-
onFlyToFeature
|
|
476
|
+
onFlyToFeature,
|
|
477
|
+
canDeleteSelected = true,
|
|
478
|
+
showUndoRedo = false
|
|
477
479
|
}) {
|
|
478
480
|
const { toast } = useToast();
|
|
479
481
|
const [goToLat, setGoToLat] = useState("");
|
|
@@ -774,30 +776,32 @@ function DrawingToolbar({
|
|
|
774
776
|
});
|
|
775
777
|
}
|
|
776
778
|
items.push({ type: "divider" });
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
/* @__PURE__ */ jsxs("
|
|
781
|
-
/* @__PURE__ */
|
|
782
|
-
|
|
779
|
+
if (showUndoRedo) {
|
|
780
|
+
items.push({
|
|
781
|
+
key: "undo",
|
|
782
|
+
label: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between w-full", children: [
|
|
783
|
+
/* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2", children: [
|
|
784
|
+
/* @__PURE__ */ jsx(Undo2, { className: "w-4 h-4" }),
|
|
785
|
+
"Undo"
|
|
786
|
+
] }),
|
|
787
|
+
showShortcutHints && /* @__PURE__ */ jsx("kbd", { className: "px-1.5 py-0.5 text-xs font-mono bg-black/10 dark:bg-white/10 rounded", children: "Ctrl+Z" })
|
|
783
788
|
] }),
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
"
|
|
789
|
+
disabled: disabled || !canUndo,
|
|
790
|
+
onClick: onUndo
|
|
791
|
+
});
|
|
792
|
+
items.push({
|
|
793
|
+
key: "redo",
|
|
794
|
+
label: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between w-full", children: [
|
|
795
|
+
/* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2", children: [
|
|
796
|
+
/* @__PURE__ */ jsx(Redo2, { className: "w-4 h-4" }),
|
|
797
|
+
"Redo"
|
|
798
|
+
] }),
|
|
799
|
+
showShortcutHints && /* @__PURE__ */ jsx("kbd", { className: "px-1.5 py-0.5 text-xs font-mono bg-black/10 dark:bg-white/10 rounded", children: "Ctrl+Y" })
|
|
795
800
|
] }),
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
});
|
|
801
|
+
disabled: disabled || !canRedo,
|
|
802
|
+
onClick: onRedo
|
|
803
|
+
});
|
|
804
|
+
}
|
|
801
805
|
items.push({ type: "divider" });
|
|
802
806
|
items.push({
|
|
803
807
|
key: "delete",
|
|
@@ -1128,7 +1132,20 @@ function DrawingToolbar({
|
|
|
1128
1132
|
showShortcutHint: showShortcutHints
|
|
1129
1133
|
}
|
|
1130
1134
|
),
|
|
1131
|
-
!hiddenDrawingTools.includes("polygon") && /* @__PURE__ */ jsx(
|
|
1135
|
+
!hiddenDrawingTools.includes("polygon") && hiddenDrawingTools.includes("rectangle") && /* @__PURE__ */ jsx(
|
|
1136
|
+
ToolButton,
|
|
1137
|
+
{
|
|
1138
|
+
mode: "draw_polygon",
|
|
1139
|
+
activeMode,
|
|
1140
|
+
onModeChange,
|
|
1141
|
+
icon: /* @__PURE__ */ jsx(Pentagon, { className: "w-5 h-5" }),
|
|
1142
|
+
label: "Draw Polygon",
|
|
1143
|
+
shortcut: "G",
|
|
1144
|
+
disabled: drawingDisabled,
|
|
1145
|
+
showShortcutHint: showShortcutHints
|
|
1146
|
+
}
|
|
1147
|
+
),
|
|
1148
|
+
!hiddenDrawingTools.includes("polygon") && !hiddenDrawingTools.includes("rectangle") && /* @__PURE__ */ jsx(
|
|
1132
1149
|
Dropdown,
|
|
1133
1150
|
{
|
|
1134
1151
|
menu: {
|
|
@@ -1226,55 +1243,57 @@ function DrawingToolbar({
|
|
|
1226
1243
|
showShortcutHint: showShortcutHints
|
|
1227
1244
|
}
|
|
1228
1245
|
),
|
|
1229
|
-
/* @__PURE__ */
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
"
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
"
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1246
|
+
showUndoRedo && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1247
|
+
/* @__PURE__ */ jsx(Divider, { className: "!my-0 !min-w-0" }),
|
|
1248
|
+
/* @__PURE__ */ jsx(
|
|
1249
|
+
Tooltip,
|
|
1250
|
+
{
|
|
1251
|
+
title: showShortcutHints ? /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2", children: [
|
|
1252
|
+
"Undo",
|
|
1253
|
+
/* @__PURE__ */ jsx("kbd", { className: "px-1.5 py-0.5 text-xs font-mono bg-black/20 rounded", children: "Ctrl+Z" })
|
|
1254
|
+
] }) : "Undo",
|
|
1255
|
+
placement: "right",
|
|
1256
|
+
children: /* @__PURE__ */ jsx(
|
|
1257
|
+
Button,
|
|
1258
|
+
{
|
|
1259
|
+
type: "text",
|
|
1260
|
+
onClick: onUndo,
|
|
1261
|
+
disabled: disabled || !canUndo,
|
|
1262
|
+
"aria-label": "Undo",
|
|
1263
|
+
"data-testid": "button-undo",
|
|
1264
|
+
className: "flex items-center justify-center !w-9 !h-9 !min-w-0 !p-0",
|
|
1265
|
+
icon: /* @__PURE__ */ jsx(Undo2, { className: "w-5 h-5" })
|
|
1266
|
+
}
|
|
1267
|
+
)
|
|
1268
|
+
}
|
|
1269
|
+
),
|
|
1270
|
+
/* @__PURE__ */ jsx(
|
|
1271
|
+
Tooltip,
|
|
1272
|
+
{
|
|
1273
|
+
title: showShortcutHints ? /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2", children: [
|
|
1274
|
+
"Redo",
|
|
1275
|
+
/* @__PURE__ */ jsx("kbd", { className: "px-1.5 py-0.5 text-xs font-mono bg-black/20 rounded", children: "Ctrl+Y" })
|
|
1276
|
+
] }) : "Redo",
|
|
1277
|
+
placement: "right",
|
|
1278
|
+
children: /* @__PURE__ */ jsx(
|
|
1279
|
+
Button,
|
|
1280
|
+
{
|
|
1281
|
+
type: "text",
|
|
1282
|
+
onClick: onRedo,
|
|
1283
|
+
disabled: disabled || !canRedo,
|
|
1284
|
+
"aria-label": "Redo",
|
|
1285
|
+
"data-testid": "button-redo",
|
|
1286
|
+
className: "flex items-center justify-center !w-9 !h-9 !min-w-0 !p-0",
|
|
1287
|
+
icon: /* @__PURE__ */ jsx(Redo2, { className: "w-5 h-5" })
|
|
1288
|
+
}
|
|
1289
|
+
)
|
|
1290
|
+
}
|
|
1291
|
+
)
|
|
1292
|
+
] })
|
|
1274
1293
|
] }),
|
|
1275
1294
|
compactOverflowItems
|
|
1276
1295
|
] }),
|
|
1277
|
-
selectedCount > 0 && /* @__PURE__ */ jsx(
|
|
1296
|
+
selectedCount > 0 && canDeleteSelected && /* @__PURE__ */ jsx(
|
|
1278
1297
|
Tooltip,
|
|
1279
1298
|
{
|
|
1280
1299
|
title: showShortcutHints ? /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2", children: [
|
|
@@ -5768,6 +5787,19 @@ const EXTERNAL_STYLE_URLS = {
|
|
|
5768
5787
|
streets: "https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json",
|
|
5769
5788
|
dark: "https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json"
|
|
5770
5789
|
};
|
|
5790
|
+
function computeUndoRedoEvent(fromState, toState) {
|
|
5791
|
+
const fromIds = new Set(fromState.features.map((f) => f.id));
|
|
5792
|
+
const toIds = new Set(toState.features.map((f) => f.id));
|
|
5793
|
+
const restoredFeatures = toState.features.filter((f) => !fromIds.has(f.id)).map((f) => {
|
|
5794
|
+
var _a;
|
|
5795
|
+
return {
|
|
5796
|
+
feature: f,
|
|
5797
|
+
layerId: ((_a = toState.layers.find((l) => l.featureIds.includes(f.id))) == null ? void 0 : _a.id) ?? null
|
|
5798
|
+
};
|
|
5799
|
+
});
|
|
5800
|
+
const removedFeatureIds = fromState.features.filter((f) => !toIds.has(f.id)).map((f) => f.id);
|
|
5801
|
+
return { restoredFeatures, removedFeatureIds };
|
|
5802
|
+
}
|
|
5771
5803
|
const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
5772
5804
|
className,
|
|
5773
5805
|
enableDrawing = true,
|
|
@@ -5795,10 +5827,13 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
5795
5827
|
onFeatureCreate,
|
|
5796
5828
|
onFeatureUpdate,
|
|
5797
5829
|
onFeatureDelete,
|
|
5830
|
+
onUndo,
|
|
5831
|
+
onRedo,
|
|
5798
5832
|
onLayerChange,
|
|
5799
5833
|
onActiveEditingLayerChange,
|
|
5800
5834
|
onTimelineChange,
|
|
5801
5835
|
onMapReady,
|
|
5836
|
+
onMapLoad,
|
|
5802
5837
|
onViewportChange,
|
|
5803
5838
|
showClearFilter = false,
|
|
5804
5839
|
onClearFilter,
|
|
@@ -5909,6 +5944,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
5909
5944
|
const [rectangleDrawCorner, setRectangleDrawCorner] = useState(null);
|
|
5910
5945
|
const [rectangleDrawPreview, setRectangleDrawPreview] = useState(null);
|
|
5911
5946
|
const isDrawingRectangle = useRef(false);
|
|
5947
|
+
const rectangleCornerPointRef = useRef(null);
|
|
5948
|
+
const justCreatedRectangleRef = useRef(false);
|
|
5912
5949
|
const [autoLabelConfig, setAutoLabelConfig] = useState({ enabled: true, threshold: 220 });
|
|
5913
5950
|
const [visibleFeatureCount, setVisibleFeatureCount] = useState(Infinity);
|
|
5914
5951
|
const lastLabelVisibility = useRef(false);
|
|
@@ -6030,6 +6067,27 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
6030
6067
|
}
|
|
6031
6068
|
return null;
|
|
6032
6069
|
}, []);
|
|
6070
|
+
const canDeleteSelected = useMemo(() => {
|
|
6071
|
+
if (selectedFeatureIds.length === 0) return false;
|
|
6072
|
+
return selectedFeatureIds.some((id) => {
|
|
6073
|
+
var _a;
|
|
6074
|
+
const feature = getFeatureById(id);
|
|
6075
|
+
if (!feature) return false;
|
|
6076
|
+
const geom = feature.geometry.type;
|
|
6077
|
+
const kind = (_a = feature.properties) == null ? void 0 : _a.kind;
|
|
6078
|
+
const isArrow = kind === "arrow" || arrowFeatureIdsRef.current.has(id);
|
|
6079
|
+
if (geom === "Point") {
|
|
6080
|
+
return kind === "text" ? !hiddenDrawingTools.includes("text") : !hiddenDrawingTools.includes("point");
|
|
6081
|
+
}
|
|
6082
|
+
if (geom === "LineString" || geom === "MultiLineString") {
|
|
6083
|
+
return isArrow ? !hiddenDrawingTools.includes("arrow") : !hiddenDrawingTools.includes("line");
|
|
6084
|
+
}
|
|
6085
|
+
if (geom === "Polygon" || geom === "MultiPolygon") {
|
|
6086
|
+
return kind === "circle" ? !hiddenDrawingTools.includes("circle") : !hiddenDrawingTools.includes("polygon");
|
|
6087
|
+
}
|
|
6088
|
+
return true;
|
|
6089
|
+
});
|
|
6090
|
+
}, [selectedFeatureIds, hiddenDrawingTools, getFeatureById]);
|
|
6033
6091
|
const applySelectionState = useCallback((nextIds, options) => {
|
|
6034
6092
|
if (!isMapLoaded || !draw.current) {
|
|
6035
6093
|
setSelectedFeatureIds(nextIds);
|
|
@@ -6074,12 +6132,12 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
6074
6132
|
if (!draw.current) return;
|
|
6075
6133
|
const currentState = {
|
|
6076
6134
|
features: draw.current.getAll().features,
|
|
6077
|
-
layers: JSON.parse(JSON.stringify(
|
|
6135
|
+
layers: JSON.parse(JSON.stringify(layersRef.current)),
|
|
6078
6136
|
selectedIds: [...selectedFeatureIds]
|
|
6079
6137
|
};
|
|
6080
6138
|
setUndoStack((prev) => [...prev.slice(-49), currentState]);
|
|
6081
6139
|
setRedoStack([]);
|
|
6082
|
-
}, [
|
|
6140
|
+
}, [selectedFeatureIds]);
|
|
6083
6141
|
const updateFeatureCount = useCallback(() => {
|
|
6084
6142
|
const drawFeatureCount = draw.current ? draw.current.getAll().features.length : 0;
|
|
6085
6143
|
let hiddenCount = 0;
|
|
@@ -7602,6 +7660,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
7602
7660
|
setActiveMode(initialDrawingMode);
|
|
7603
7661
|
}
|
|
7604
7662
|
onMapReady == null ? void 0 : onMapReady();
|
|
7663
|
+
onMapLoad == null ? void 0 : onMapLoad(mapInstance);
|
|
7605
7664
|
if (baseMapStyle !== "satellite") {
|
|
7606
7665
|
const customDef = customBasemaps == null ? void 0 : customBasemaps[baseMapStyle];
|
|
7607
7666
|
const styleUrl = (customDef == null ? void 0 : customDef.type) === "vector" && typeof customDef.style === "string" ? customDef.style : EXTERNAL_STYLE_URLS[baseMapStyle];
|
|
@@ -7782,25 +7841,20 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
7782
7841
|
}
|
|
7783
7842
|
if (!isApiAddingRef.current) {
|
|
7784
7843
|
const currentActiveEditingLayerId = activeEditingLayerIdRef.current;
|
|
7785
|
-
|
|
7786
|
-
|
|
7787
|
-
|
|
7788
|
-
|
|
7789
|
-
|
|
7790
|
-
|
|
7791
|
-
|
|
7792
|
-
|
|
7793
|
-
|
|
7794
|
-
|
|
7795
|
-
|
|
7796
|
-
|
|
7797
|
-
|
|
7798
|
-
|
|
7799
|
-
};
|
|
7800
|
-
}
|
|
7801
|
-
return layer;
|
|
7802
|
-
});
|
|
7803
|
-
});
|
|
7844
|
+
const currentLayers = layersRef.current;
|
|
7845
|
+
const newIds = newFeatures.map((f) => f.id);
|
|
7846
|
+
let targetLayer = currentLayers.find((l) => l.id === currentActiveEditingLayerId && l.visible && !l.readOnly);
|
|
7847
|
+
if (!targetLayer) targetLayer = currentLayers.find((l) => l.visible && !l.readOnly);
|
|
7848
|
+
if (!targetLayer) targetLayer = currentLayers.find((l) => !l.readOnly);
|
|
7849
|
+
if (targetLayer) {
|
|
7850
|
+
const targetId = targetLayer.id;
|
|
7851
|
+
setLayers((prev) => prev.map(
|
|
7852
|
+
(layer) => layer.id === targetId ? { ...layer, featureIds: [...layer.featureIds, ...newIds] } : layer
|
|
7853
|
+
));
|
|
7854
|
+
layersRef.current = currentLayers.map(
|
|
7855
|
+
(layer) => layer.id === targetId ? { ...layer, featureIds: [...layer.featureIds, ...newIds] } : layer
|
|
7856
|
+
);
|
|
7857
|
+
}
|
|
7804
7858
|
}
|
|
7805
7859
|
updateFeatureCount();
|
|
7806
7860
|
scheduleTimelineUpdate();
|
|
@@ -7882,6 +7936,10 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
7882
7936
|
return;
|
|
7883
7937
|
}
|
|
7884
7938
|
const ids = e.features.map((f) => f.id);
|
|
7939
|
+
if (justCreatedRectangleRef.current && ids.length === 0) {
|
|
7940
|
+
justCreatedRectangleRef.current = false;
|
|
7941
|
+
return;
|
|
7942
|
+
}
|
|
7885
7943
|
e.features.forEach((feature) => {
|
|
7886
7944
|
const fid = feature.id;
|
|
7887
7945
|
if (!originalGeometriesRef.current.has(fid)) {
|
|
@@ -7896,7 +7954,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
7896
7954
|
});
|
|
7897
7955
|
setSelectedFeatureIds(ids);
|
|
7898
7956
|
selectedFeatureIdsRef.current = ids;
|
|
7899
|
-
setShowProperties(ids.length > 0);
|
|
7957
|
+
if (enableProperties) setShowProperties(ids.length > 0);
|
|
7900
7958
|
syncRef.current();
|
|
7901
7959
|
onFeatureSelect == null ? void 0 : onFeatureSelect(e.features);
|
|
7902
7960
|
});
|
|
@@ -8481,9 +8539,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
8481
8539
|
onTimelineChange == null ? void 0 : onTimelineChange(start, end);
|
|
8482
8540
|
},
|
|
8483
8541
|
exportGeoJSON: (layerIds) => {
|
|
8484
|
-
const targetLayerIds = layerIds ??
|
|
8542
|
+
const targetLayerIds = layerIds ?? layersRef.current.map((l) => l.id);
|
|
8485
8543
|
const allFeatures = [];
|
|
8486
|
-
|
|
8544
|
+
layersRef.current.filter((l) => targetLayerIds.includes(l.id)).forEach((layer) => {
|
|
8487
8545
|
const readOnly = readOnlyFeatures.current.get(layer.id);
|
|
8488
8546
|
if (readOnly) {
|
|
8489
8547
|
allFeatures.push(...readOnly);
|
|
@@ -8885,7 +8943,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
8885
8943
|
layerTemporalCacheRef.current.clear();
|
|
8886
8944
|
scheduleTimelineUpdate();
|
|
8887
8945
|
syncFeaturesToCustomLayers();
|
|
8888
|
-
|
|
8946
|
+
layersRef.current = prevState.layers;
|
|
8947
|
+
onUndo == null ? void 0 : onUndo(computeUndoRedoEvent(currentState, prevState));
|
|
8948
|
+
}, [undoStack, layers, selectedFeatureIds, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, applySelectionState, onUndo]);
|
|
8889
8949
|
const handleRedo = useCallback(() => {
|
|
8890
8950
|
if (redoStack.length === 0 || !draw.current) return;
|
|
8891
8951
|
const currentState = {
|
|
@@ -8910,7 +8970,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
8910
8970
|
layerTemporalCacheRef.current.clear();
|
|
8911
8971
|
scheduleTimelineUpdate();
|
|
8912
8972
|
syncFeaturesToCustomLayers();
|
|
8913
|
-
|
|
8973
|
+
layersRef.current = nextState.layers;
|
|
8974
|
+
onRedo == null ? void 0 : onRedo(computeUndoRedoEvent(currentState, nextState));
|
|
8975
|
+
}, [redoStack, layers, selectedFeatureIds, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, applySelectionState, onRedo]);
|
|
8914
8976
|
const handleClear = useCallback(() => {
|
|
8915
8977
|
if (!draw.current) return;
|
|
8916
8978
|
const activeLayer = layersRef.current.find((l) => l.id === activeEditingLayerId);
|
|
@@ -9066,7 +9128,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9066
9128
|
handleToggleEditMode();
|
|
9067
9129
|
return;
|
|
9068
9130
|
}
|
|
9069
|
-
if ((key === "delete" || key === "backspace") && !isCtrlOrCmd && selectedFeatureIds.length > 0) {
|
|
9131
|
+
if ((key === "delete" || key === "backspace") && !isCtrlOrCmd && selectedFeatureIds.length > 0 && canDeleteSelected) {
|
|
9070
9132
|
e.preventDefault();
|
|
9071
9133
|
handleDeleteSelected();
|
|
9072
9134
|
return;
|
|
@@ -9087,6 +9149,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9087
9149
|
handleModeChange(activeMode === "draw_polygon" ? "simple_select" : "draw_polygon");
|
|
9088
9150
|
break;
|
|
9089
9151
|
case "b":
|
|
9152
|
+
if (hiddenDrawingTools.includes("rectangle")) break;
|
|
9090
9153
|
e.preventDefault();
|
|
9091
9154
|
handleModeChange(activeMode === "draw_rectangle" ? "simple_select" : "draw_rectangle");
|
|
9092
9155
|
break;
|
|
@@ -9109,7 +9172,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9109
9172
|
};
|
|
9110
9173
|
container.addEventListener("keydown", handleKeyDown);
|
|
9111
9174
|
return () => container.removeEventListener("keydown", handleKeyDown);
|
|
9112
|
-
}, [isMapLoaded, enableKeyboardShortcuts, isEditMode, activeMode, handleToggleEditMode, handleUndo, handleRedo, handleModeChange, selectedFeatureIds, handleDeleteSelected]);
|
|
9175
|
+
}, [isMapLoaded, enableKeyboardShortcuts, isEditMode, activeMode, handleToggleEditMode, handleUndo, handleRedo, handleModeChange, selectedFeatureIds, handleDeleteSelected, canDeleteSelected, hiddenDrawingTools]);
|
|
9113
9176
|
const createPointAtCoords = useCallback((lng, lat) => {
|
|
9114
9177
|
if (!draw.current || !isMapLoaded) return;
|
|
9115
9178
|
if (!isEditModeRef.current) {
|
|
@@ -9141,13 +9204,13 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9141
9204
|
});
|
|
9142
9205
|
draw.current.changeMode("simple_select", { featureIds: [id] });
|
|
9143
9206
|
setSelectedFeatureIds([id]);
|
|
9144
|
-
setShowProperties(true);
|
|
9207
|
+
if (enableProperties) setShowProperties(true);
|
|
9145
9208
|
updateFeatureCount();
|
|
9146
9209
|
scheduleTimelineUpdate();
|
|
9147
9210
|
saveStateForUndo();
|
|
9148
9211
|
syncFeaturesToCustomLayers();
|
|
9149
9212
|
onFeatureCreate == null ? void 0 : onFeatureCreate(feature);
|
|
9150
|
-
}, [isMapLoaded, externalPersistence, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, onFeatureCreate]);
|
|
9213
|
+
}, [isMapLoaded, externalPersistence, enableProperties, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, onFeatureCreate]);
|
|
9151
9214
|
const handleFeatureContextMenu = useCallback((e) => {
|
|
9152
9215
|
var _a, _b;
|
|
9153
9216
|
contextMenuFiredRef.current = true;
|
|
@@ -9236,7 +9299,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9236
9299
|
return;
|
|
9237
9300
|
}
|
|
9238
9301
|
}
|
|
9239
|
-
if (features.length === 0) {
|
|
9302
|
+
if (features.length === 0 && !hiddenDrawingTools.includes("point")) {
|
|
9240
9303
|
e.preventDefault();
|
|
9241
9304
|
const canCreate = hasEditableLayer;
|
|
9242
9305
|
const items = [
|
|
@@ -9251,7 +9314,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9251
9314
|
];
|
|
9252
9315
|
setContextMenu({ x: e.clientX, y: e.clientY, items });
|
|
9253
9316
|
}
|
|
9254
|
-
}, [contextMenuProvider, isEditMode, hasEditableLayer, onEntityContextMenu, createPointAtCoords]);
|
|
9317
|
+
}, [contextMenuProvider, isEditMode, hasEditableLayer, onEntityContextMenu, createPointAtCoords, hiddenDrawingTools]);
|
|
9255
9318
|
useEffect(() => {
|
|
9256
9319
|
if (!isMapLoaded || !map.current) return;
|
|
9257
9320
|
const canvas = map.current.getCanvas();
|
|
@@ -10849,10 +10912,11 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
10849
10912
|
map.current.getCanvas().style.cursor = "";
|
|
10850
10913
|
}
|
|
10851
10914
|
};
|
|
10852
|
-
}, [activeMode, isMapLoaded, onFeatureCreate]);
|
|
10915
|
+
}, [activeMode, isMapLoaded, onFeatureCreate, enableProperties]);
|
|
10853
10916
|
useEffect(() => {
|
|
10854
10917
|
if (!map.current || !isMapLoaded || !draw.current) return;
|
|
10855
10918
|
if (activeMode !== "draw_rectangle") {
|
|
10919
|
+
rectangleCornerPointRef.current = null;
|
|
10856
10920
|
setRectangleDrawCorner(null);
|
|
10857
10921
|
setRectangleDrawPreview(null);
|
|
10858
10922
|
isDrawingRectangle.current = false;
|
|
@@ -10863,18 +10927,18 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
10863
10927
|
const canvas = mapInstance.getCanvas();
|
|
10864
10928
|
mapInstance.dragPan.disable();
|
|
10865
10929
|
canvas.style.cursor = "crosshair";
|
|
10866
|
-
let cornerPoint = null;
|
|
10867
10930
|
const handleMouseDown = (e) => {
|
|
10868
10931
|
if (e.button !== 0) return;
|
|
10869
10932
|
const lngLat = mapInstance.unproject([e.offsetX, e.offsetY]);
|
|
10870
|
-
|
|
10933
|
+
rectangleCornerPointRef.current = { lngLat: [lngLat.lng, lngLat.lat] };
|
|
10871
10934
|
isDrawingRectangle.current = true;
|
|
10872
10935
|
setRectangleDrawCorner([lngLat.lng, lngLat.lat]);
|
|
10873
10936
|
};
|
|
10874
10937
|
const handleMouseMove = (e) => {
|
|
10875
|
-
if (!isDrawingRectangle.current || !
|
|
10876
|
-
const
|
|
10877
|
-
const [
|
|
10938
|
+
if (!isDrawingRectangle.current || !rectangleCornerPointRef.current) return;
|
|
10939
|
+
const rect = canvas.getBoundingClientRect();
|
|
10940
|
+
const oppositeCorner = mapInstance.unproject([e.clientX - rect.left, e.clientY - rect.top]);
|
|
10941
|
+
const [x1, y1] = rectangleCornerPointRef.current.lngLat;
|
|
10878
10942
|
const [x2, y2] = [oppositeCorner.lng, oppositeCorner.lat];
|
|
10879
10943
|
const rectCoords = [
|
|
10880
10944
|
[x1, y1],
|
|
@@ -10891,9 +10955,10 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
10891
10955
|
setRectangleDrawPreview(rectCoords);
|
|
10892
10956
|
};
|
|
10893
10957
|
const handleMouseUp = (e) => {
|
|
10894
|
-
if (!isDrawingRectangle.current || !
|
|
10895
|
-
const
|
|
10896
|
-
const [
|
|
10958
|
+
if (!isDrawingRectangle.current || !rectangleCornerPointRef.current) return;
|
|
10959
|
+
const rect = canvas.getBoundingClientRect();
|
|
10960
|
+
const oppositeCorner = mapInstance.unproject([e.clientX - rect.left, e.clientY - rect.top]);
|
|
10961
|
+
const [x1, y1] = rectangleCornerPointRef.current.lngLat;
|
|
10897
10962
|
const [x2, y2] = [oppositeCorner.lng, oppositeCorner.lat];
|
|
10898
10963
|
const width = Math.abs(x2 - x1);
|
|
10899
10964
|
const height = Math.abs(y2 - y1);
|
|
@@ -10938,6 +11003,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
10938
11003
|
layers: layersRef.current
|
|
10939
11004
|
}]);
|
|
10940
11005
|
setRedoStack([]);
|
|
11006
|
+
justCreatedRectangleRef.current = true;
|
|
10941
11007
|
drawInstance.changeMode("simple_select", { featureIds: [featureId] });
|
|
10942
11008
|
setActiveMode("simple_select");
|
|
10943
11009
|
setSelectedFeatureIds([featureId]);
|
|
@@ -10946,14 +11012,14 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
10946
11012
|
onFeatureCreate(rectFeature);
|
|
10947
11013
|
}
|
|
10948
11014
|
}
|
|
10949
|
-
|
|
11015
|
+
rectangleCornerPointRef.current = null;
|
|
10950
11016
|
isDrawingRectangle.current = false;
|
|
10951
11017
|
setRectangleDrawCorner(null);
|
|
10952
11018
|
setRectangleDrawPreview(null);
|
|
10953
11019
|
};
|
|
10954
11020
|
const handleKeyDown = (e) => {
|
|
10955
11021
|
if (e.key === "Escape") {
|
|
10956
|
-
|
|
11022
|
+
rectangleCornerPointRef.current = null;
|
|
10957
11023
|
isDrawingRectangle.current = false;
|
|
10958
11024
|
setRectangleDrawCorner(null);
|
|
10959
11025
|
setRectangleDrawPreview(null);
|
|
@@ -10961,20 +11027,20 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
10961
11027
|
}
|
|
10962
11028
|
};
|
|
10963
11029
|
canvas.addEventListener("mousedown", handleMouseDown);
|
|
10964
|
-
|
|
10965
|
-
|
|
11030
|
+
window.addEventListener("mousemove", handleMouseMove);
|
|
11031
|
+
window.addEventListener("mouseup", handleMouseUp);
|
|
10966
11032
|
window.addEventListener("keydown", handleKeyDown);
|
|
10967
11033
|
return () => {
|
|
10968
11034
|
canvas.removeEventListener("mousedown", handleMouseDown);
|
|
10969
|
-
|
|
10970
|
-
|
|
11035
|
+
window.removeEventListener("mousemove", handleMouseMove);
|
|
11036
|
+
window.removeEventListener("mouseup", handleMouseUp);
|
|
10971
11037
|
window.removeEventListener("keydown", handleKeyDown);
|
|
10972
11038
|
if (map.current) {
|
|
10973
11039
|
map.current.dragPan.enable();
|
|
10974
11040
|
map.current.getCanvas().style.cursor = "";
|
|
10975
11041
|
}
|
|
10976
11042
|
};
|
|
10977
|
-
}, [activeMode, isMapLoaded, onFeatureCreate]);
|
|
11043
|
+
}, [activeMode, isMapLoaded, onFeatureCreate, enableProperties]);
|
|
10978
11044
|
const measurePointsRef = useRef([]);
|
|
10979
11045
|
useEffect(() => {
|
|
10980
11046
|
measurePointsRef.current = measurePoints;
|
|
@@ -12153,7 +12219,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
12153
12219
|
] }) });
|
|
12154
12220
|
}
|
|
12155
12221
|
const toastContextValue = toastProvider ?? null;
|
|
12156
|
-
return /* @__PURE__ */ jsx(ToastContext.Provider, { value: toastContextValue, children: /* @__PURE__ */ jsx(MapDropZone, { onDrop: handleDropGeoJSON, children: /* @__PURE__ */ jsxs("div", { className: `map-container w-full h-full min-w-0 relative ${className || ""}`, "data-testid": "map-editor-canvas", children: [
|
|
12222
|
+
return /* @__PURE__ */ jsx(ToastContext.Provider, { value: toastContextValue, children: /* @__PURE__ */ jsx(MapDropZone, { onDrop: handleDropGeoJSON, children: /* @__PURE__ */ jsxs("div", { className: `map-container w-full h-full min-w-0 relative overflow-hidden isolate ${className || ""}`, "data-testid": "map-editor-canvas", children: [
|
|
12157
12223
|
/* @__PURE__ */ jsx(
|
|
12158
12224
|
"div",
|
|
12159
12225
|
{
|
|
@@ -12377,6 +12443,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
12377
12443
|
onRedo: handleRedo,
|
|
12378
12444
|
featureCount,
|
|
12379
12445
|
selectedCount: selectedFeatureIds.length,
|
|
12446
|
+
canDeleteSelected,
|
|
12380
12447
|
canUndo: undoStack.length > 0,
|
|
12381
12448
|
canRedo: redoStack.length > 0,
|
|
12382
12449
|
disabled: !isMapLoaded,
|
|
@@ -13381,7 +13448,7 @@ function DraggableDroneFlight({ item }) {
|
|
|
13381
13448
|
}
|
|
13382
13449
|
);
|
|
13383
13450
|
}
|
|
13384
|
-
function DebugSidebar({ onAddRandomPoints, onImportKML, canAddFeatures = true, className, onCloseMap }) {
|
|
13451
|
+
function DebugSidebar({ onAddRandomPoints, onImportKML, onAddDomMarkers, onRemoveDomMarkers, canAddFeatures = true, className, onCloseMap }) {
|
|
13385
13452
|
const [isGenerating, setIsGenerating] = useState(false);
|
|
13386
13453
|
const [isDragOver, setIsDragOver] = useState(false);
|
|
13387
13454
|
const [wizardOpen, setWizardOpen] = useState(false);
|
|
@@ -13549,6 +13616,32 @@ function DebugSidebar({ onAddRandomPoints, onImportKML, canAddFeatures = true, c
|
|
|
13549
13616
|
"Add 100k NYC Points"
|
|
13550
13617
|
]
|
|
13551
13618
|
}
|
|
13619
|
+
),
|
|
13620
|
+
onAddDomMarkers && /* @__PURE__ */ jsxs(
|
|
13621
|
+
Button,
|
|
13622
|
+
{
|
|
13623
|
+
type: "default",
|
|
13624
|
+
size: "small",
|
|
13625
|
+
onClick: onAddDomMarkers,
|
|
13626
|
+
className: "w-full flex items-center justify-center",
|
|
13627
|
+
"data-testid": "button-add-dom-markers",
|
|
13628
|
+
children: [
|
|
13629
|
+
/* @__PURE__ */ jsx(Plus, { className: "w-4 h-4 mr-2" }),
|
|
13630
|
+
"Add DOM Markers (test)"
|
|
13631
|
+
]
|
|
13632
|
+
}
|
|
13633
|
+
),
|
|
13634
|
+
onRemoveDomMarkers && /* @__PURE__ */ jsx(
|
|
13635
|
+
Button,
|
|
13636
|
+
{
|
|
13637
|
+
type: "default",
|
|
13638
|
+
size: "small",
|
|
13639
|
+
danger: true,
|
|
13640
|
+
onClick: onRemoveDomMarkers,
|
|
13641
|
+
className: "w-full flex items-center justify-center",
|
|
13642
|
+
"data-testid": "button-remove-dom-markers",
|
|
13643
|
+
children: "Remove DOM Markers"
|
|
13644
|
+
}
|
|
13552
13645
|
)
|
|
13553
13646
|
] }),
|
|
13554
13647
|
/* @__PURE__ */ 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." })
|