@octostar/map-component 0.1.32 → 0.1.34
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/README.md +13 -0
- package/dist/index.cjs +194 -115
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +194 -115
- 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 +5 -1
- 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 +16 -0
- 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",
|
|
@@ -1226,55 +1230,57 @@ function DrawingToolbar({
|
|
|
1226
1230
|
showShortcutHint: showShortcutHints
|
|
1227
1231
|
}
|
|
1228
1232
|
),
|
|
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
|
-
|
|
1233
|
+
showUndoRedo && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1234
|
+
/* @__PURE__ */ jsx(Divider, { className: "!my-0 !min-w-0" }),
|
|
1235
|
+
/* @__PURE__ */ jsx(
|
|
1236
|
+
Tooltip,
|
|
1237
|
+
{
|
|
1238
|
+
title: showShortcutHints ? /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2", children: [
|
|
1239
|
+
"Undo",
|
|
1240
|
+
/* @__PURE__ */ jsx("kbd", { className: "px-1.5 py-0.5 text-xs font-mono bg-black/20 rounded", children: "Ctrl+Z" })
|
|
1241
|
+
] }) : "Undo",
|
|
1242
|
+
placement: "right",
|
|
1243
|
+
children: /* @__PURE__ */ jsx(
|
|
1244
|
+
Button,
|
|
1245
|
+
{
|
|
1246
|
+
type: "text",
|
|
1247
|
+
onClick: onUndo,
|
|
1248
|
+
disabled: disabled || !canUndo,
|
|
1249
|
+
"aria-label": "Undo",
|
|
1250
|
+
"data-testid": "button-undo",
|
|
1251
|
+
className: "flex items-center justify-center !w-9 !h-9 !min-w-0 !p-0",
|
|
1252
|
+
icon: /* @__PURE__ */ jsx(Undo2, { className: "w-5 h-5" })
|
|
1253
|
+
}
|
|
1254
|
+
)
|
|
1255
|
+
}
|
|
1256
|
+
),
|
|
1257
|
+
/* @__PURE__ */ jsx(
|
|
1258
|
+
Tooltip,
|
|
1259
|
+
{
|
|
1260
|
+
title: showShortcutHints ? /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2", children: [
|
|
1261
|
+
"Redo",
|
|
1262
|
+
/* @__PURE__ */ jsx("kbd", { className: "px-1.5 py-0.5 text-xs font-mono bg-black/20 rounded", children: "Ctrl+Y" })
|
|
1263
|
+
] }) : "Redo",
|
|
1264
|
+
placement: "right",
|
|
1265
|
+
children: /* @__PURE__ */ jsx(
|
|
1266
|
+
Button,
|
|
1267
|
+
{
|
|
1268
|
+
type: "text",
|
|
1269
|
+
onClick: onRedo,
|
|
1270
|
+
disabled: disabled || !canRedo,
|
|
1271
|
+
"aria-label": "Redo",
|
|
1272
|
+
"data-testid": "button-redo",
|
|
1273
|
+
className: "flex items-center justify-center !w-9 !h-9 !min-w-0 !p-0",
|
|
1274
|
+
icon: /* @__PURE__ */ jsx(Redo2, { className: "w-5 h-5" })
|
|
1275
|
+
}
|
|
1276
|
+
)
|
|
1277
|
+
}
|
|
1278
|
+
)
|
|
1279
|
+
] })
|
|
1274
1280
|
] }),
|
|
1275
1281
|
compactOverflowItems
|
|
1276
1282
|
] }),
|
|
1277
|
-
selectedCount > 0 && /* @__PURE__ */ jsx(
|
|
1283
|
+
selectedCount > 0 && canDeleteSelected && /* @__PURE__ */ jsx(
|
|
1278
1284
|
Tooltip,
|
|
1279
1285
|
{
|
|
1280
1286
|
title: showShortcutHints ? /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2", children: [
|
|
@@ -5768,6 +5774,19 @@ const EXTERNAL_STYLE_URLS = {
|
|
|
5768
5774
|
streets: "https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json",
|
|
5769
5775
|
dark: "https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json"
|
|
5770
5776
|
};
|
|
5777
|
+
function computeUndoRedoEvent(fromState, toState) {
|
|
5778
|
+
const fromIds = new Set(fromState.features.map((f) => f.id));
|
|
5779
|
+
const toIds = new Set(toState.features.map((f) => f.id));
|
|
5780
|
+
const restoredFeatures = toState.features.filter((f) => !fromIds.has(f.id)).map((f) => {
|
|
5781
|
+
var _a;
|
|
5782
|
+
return {
|
|
5783
|
+
feature: f,
|
|
5784
|
+
layerId: ((_a = toState.layers.find((l) => l.featureIds.includes(f.id))) == null ? void 0 : _a.id) ?? null
|
|
5785
|
+
};
|
|
5786
|
+
});
|
|
5787
|
+
const removedFeatureIds = fromState.features.filter((f) => !toIds.has(f.id)).map((f) => f.id);
|
|
5788
|
+
return { restoredFeatures, removedFeatureIds };
|
|
5789
|
+
}
|
|
5771
5790
|
const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
5772
5791
|
className,
|
|
5773
5792
|
enableDrawing = true,
|
|
@@ -5795,10 +5814,13 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
5795
5814
|
onFeatureCreate,
|
|
5796
5815
|
onFeatureUpdate,
|
|
5797
5816
|
onFeatureDelete,
|
|
5817
|
+
onUndo,
|
|
5818
|
+
onRedo,
|
|
5798
5819
|
onLayerChange,
|
|
5799
5820
|
onActiveEditingLayerChange,
|
|
5800
5821
|
onTimelineChange,
|
|
5801
5822
|
onMapReady,
|
|
5823
|
+
onMapLoad,
|
|
5802
5824
|
onViewportChange,
|
|
5803
5825
|
showClearFilter = false,
|
|
5804
5826
|
onClearFilter,
|
|
@@ -5909,6 +5931,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
5909
5931
|
const [rectangleDrawCorner, setRectangleDrawCorner] = useState(null);
|
|
5910
5932
|
const [rectangleDrawPreview, setRectangleDrawPreview] = useState(null);
|
|
5911
5933
|
const isDrawingRectangle = useRef(false);
|
|
5934
|
+
const rectangleCornerPointRef = useRef(null);
|
|
5935
|
+
const justCreatedRectangleRef = useRef(false);
|
|
5912
5936
|
const [autoLabelConfig, setAutoLabelConfig] = useState({ enabled: true, threshold: 220 });
|
|
5913
5937
|
const [visibleFeatureCount, setVisibleFeatureCount] = useState(Infinity);
|
|
5914
5938
|
const lastLabelVisibility = useRef(false);
|
|
@@ -6030,6 +6054,27 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
6030
6054
|
}
|
|
6031
6055
|
return null;
|
|
6032
6056
|
}, []);
|
|
6057
|
+
const canDeleteSelected = useMemo(() => {
|
|
6058
|
+
if (selectedFeatureIds.length === 0) return false;
|
|
6059
|
+
return selectedFeatureIds.some((id) => {
|
|
6060
|
+
var _a;
|
|
6061
|
+
const feature = getFeatureById(id);
|
|
6062
|
+
if (!feature) return false;
|
|
6063
|
+
const geom = feature.geometry.type;
|
|
6064
|
+
const kind = (_a = feature.properties) == null ? void 0 : _a.kind;
|
|
6065
|
+
const isArrow = kind === "arrow" || arrowFeatureIdsRef.current.has(id);
|
|
6066
|
+
if (geom === "Point") {
|
|
6067
|
+
return kind === "text" ? !hiddenDrawingTools.includes("text") : !hiddenDrawingTools.includes("point");
|
|
6068
|
+
}
|
|
6069
|
+
if (geom === "LineString" || geom === "MultiLineString") {
|
|
6070
|
+
return isArrow ? !hiddenDrawingTools.includes("arrow") : !hiddenDrawingTools.includes("line");
|
|
6071
|
+
}
|
|
6072
|
+
if (geom === "Polygon" || geom === "MultiPolygon") {
|
|
6073
|
+
return kind === "circle" ? !hiddenDrawingTools.includes("circle") : !hiddenDrawingTools.includes("polygon");
|
|
6074
|
+
}
|
|
6075
|
+
return true;
|
|
6076
|
+
});
|
|
6077
|
+
}, [selectedFeatureIds, hiddenDrawingTools, getFeatureById]);
|
|
6033
6078
|
const applySelectionState = useCallback((nextIds, options) => {
|
|
6034
6079
|
if (!isMapLoaded || !draw.current) {
|
|
6035
6080
|
setSelectedFeatureIds(nextIds);
|
|
@@ -6074,12 +6119,12 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
6074
6119
|
if (!draw.current) return;
|
|
6075
6120
|
const currentState = {
|
|
6076
6121
|
features: draw.current.getAll().features,
|
|
6077
|
-
layers: JSON.parse(JSON.stringify(
|
|
6122
|
+
layers: JSON.parse(JSON.stringify(layersRef.current)),
|
|
6078
6123
|
selectedIds: [...selectedFeatureIds]
|
|
6079
6124
|
};
|
|
6080
6125
|
setUndoStack((prev) => [...prev.slice(-49), currentState]);
|
|
6081
6126
|
setRedoStack([]);
|
|
6082
|
-
}, [
|
|
6127
|
+
}, [selectedFeatureIds]);
|
|
6083
6128
|
const updateFeatureCount = useCallback(() => {
|
|
6084
6129
|
const drawFeatureCount = draw.current ? draw.current.getAll().features.length : 0;
|
|
6085
6130
|
let hiddenCount = 0;
|
|
@@ -7602,6 +7647,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
7602
7647
|
setActiveMode(initialDrawingMode);
|
|
7603
7648
|
}
|
|
7604
7649
|
onMapReady == null ? void 0 : onMapReady();
|
|
7650
|
+
onMapLoad == null ? void 0 : onMapLoad(mapInstance);
|
|
7605
7651
|
if (baseMapStyle !== "satellite") {
|
|
7606
7652
|
const customDef = customBasemaps == null ? void 0 : customBasemaps[baseMapStyle];
|
|
7607
7653
|
const styleUrl = (customDef == null ? void 0 : customDef.type) === "vector" && typeof customDef.style === "string" ? customDef.style : EXTERNAL_STYLE_URLS[baseMapStyle];
|
|
@@ -7782,25 +7828,20 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
7782
7828
|
}
|
|
7783
7829
|
if (!isApiAddingRef.current) {
|
|
7784
7830
|
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
|
-
});
|
|
7831
|
+
const currentLayers = layersRef.current;
|
|
7832
|
+
const newIds = newFeatures.map((f) => f.id);
|
|
7833
|
+
let targetLayer = currentLayers.find((l) => l.id === currentActiveEditingLayerId && l.visible && !l.readOnly);
|
|
7834
|
+
if (!targetLayer) targetLayer = currentLayers.find((l) => l.visible && !l.readOnly);
|
|
7835
|
+
if (!targetLayer) targetLayer = currentLayers.find((l) => !l.readOnly);
|
|
7836
|
+
if (targetLayer) {
|
|
7837
|
+
const targetId = targetLayer.id;
|
|
7838
|
+
setLayers((prev) => prev.map(
|
|
7839
|
+
(layer) => layer.id === targetId ? { ...layer, featureIds: [...layer.featureIds, ...newIds] } : layer
|
|
7840
|
+
));
|
|
7841
|
+
layersRef.current = currentLayers.map(
|
|
7842
|
+
(layer) => layer.id === targetId ? { ...layer, featureIds: [...layer.featureIds, ...newIds] } : layer
|
|
7843
|
+
);
|
|
7844
|
+
}
|
|
7804
7845
|
}
|
|
7805
7846
|
updateFeatureCount();
|
|
7806
7847
|
scheduleTimelineUpdate();
|
|
@@ -7882,6 +7923,10 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
7882
7923
|
return;
|
|
7883
7924
|
}
|
|
7884
7925
|
const ids = e.features.map((f) => f.id);
|
|
7926
|
+
if (justCreatedRectangleRef.current && ids.length === 0) {
|
|
7927
|
+
justCreatedRectangleRef.current = false;
|
|
7928
|
+
return;
|
|
7929
|
+
}
|
|
7885
7930
|
e.features.forEach((feature) => {
|
|
7886
7931
|
const fid = feature.id;
|
|
7887
7932
|
if (!originalGeometriesRef.current.has(fid)) {
|
|
@@ -8481,9 +8526,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
8481
8526
|
onTimelineChange == null ? void 0 : onTimelineChange(start, end);
|
|
8482
8527
|
},
|
|
8483
8528
|
exportGeoJSON: (layerIds) => {
|
|
8484
|
-
const targetLayerIds = layerIds ??
|
|
8529
|
+
const targetLayerIds = layerIds ?? layersRef.current.map((l) => l.id);
|
|
8485
8530
|
const allFeatures = [];
|
|
8486
|
-
|
|
8531
|
+
layersRef.current.filter((l) => targetLayerIds.includes(l.id)).forEach((layer) => {
|
|
8487
8532
|
const readOnly = readOnlyFeatures.current.get(layer.id);
|
|
8488
8533
|
if (readOnly) {
|
|
8489
8534
|
allFeatures.push(...readOnly);
|
|
@@ -8885,7 +8930,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
8885
8930
|
layerTemporalCacheRef.current.clear();
|
|
8886
8931
|
scheduleTimelineUpdate();
|
|
8887
8932
|
syncFeaturesToCustomLayers();
|
|
8888
|
-
|
|
8933
|
+
layersRef.current = prevState.layers;
|
|
8934
|
+
onUndo == null ? void 0 : onUndo(computeUndoRedoEvent(currentState, prevState));
|
|
8935
|
+
}, [undoStack, layers, selectedFeatureIds, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, applySelectionState, onUndo]);
|
|
8889
8936
|
const handleRedo = useCallback(() => {
|
|
8890
8937
|
if (redoStack.length === 0 || !draw.current) return;
|
|
8891
8938
|
const currentState = {
|
|
@@ -8910,7 +8957,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
8910
8957
|
layerTemporalCacheRef.current.clear();
|
|
8911
8958
|
scheduleTimelineUpdate();
|
|
8912
8959
|
syncFeaturesToCustomLayers();
|
|
8913
|
-
|
|
8960
|
+
layersRef.current = nextState.layers;
|
|
8961
|
+
onRedo == null ? void 0 : onRedo(computeUndoRedoEvent(currentState, nextState));
|
|
8962
|
+
}, [redoStack, layers, selectedFeatureIds, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, applySelectionState, onRedo]);
|
|
8914
8963
|
const handleClear = useCallback(() => {
|
|
8915
8964
|
if (!draw.current) return;
|
|
8916
8965
|
const activeLayer = layersRef.current.find((l) => l.id === activeEditingLayerId);
|
|
@@ -9066,7 +9115,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9066
9115
|
handleToggleEditMode();
|
|
9067
9116
|
return;
|
|
9068
9117
|
}
|
|
9069
|
-
if ((key === "delete" || key === "backspace") && !isCtrlOrCmd && selectedFeatureIds.length > 0) {
|
|
9118
|
+
if ((key === "delete" || key === "backspace") && !isCtrlOrCmd && selectedFeatureIds.length > 0 && canDeleteSelected) {
|
|
9070
9119
|
e.preventDefault();
|
|
9071
9120
|
handleDeleteSelected();
|
|
9072
9121
|
return;
|
|
@@ -9109,7 +9158,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9109
9158
|
};
|
|
9110
9159
|
container.addEventListener("keydown", handleKeyDown);
|
|
9111
9160
|
return () => container.removeEventListener("keydown", handleKeyDown);
|
|
9112
|
-
}, [isMapLoaded, enableKeyboardShortcuts, isEditMode, activeMode, handleToggleEditMode, handleUndo, handleRedo, handleModeChange, selectedFeatureIds, handleDeleteSelected]);
|
|
9161
|
+
}, [isMapLoaded, enableKeyboardShortcuts, isEditMode, activeMode, handleToggleEditMode, handleUndo, handleRedo, handleModeChange, selectedFeatureIds, handleDeleteSelected, canDeleteSelected]);
|
|
9113
9162
|
const createPointAtCoords = useCallback((lng, lat) => {
|
|
9114
9163
|
if (!draw.current || !isMapLoaded) return;
|
|
9115
9164
|
if (!isEditModeRef.current) {
|
|
@@ -9236,7 +9285,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9236
9285
|
return;
|
|
9237
9286
|
}
|
|
9238
9287
|
}
|
|
9239
|
-
if (features.length === 0) {
|
|
9288
|
+
if (features.length === 0 && !hiddenDrawingTools.includes("point")) {
|
|
9240
9289
|
e.preventDefault();
|
|
9241
9290
|
const canCreate = hasEditableLayer;
|
|
9242
9291
|
const items = [
|
|
@@ -9251,7 +9300,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9251
9300
|
];
|
|
9252
9301
|
setContextMenu({ x: e.clientX, y: e.clientY, items });
|
|
9253
9302
|
}
|
|
9254
|
-
}, [contextMenuProvider, isEditMode, hasEditableLayer, onEntityContextMenu, createPointAtCoords]);
|
|
9303
|
+
}, [contextMenuProvider, isEditMode, hasEditableLayer, onEntityContextMenu, createPointAtCoords, hiddenDrawingTools]);
|
|
9255
9304
|
useEffect(() => {
|
|
9256
9305
|
if (!isMapLoaded || !map.current) return;
|
|
9257
9306
|
const canvas = map.current.getCanvas();
|
|
@@ -10853,6 +10902,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
10853
10902
|
useEffect(() => {
|
|
10854
10903
|
if (!map.current || !isMapLoaded || !draw.current) return;
|
|
10855
10904
|
if (activeMode !== "draw_rectangle") {
|
|
10905
|
+
rectangleCornerPointRef.current = null;
|
|
10856
10906
|
setRectangleDrawCorner(null);
|
|
10857
10907
|
setRectangleDrawPreview(null);
|
|
10858
10908
|
isDrawingRectangle.current = false;
|
|
@@ -10863,18 +10913,18 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
10863
10913
|
const canvas = mapInstance.getCanvas();
|
|
10864
10914
|
mapInstance.dragPan.disable();
|
|
10865
10915
|
canvas.style.cursor = "crosshair";
|
|
10866
|
-
let cornerPoint = null;
|
|
10867
10916
|
const handleMouseDown = (e) => {
|
|
10868
10917
|
if (e.button !== 0) return;
|
|
10869
10918
|
const lngLat = mapInstance.unproject([e.offsetX, e.offsetY]);
|
|
10870
|
-
|
|
10919
|
+
rectangleCornerPointRef.current = { lngLat: [lngLat.lng, lngLat.lat] };
|
|
10871
10920
|
isDrawingRectangle.current = true;
|
|
10872
10921
|
setRectangleDrawCorner([lngLat.lng, lngLat.lat]);
|
|
10873
10922
|
};
|
|
10874
10923
|
const handleMouseMove = (e) => {
|
|
10875
|
-
if (!isDrawingRectangle.current || !
|
|
10876
|
-
const
|
|
10877
|
-
const [
|
|
10924
|
+
if (!isDrawingRectangle.current || !rectangleCornerPointRef.current) return;
|
|
10925
|
+
const rect = canvas.getBoundingClientRect();
|
|
10926
|
+
const oppositeCorner = mapInstance.unproject([e.clientX - rect.left, e.clientY - rect.top]);
|
|
10927
|
+
const [x1, y1] = rectangleCornerPointRef.current.lngLat;
|
|
10878
10928
|
const [x2, y2] = [oppositeCorner.lng, oppositeCorner.lat];
|
|
10879
10929
|
const rectCoords = [
|
|
10880
10930
|
[x1, y1],
|
|
@@ -10891,9 +10941,10 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
10891
10941
|
setRectangleDrawPreview(rectCoords);
|
|
10892
10942
|
};
|
|
10893
10943
|
const handleMouseUp = (e) => {
|
|
10894
|
-
if (!isDrawingRectangle.current || !
|
|
10895
|
-
const
|
|
10896
|
-
const [
|
|
10944
|
+
if (!isDrawingRectangle.current || !rectangleCornerPointRef.current) return;
|
|
10945
|
+
const rect = canvas.getBoundingClientRect();
|
|
10946
|
+
const oppositeCorner = mapInstance.unproject([e.clientX - rect.left, e.clientY - rect.top]);
|
|
10947
|
+
const [x1, y1] = rectangleCornerPointRef.current.lngLat;
|
|
10897
10948
|
const [x2, y2] = [oppositeCorner.lng, oppositeCorner.lat];
|
|
10898
10949
|
const width = Math.abs(x2 - x1);
|
|
10899
10950
|
const height = Math.abs(y2 - y1);
|
|
@@ -10938,22 +10989,23 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
10938
10989
|
layers: layersRef.current
|
|
10939
10990
|
}]);
|
|
10940
10991
|
setRedoStack([]);
|
|
10992
|
+
justCreatedRectangleRef.current = true;
|
|
10941
10993
|
drawInstance.changeMode("simple_select", { featureIds: [featureId] });
|
|
10942
10994
|
setActiveMode("simple_select");
|
|
10943
10995
|
setSelectedFeatureIds([featureId]);
|
|
10944
|
-
|
|
10996
|
+
setShowProperties(true);
|
|
10945
10997
|
if (onFeatureCreate) {
|
|
10946
10998
|
onFeatureCreate(rectFeature);
|
|
10947
10999
|
}
|
|
10948
11000
|
}
|
|
10949
|
-
|
|
11001
|
+
rectangleCornerPointRef.current = null;
|
|
10950
11002
|
isDrawingRectangle.current = false;
|
|
10951
11003
|
setRectangleDrawCorner(null);
|
|
10952
11004
|
setRectangleDrawPreview(null);
|
|
10953
11005
|
};
|
|
10954
11006
|
const handleKeyDown = (e) => {
|
|
10955
11007
|
if (e.key === "Escape") {
|
|
10956
|
-
|
|
11008
|
+
rectangleCornerPointRef.current = null;
|
|
10957
11009
|
isDrawingRectangle.current = false;
|
|
10958
11010
|
setRectangleDrawCorner(null);
|
|
10959
11011
|
setRectangleDrawPreview(null);
|
|
@@ -10961,13 +11013,13 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
10961
11013
|
}
|
|
10962
11014
|
};
|
|
10963
11015
|
canvas.addEventListener("mousedown", handleMouseDown);
|
|
10964
|
-
|
|
10965
|
-
|
|
11016
|
+
window.addEventListener("mousemove", handleMouseMove);
|
|
11017
|
+
window.addEventListener("mouseup", handleMouseUp);
|
|
10966
11018
|
window.addEventListener("keydown", handleKeyDown);
|
|
10967
11019
|
return () => {
|
|
10968
11020
|
canvas.removeEventListener("mousedown", handleMouseDown);
|
|
10969
|
-
|
|
10970
|
-
|
|
11021
|
+
window.removeEventListener("mousemove", handleMouseMove);
|
|
11022
|
+
window.removeEventListener("mouseup", handleMouseUp);
|
|
10971
11023
|
window.removeEventListener("keydown", handleKeyDown);
|
|
10972
11024
|
if (map.current) {
|
|
10973
11025
|
map.current.dragPan.enable();
|
|
@@ -12153,7 +12205,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
12153
12205
|
] }) });
|
|
12154
12206
|
}
|
|
12155
12207
|
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: [
|
|
12208
|
+
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
12209
|
/* @__PURE__ */ jsx(
|
|
12158
12210
|
"div",
|
|
12159
12211
|
{
|
|
@@ -12377,6 +12429,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
12377
12429
|
onRedo: handleRedo,
|
|
12378
12430
|
featureCount,
|
|
12379
12431
|
selectedCount: selectedFeatureIds.length,
|
|
12432
|
+
canDeleteSelected,
|
|
12380
12433
|
canUndo: undoStack.length > 0,
|
|
12381
12434
|
canRedo: redoStack.length > 0,
|
|
12382
12435
|
disabled: !isMapLoaded,
|
|
@@ -13381,7 +13434,7 @@ function DraggableDroneFlight({ item }) {
|
|
|
13381
13434
|
}
|
|
13382
13435
|
);
|
|
13383
13436
|
}
|
|
13384
|
-
function DebugSidebar({ onAddRandomPoints, onImportKML, canAddFeatures = true, className, onCloseMap }) {
|
|
13437
|
+
function DebugSidebar({ onAddRandomPoints, onImportKML, onAddDomMarkers, onRemoveDomMarkers, canAddFeatures = true, className, onCloseMap }) {
|
|
13385
13438
|
const [isGenerating, setIsGenerating] = useState(false);
|
|
13386
13439
|
const [isDragOver, setIsDragOver] = useState(false);
|
|
13387
13440
|
const [wizardOpen, setWizardOpen] = useState(false);
|
|
@@ -13549,6 +13602,32 @@ function DebugSidebar({ onAddRandomPoints, onImportKML, canAddFeatures = true, c
|
|
|
13549
13602
|
"Add 100k NYC Points"
|
|
13550
13603
|
]
|
|
13551
13604
|
}
|
|
13605
|
+
),
|
|
13606
|
+
onAddDomMarkers && /* @__PURE__ */ jsxs(
|
|
13607
|
+
Button,
|
|
13608
|
+
{
|
|
13609
|
+
type: "default",
|
|
13610
|
+
size: "small",
|
|
13611
|
+
onClick: onAddDomMarkers,
|
|
13612
|
+
className: "w-full flex items-center justify-center",
|
|
13613
|
+
"data-testid": "button-add-dom-markers",
|
|
13614
|
+
children: [
|
|
13615
|
+
/* @__PURE__ */ jsx(Plus, { className: "w-4 h-4 mr-2" }),
|
|
13616
|
+
"Add DOM Markers (test)"
|
|
13617
|
+
]
|
|
13618
|
+
}
|
|
13619
|
+
),
|
|
13620
|
+
onRemoveDomMarkers && /* @__PURE__ */ jsx(
|
|
13621
|
+
Button,
|
|
13622
|
+
{
|
|
13623
|
+
type: "default",
|
|
13624
|
+
size: "small",
|
|
13625
|
+
danger: true,
|
|
13626
|
+
onClick: onRemoveDomMarkers,
|
|
13627
|
+
className: "w-full flex items-center justify-center",
|
|
13628
|
+
"data-testid": "button-remove-dom-markers",
|
|
13629
|
+
children: "Remove DOM Markers"
|
|
13630
|
+
}
|
|
13552
13631
|
)
|
|
13553
13632
|
] }),
|
|
13554
13633
|
/* @__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." })
|