@octostar/map-component 0.1.38 → 0.2.0
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 +427 -113
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +427 -113
- package/dist/index.mjs.map +1 -1
- package/dist/types/components/map-editor-canvas.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/map-editor-api.d.ts +44 -17
- package/dist/types/lib/map-editor-api.d.ts.map +1 -1
- package/dist/types/lib/map-history.d.ts +68 -0
- package/dist/types/lib/map-history.d.ts.map +1 -0
- package/package.json +7 -1
package/dist/index.mjs
CHANGED
|
@@ -5168,6 +5168,90 @@ function MapDropZone({ onDrop, children }) {
|
|
|
5168
5168
|
}
|
|
5169
5169
|
);
|
|
5170
5170
|
}
|
|
5171
|
+
const DEFAULT_LIMIT = 50;
|
|
5172
|
+
const DEFAULT_COALESCE_MS = 600;
|
|
5173
|
+
class CommandHistory {
|
|
5174
|
+
constructor(limit = DEFAULT_LIMIT, coalesceMs = DEFAULT_COALESCE_MS, now = Date.now) {
|
|
5175
|
+
this.limit = limit;
|
|
5176
|
+
this.coalesceMs = coalesceMs;
|
|
5177
|
+
this.now = now;
|
|
5178
|
+
this.undoStack = [];
|
|
5179
|
+
this.redoStack = [];
|
|
5180
|
+
this.lastPush = null;
|
|
5181
|
+
}
|
|
5182
|
+
get canUndo() {
|
|
5183
|
+
return this.undoStack.length > 0;
|
|
5184
|
+
}
|
|
5185
|
+
get canRedo() {
|
|
5186
|
+
return this.redoStack.length > 0;
|
|
5187
|
+
}
|
|
5188
|
+
/** Push a new command. Clears the redo stack (a new action forks history). */
|
|
5189
|
+
push(command) {
|
|
5190
|
+
const at = this.now();
|
|
5191
|
+
const key = command.coalesceKey;
|
|
5192
|
+
const top = this.undoStack[this.undoStack.length - 1];
|
|
5193
|
+
if (key && top && this.lastPush && this.lastPush.key === key && at - this.lastPush.at < this.coalesceMs) {
|
|
5194
|
+
top.redo = command.redo;
|
|
5195
|
+
this.lastPush = { key, at };
|
|
5196
|
+
this.redoStack = [];
|
|
5197
|
+
return;
|
|
5198
|
+
}
|
|
5199
|
+
this.undoStack.push(command);
|
|
5200
|
+
if (this.undoStack.length > this.limit) this.undoStack.shift();
|
|
5201
|
+
this.redoStack = [];
|
|
5202
|
+
this.lastPush = key ? { key, at } : null;
|
|
5203
|
+
}
|
|
5204
|
+
/** Reverse the most recent command. Returns false if nothing to undo. */
|
|
5205
|
+
undo() {
|
|
5206
|
+
const command = this.undoStack.pop();
|
|
5207
|
+
if (!command) return false;
|
|
5208
|
+
this.lastPush = null;
|
|
5209
|
+
command.undo();
|
|
5210
|
+
this.redoStack.push(command);
|
|
5211
|
+
return true;
|
|
5212
|
+
}
|
|
5213
|
+
/** Re-apply the most recently undone command. Returns false if none. */
|
|
5214
|
+
redo() {
|
|
5215
|
+
const command = this.redoStack.pop();
|
|
5216
|
+
if (!command) return false;
|
|
5217
|
+
this.lastPush = null;
|
|
5218
|
+
command.redo();
|
|
5219
|
+
this.undoStack.push(command);
|
|
5220
|
+
return true;
|
|
5221
|
+
}
|
|
5222
|
+
clear() {
|
|
5223
|
+
this.undoStack = [];
|
|
5224
|
+
this.redoStack = [];
|
|
5225
|
+
this.lastPush = null;
|
|
5226
|
+
}
|
|
5227
|
+
}
|
|
5228
|
+
function useMapHistory(options) {
|
|
5229
|
+
const historyRef = useRef(null);
|
|
5230
|
+
if (historyRef.current === null) {
|
|
5231
|
+
historyRef.current = new CommandHistory(options == null ? void 0 : options.limit, options == null ? void 0 : options.coalesceMs);
|
|
5232
|
+
}
|
|
5233
|
+
const history = historyRef.current;
|
|
5234
|
+
const [, setTick] = useState(0);
|
|
5235
|
+
const rerender = useCallback(() => setTick((t) => t + 1), []);
|
|
5236
|
+
const push = useCallback(
|
|
5237
|
+
(command) => {
|
|
5238
|
+
history.push(command);
|
|
5239
|
+
rerender();
|
|
5240
|
+
},
|
|
5241
|
+
[history, rerender]
|
|
5242
|
+
);
|
|
5243
|
+
const undo = useCallback(() => {
|
|
5244
|
+
if (history.undo()) rerender();
|
|
5245
|
+
}, [history, rerender]);
|
|
5246
|
+
const redo = useCallback(() => {
|
|
5247
|
+
if (history.redo()) rerender();
|
|
5248
|
+
}, [history, rerender]);
|
|
5249
|
+
const clear = useCallback(() => {
|
|
5250
|
+
history.clear();
|
|
5251
|
+
rerender();
|
|
5252
|
+
}, [history, rerender]);
|
|
5253
|
+
return { push, undo, redo, clear, canUndo: history.canUndo, canRedo: history.canRedo };
|
|
5254
|
+
}
|
|
5171
5255
|
const OTHER_BUCKET_KEY = "__other__";
|
|
5172
5256
|
const OTHER_BUCKET_LABEL = "Other";
|
|
5173
5257
|
const OTHER_BUCKET_COLOR = "#9ca3af";
|
|
@@ -5818,19 +5902,6 @@ const EXTERNAL_STYLE_URLS = {
|
|
|
5818
5902
|
streets: "https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json",
|
|
5819
5903
|
dark: "https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json"
|
|
5820
5904
|
};
|
|
5821
|
-
function computeUndoRedoEvent(fromState, toState) {
|
|
5822
|
-
const fromIds = new Set(fromState.features.map((f) => f.id));
|
|
5823
|
-
const toIds = new Set(toState.features.map((f) => f.id));
|
|
5824
|
-
const restoredFeatures = toState.features.filter((f) => !fromIds.has(f.id)).map((f) => {
|
|
5825
|
-
var _a;
|
|
5826
|
-
return {
|
|
5827
|
-
feature: f,
|
|
5828
|
-
layerId: ((_a = toState.layers.find((l) => l.featureIds.includes(f.id))) == null ? void 0 : _a.id) ?? null
|
|
5829
|
-
};
|
|
5830
|
-
});
|
|
5831
|
-
const removedFeatureIds = fromState.features.filter((f) => !toIds.has(f.id)).map((f) => f.id);
|
|
5832
|
-
return { restoredFeatures, removedFeatureIds };
|
|
5833
|
-
}
|
|
5834
5905
|
const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
5835
5906
|
className,
|
|
5836
5907
|
enableDrawing = true,
|
|
@@ -5858,8 +5929,6 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
5858
5929
|
onFeatureCreate,
|
|
5859
5930
|
onFeatureUpdate,
|
|
5860
5931
|
onFeatureDelete,
|
|
5861
|
-
onUndo,
|
|
5862
|
-
onRedo,
|
|
5863
5932
|
onLayerChange,
|
|
5864
5933
|
onActiveEditingLayerChange,
|
|
5865
5934
|
onTimelineChange,
|
|
@@ -5950,8 +6019,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
5950
6019
|
{ id: "default", name: "Default Layer", visible: true, featureIds: [] }
|
|
5951
6020
|
]);
|
|
5952
6021
|
const [activeEditingLayerId, setActiveEditingLayerId] = useState("default");
|
|
5953
|
-
const
|
|
5954
|
-
const
|
|
6022
|
+
const history = useMapHistory();
|
|
6023
|
+
const pendingCaptureRef = useRef(null);
|
|
6024
|
+
const preDragRef = useRef(null);
|
|
5955
6025
|
const [isEditMode, setIsEditMode] = useState(false);
|
|
5956
6026
|
const [currentMapStyle, setCurrentMapStyle] = useState(baseMapStyle);
|
|
5957
6027
|
const [measureMode, setMeasureMode] = useState("none");
|
|
@@ -6161,16 +6231,6 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
6161
6231
|
});
|
|
6162
6232
|
}
|
|
6163
6233
|
}, [isMapLoaded, getFeatureById, onFeatureSelect]);
|
|
6164
|
-
const saveStateForUndo = useCallback(() => {
|
|
6165
|
-
if (!draw.current) return;
|
|
6166
|
-
const currentState = {
|
|
6167
|
-
features: draw.current.getAll().features,
|
|
6168
|
-
layers: JSON.parse(JSON.stringify(layersRef.current)),
|
|
6169
|
-
selectedIds: [...selectedFeatureIds]
|
|
6170
|
-
};
|
|
6171
|
-
setUndoStack((prev) => [...prev.slice(-49), currentState]);
|
|
6172
|
-
setRedoStack([]);
|
|
6173
|
-
}, [selectedFeatureIds]);
|
|
6174
6234
|
const updateFeatureCount = useCallback(() => {
|
|
6175
6235
|
const drawFeatureCount = draw.current ? draw.current.getAll().features.length : 0;
|
|
6176
6236
|
let hiddenCount = 0;
|
|
@@ -6468,7 +6528,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
6468
6528
|
}
|
|
6469
6529
|
});
|
|
6470
6530
|
}
|
|
6471
|
-
const isFeatureSelected = selectedIds.includes(featureId) ? 1 : 0;
|
|
6531
|
+
const isFeatureSelected = (enableSelectionRef.current || enableDrawingRef.current) && selectedIds.includes(featureId) ? 1 : 0;
|
|
6472
6532
|
let labelPriority = 100;
|
|
6473
6533
|
if (isFeatureSelected) {
|
|
6474
6534
|
labelPriority = 0;
|
|
@@ -6878,6 +6938,287 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
6878
6938
|
updateTimelineStore();
|
|
6879
6939
|
}, 300);
|
|
6880
6940
|
}, [updateTimelineStore]);
|
|
6941
|
+
const collectHistoryFeatures = useCallback(
|
|
6942
|
+
(overrides) => {
|
|
6943
|
+
var _a;
|
|
6944
|
+
const featureToLayer = /* @__PURE__ */ new Map();
|
|
6945
|
+
for (const l of layersRef.current) {
|
|
6946
|
+
if (((_a = l.metadata) == null ? void 0 : _a.dataViewing) === true) continue;
|
|
6947
|
+
for (const fid of l.featureIds) featureToLayer.set(fid, l.id);
|
|
6948
|
+
}
|
|
6949
|
+
const result = /* @__PURE__ */ new Map();
|
|
6950
|
+
if (draw.current) {
|
|
6951
|
+
for (const f of draw.current.getAll().features) {
|
|
6952
|
+
if (f.id == null) continue;
|
|
6953
|
+
const id = String(f.id);
|
|
6954
|
+
result.set(id, {
|
|
6955
|
+
feature: f,
|
|
6956
|
+
layerId: featureToLayer.get(id) ?? activeEditingLayerIdRef.current,
|
|
6957
|
+
store: "draw"
|
|
6958
|
+
});
|
|
6959
|
+
}
|
|
6960
|
+
}
|
|
6961
|
+
readOnlyFeatures.current.forEach((features, layerId) => {
|
|
6962
|
+
var _a2;
|
|
6963
|
+
const layer = layersRef.current.find((l) => l.id === layerId);
|
|
6964
|
+
if (((_a2 = layer == null ? void 0 : layer.metadata) == null ? void 0 : _a2.dataViewing) === true) return;
|
|
6965
|
+
for (const f of features) {
|
|
6966
|
+
if (f.id == null) continue;
|
|
6967
|
+
result.set(String(f.id), { feature: f, layerId, store: "readOnly" });
|
|
6968
|
+
}
|
|
6969
|
+
});
|
|
6970
|
+
hiddenFeatures.current.forEach((features, layerId) => {
|
|
6971
|
+
for (const f of features) {
|
|
6972
|
+
if (f.id == null) continue;
|
|
6973
|
+
result.set(String(f.id), { feature: f, layerId, store: "hidden" });
|
|
6974
|
+
}
|
|
6975
|
+
});
|
|
6976
|
+
if (overrides == null ? void 0 : overrides.excludeDrawIds) {
|
|
6977
|
+
overrides.excludeDrawIds.forEach((id) => result.delete(id));
|
|
6978
|
+
}
|
|
6979
|
+
if (overrides == null ? void 0 : overrides.addDrawFeatures) {
|
|
6980
|
+
for (const f of overrides.addDrawFeatures) {
|
|
6981
|
+
if (f.id == null) continue;
|
|
6982
|
+
const id = String(f.id);
|
|
6983
|
+
const layerId = featureToLayer.get(id) ?? activeEditingLayerIdRef.current;
|
|
6984
|
+
const layer = layersRef.current.find((l) => l.id === layerId);
|
|
6985
|
+
result.set(id, { feature: f, layerId, store: (layer == null ? void 0 : layer.readOnly) ? "readOnly" : "draw" });
|
|
6986
|
+
}
|
|
6987
|
+
}
|
|
6988
|
+
return result;
|
|
6989
|
+
},
|
|
6990
|
+
[]
|
|
6991
|
+
);
|
|
6992
|
+
const collectHistoryLayers = useCallback(() => {
|
|
6993
|
+
var _a;
|
|
6994
|
+
const result = /* @__PURE__ */ new Map();
|
|
6995
|
+
for (const l of layersRef.current) {
|
|
6996
|
+
if (((_a = l.metadata) == null ? void 0 : _a.dataViewing) === true) continue;
|
|
6997
|
+
result.set(l.id, { ...l, featureIds: [...l.featureIds] });
|
|
6998
|
+
}
|
|
6999
|
+
return result;
|
|
7000
|
+
}, []);
|
|
7001
|
+
const cleanupOrphanLayerSources = useCallback((liveLayerIds) => {
|
|
7002
|
+
clusterPieManagers.current.forEach((mgr, layerId) => {
|
|
7003
|
+
if (!liveLayerIds.has(layerId)) {
|
|
7004
|
+
try {
|
|
7005
|
+
mgr.destroy();
|
|
7006
|
+
} catch {
|
|
7007
|
+
}
|
|
7008
|
+
clusterPieManagers.current.delete(layerId);
|
|
7009
|
+
}
|
|
7010
|
+
});
|
|
7011
|
+
const m = map.current;
|
|
7012
|
+
if (!m) return;
|
|
7013
|
+
let style;
|
|
7014
|
+
try {
|
|
7015
|
+
style = m.getStyle();
|
|
7016
|
+
} catch {
|
|
7017
|
+
return;
|
|
7018
|
+
}
|
|
7019
|
+
const layerPrefixes = ["heatmap-layer-", "cluster-count-", "clusters-", "unclustered-point-"];
|
|
7020
|
+
const sourcePrefixes = ["heatmap-source-", "cluster-source-"];
|
|
7021
|
+
((style == null ? void 0 : style.layers) ?? []).forEach((sl) => {
|
|
7022
|
+
const prefix = layerPrefixes.find((p) => sl.id.startsWith(p));
|
|
7023
|
+
if (!prefix) return;
|
|
7024
|
+
const id = sl.id.slice(prefix.length);
|
|
7025
|
+
if (!liveLayerIds.has(id) && m.getLayer(sl.id)) {
|
|
7026
|
+
try {
|
|
7027
|
+
m.removeLayer(sl.id);
|
|
7028
|
+
} catch {
|
|
7029
|
+
}
|
|
7030
|
+
}
|
|
7031
|
+
});
|
|
7032
|
+
Object.keys((style == null ? void 0 : style.sources) ?? {}).forEach((sid) => {
|
|
7033
|
+
const prefix = sourcePrefixes.find((p) => sid.startsWith(p));
|
|
7034
|
+
if (!prefix) return;
|
|
7035
|
+
const id = sid.slice(prefix.length);
|
|
7036
|
+
if (!liveLayerIds.has(id) && m.getSource(sid)) {
|
|
7037
|
+
try {
|
|
7038
|
+
m.removeSource(sid);
|
|
7039
|
+
} catch {
|
|
7040
|
+
}
|
|
7041
|
+
}
|
|
7042
|
+
});
|
|
7043
|
+
}, []);
|
|
7044
|
+
useEffect(() => {
|
|
7045
|
+
if (!isMapLoaded) return;
|
|
7046
|
+
cleanupOrphanLayerSources(new Set(layers.map((l) => l.id)));
|
|
7047
|
+
}, [layers, isMapLoaded, cleanupOrphanLayerSources]);
|
|
7048
|
+
const applyHistoryState = useCallback(
|
|
7049
|
+
(featureIds, layerIds, targetFeatures, targetLayers) => {
|
|
7050
|
+
isApiAddingRef.current = true;
|
|
7051
|
+
isSelectingReadOnlyRef.current = true;
|
|
7052
|
+
try {
|
|
7053
|
+
featureIds.forEach((id) => {
|
|
7054
|
+
var _a;
|
|
7055
|
+
try {
|
|
7056
|
+
(_a = draw.current) == null ? void 0 : _a.delete(id);
|
|
7057
|
+
} catch {
|
|
7058
|
+
}
|
|
7059
|
+
});
|
|
7060
|
+
readOnlyFeatures.current.forEach((features, layerId) => {
|
|
7061
|
+
const filtered = features.filter((f) => !featureIds.has(String(f.id)));
|
|
7062
|
+
if (filtered.length !== features.length) readOnlyFeatures.current.set(layerId, filtered);
|
|
7063
|
+
});
|
|
7064
|
+
hiddenFeatures.current.forEach((features, layerId) => {
|
|
7065
|
+
const filtered = features.filter((f) => !featureIds.has(String(f.id)));
|
|
7066
|
+
if (filtered.length !== features.length) hiddenFeatures.current.set(layerId, filtered);
|
|
7067
|
+
});
|
|
7068
|
+
const readOnlyAdds = /* @__PURE__ */ new Map();
|
|
7069
|
+
const hiddenAdds = /* @__PURE__ */ new Map();
|
|
7070
|
+
featureIds.forEach((id) => {
|
|
7071
|
+
var _a;
|
|
7072
|
+
const entry = targetFeatures.get(id);
|
|
7073
|
+
if (!entry) return;
|
|
7074
|
+
if (entry.store === "draw") {
|
|
7075
|
+
try {
|
|
7076
|
+
(_a = draw.current) == null ? void 0 : _a.add(entry.feature);
|
|
7077
|
+
} catch {
|
|
7078
|
+
}
|
|
7079
|
+
} else if (entry.store === "readOnly") {
|
|
7080
|
+
const list = readOnlyAdds.get(entry.layerId) ?? [];
|
|
7081
|
+
list.push(entry.feature);
|
|
7082
|
+
readOnlyAdds.set(entry.layerId, list);
|
|
7083
|
+
} else {
|
|
7084
|
+
const list = hiddenAdds.get(entry.layerId) ?? [];
|
|
7085
|
+
list.push(entry.feature);
|
|
7086
|
+
hiddenAdds.set(entry.layerId, list);
|
|
7087
|
+
}
|
|
7088
|
+
});
|
|
7089
|
+
readOnlyAdds.forEach((features, layerId) => {
|
|
7090
|
+
readOnlyFeatures.current.set(layerId, [...readOnlyFeatures.current.get(layerId) ?? [], ...features]);
|
|
7091
|
+
});
|
|
7092
|
+
hiddenAdds.forEach((features, layerId) => {
|
|
7093
|
+
hiddenFeatures.current.set(layerId, [...hiddenFeatures.current.get(layerId) ?? [], ...features]);
|
|
7094
|
+
});
|
|
7095
|
+
const next = layersRef.current.slice();
|
|
7096
|
+
layerIds.forEach((id) => {
|
|
7097
|
+
const target = targetLayers.get(id);
|
|
7098
|
+
const idx = next.findIndex((l) => l.id === id);
|
|
7099
|
+
if (target && idx === -1) next.push(target);
|
|
7100
|
+
else if (target && idx !== -1) next[idx] = target;
|
|
7101
|
+
else if (!target && idx !== -1) {
|
|
7102
|
+
next.splice(idx, 1);
|
|
7103
|
+
readOnlyFeatures.current.delete(id);
|
|
7104
|
+
hiddenFeatures.current.delete(id);
|
|
7105
|
+
layerTemporalCacheRef.current.delete(id);
|
|
7106
|
+
}
|
|
7107
|
+
});
|
|
7108
|
+
layersRef.current = next;
|
|
7109
|
+
setLayers(next);
|
|
7110
|
+
} finally {
|
|
7111
|
+
isApiAddingRef.current = false;
|
|
7112
|
+
}
|
|
7113
|
+
cleanupOrphanLayerSources(new Set(layersRef.current.map((l) => l.id)));
|
|
7114
|
+
layerTemporalCacheRef.current.clear();
|
|
7115
|
+
updateFeatureCount();
|
|
7116
|
+
scheduleTimelineUpdate();
|
|
7117
|
+
syncFeaturesToCustomLayers();
|
|
7118
|
+
queueMicrotask(() => {
|
|
7119
|
+
isSelectingReadOnlyRef.current = false;
|
|
7120
|
+
});
|
|
7121
|
+
},
|
|
7122
|
+
[cleanupOrphanLayerSources, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers]
|
|
7123
|
+
);
|
|
7124
|
+
const buildDiffCommand = useCallback(
|
|
7125
|
+
(label, coalesceKey, before, after, beforeLayers, afterLayers, beforeSelectedIds, afterSelectedIds) => {
|
|
7126
|
+
const featureIds = /* @__PURE__ */ new Set();
|
|
7127
|
+
before.forEach((_v, k) => featureIds.add(k));
|
|
7128
|
+
after.forEach((_v, k) => featureIds.add(k));
|
|
7129
|
+
const layerIds = /* @__PURE__ */ new Set();
|
|
7130
|
+
beforeLayers.forEach((_v, k) => layerIds.add(k));
|
|
7131
|
+
afterLayers.forEach((_v, k) => layerIds.add(k));
|
|
7132
|
+
const featuresChanged = Array.from(featureIds).some((id) => {
|
|
7133
|
+
const b = before.get(id);
|
|
7134
|
+
const a = after.get(id);
|
|
7135
|
+
if (!b || !a || b.layerId !== a.layerId) return true;
|
|
7136
|
+
if (JSON.stringify(b.feature.geometry) !== JSON.stringify(a.feature.geometry)) return true;
|
|
7137
|
+
return JSON.stringify(b.feature.properties ?? {}) !== JSON.stringify(a.feature.properties ?? {});
|
|
7138
|
+
});
|
|
7139
|
+
const layersChanged = featuresChanged || Array.from(layerIds).some((id) => {
|
|
7140
|
+
const b = beforeLayers.get(id);
|
|
7141
|
+
const a = afterLayers.get(id);
|
|
7142
|
+
return !b || !a || JSON.stringify(b) !== JSON.stringify(a);
|
|
7143
|
+
});
|
|
7144
|
+
if (!featuresChanged && !layersChanged) return null;
|
|
7145
|
+
const pick = (src, keys) => {
|
|
7146
|
+
const out = /* @__PURE__ */ new Map();
|
|
7147
|
+
keys.forEach((k) => {
|
|
7148
|
+
const v = src.get(k);
|
|
7149
|
+
if (v !== void 0) out.set(k, v);
|
|
7150
|
+
});
|
|
7151
|
+
return out;
|
|
7152
|
+
};
|
|
7153
|
+
const beforeF = pick(before, featureIds);
|
|
7154
|
+
const afterF = pick(after, featureIds);
|
|
7155
|
+
const beforeL = pick(beforeLayers, layerIds);
|
|
7156
|
+
const afterL = pick(afterLayers, layerIds);
|
|
7157
|
+
return {
|
|
7158
|
+
label,
|
|
7159
|
+
coalesceKey,
|
|
7160
|
+
undo: () => {
|
|
7161
|
+
applyHistoryState(featureIds, layerIds, beforeF, beforeL);
|
|
7162
|
+
applySelectionState(beforeSelectedIds, { focusProperties: false });
|
|
7163
|
+
},
|
|
7164
|
+
redo: () => {
|
|
7165
|
+
applyHistoryState(featureIds, layerIds, afterF, afterL);
|
|
7166
|
+
applySelectionState(afterSelectedIds, { focusProperties: false });
|
|
7167
|
+
}
|
|
7168
|
+
};
|
|
7169
|
+
},
|
|
7170
|
+
[applyHistoryState, applySelectionState]
|
|
7171
|
+
);
|
|
7172
|
+
const finalizeCapture = useCallback(() => {
|
|
7173
|
+
const pending = pendingCaptureRef.current;
|
|
7174
|
+
pendingCaptureRef.current = null;
|
|
7175
|
+
if (!pending) return;
|
|
7176
|
+
const after = collectHistoryFeatures();
|
|
7177
|
+
const afterLayers = collectHistoryLayers();
|
|
7178
|
+
const command = buildDiffCommand(
|
|
7179
|
+
pending.label,
|
|
7180
|
+
pending.coalesceKey,
|
|
7181
|
+
pending.before,
|
|
7182
|
+
after,
|
|
7183
|
+
pending.beforeLayers,
|
|
7184
|
+
afterLayers,
|
|
7185
|
+
pending.beforeSelectedIds,
|
|
7186
|
+
[...selectedFeatureIdsRef.current]
|
|
7187
|
+
);
|
|
7188
|
+
if (command) {
|
|
7189
|
+
history.push(command);
|
|
7190
|
+
}
|
|
7191
|
+
}, [collectHistoryFeatures, collectHistoryLayers, buildDiffCommand, history]);
|
|
7192
|
+
const saveStateForUndo = useCallback(
|
|
7193
|
+
(label = "edit", options) => {
|
|
7194
|
+
if (isApiAddingRef.current) return;
|
|
7195
|
+
if (pendingCaptureRef.current) return;
|
|
7196
|
+
pendingCaptureRef.current = {
|
|
7197
|
+
label,
|
|
7198
|
+
coalesceKey: options == null ? void 0 : options.coalesceKey,
|
|
7199
|
+
before: collectHistoryFeatures({
|
|
7200
|
+
excludeDrawIds: options == null ? void 0 : options.excludeDrawIds,
|
|
7201
|
+
addDrawFeatures: options == null ? void 0 : options.addDrawFeatures
|
|
7202
|
+
}),
|
|
7203
|
+
beforeLayers: collectHistoryLayers(),
|
|
7204
|
+
beforeSelectedIds: [...selectedFeatureIdsRef.current]
|
|
7205
|
+
};
|
|
7206
|
+
requestAnimationFrame(finalizeCapture);
|
|
7207
|
+
},
|
|
7208
|
+
[collectHistoryFeatures, collectHistoryLayers, finalizeCapture]
|
|
7209
|
+
);
|
|
7210
|
+
const recordMoveFromPreDrag = useCallback(() => {
|
|
7211
|
+
const pre = preDragRef.current;
|
|
7212
|
+
preDragRef.current = null;
|
|
7213
|
+
if (!pre || isApiAddingRef.current || pendingCaptureRef.current) return;
|
|
7214
|
+
pendingCaptureRef.current = {
|
|
7215
|
+
label: "move feature",
|
|
7216
|
+
before: pre.features,
|
|
7217
|
+
beforeLayers: pre.layers,
|
|
7218
|
+
beforeSelectedIds: pre.selectedIds
|
|
7219
|
+
};
|
|
7220
|
+
requestAnimationFrame(finalizeCapture);
|
|
7221
|
+
}, [finalizeCapture]);
|
|
6881
7222
|
useEffect(() => {
|
|
6882
7223
|
if (!mapContainer.current || map.current) return;
|
|
6883
7224
|
try {
|
|
@@ -7806,6 +8147,15 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
7806
8147
|
}
|
|
7807
8148
|
});
|
|
7808
8149
|
const processedFeatureIds = /* @__PURE__ */ new Set();
|
|
8150
|
+
mapInstance.on("mousedown", () => {
|
|
8151
|
+
if (draw.current && draw.current.getSelectedIds().length > 0) {
|
|
8152
|
+
preDragRef.current = {
|
|
8153
|
+
features: collectHistoryFeatures(),
|
|
8154
|
+
layers: collectHistoryLayers(),
|
|
8155
|
+
selectedIds: [...selectedFeatureIdsRef.current]
|
|
8156
|
+
};
|
|
8157
|
+
}
|
|
8158
|
+
});
|
|
7809
8159
|
mapInstance.on("draw.create", (e) => {
|
|
7810
8160
|
justCreatedFeatureRef.current = true;
|
|
7811
8161
|
setTimeout(() => {
|
|
@@ -7895,7 +8245,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
7895
8245
|
}
|
|
7896
8246
|
updateFeatureCount();
|
|
7897
8247
|
scheduleTimelineUpdate();
|
|
7898
|
-
saveStateForUndo(
|
|
8248
|
+
saveStateForUndo("draw feature", {
|
|
8249
|
+
excludeDrawIds: new Set(newFeatures.map((f) => String(f.id)))
|
|
8250
|
+
});
|
|
7899
8251
|
syncRef.current();
|
|
7900
8252
|
setTimeout(() => {
|
|
7901
8253
|
setActiveMode("simple_select");
|
|
@@ -7952,7 +8304,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
7952
8304
|
syncRef.current();
|
|
7953
8305
|
if (e.action === "change_coordinates" && !hasRevertedFeatures) {
|
|
7954
8306
|
scheduleTimelineUpdate();
|
|
7955
|
-
|
|
8307
|
+
recordMoveFromPreDrag();
|
|
7956
8308
|
}
|
|
7957
8309
|
});
|
|
7958
8310
|
mapInstance.on("draw.delete", (e) => {
|
|
@@ -7968,7 +8320,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
7968
8320
|
});
|
|
7969
8321
|
updateFeatureCount();
|
|
7970
8322
|
scheduleTimelineUpdate();
|
|
7971
|
-
saveStateForUndo();
|
|
8323
|
+
saveStateForUndo("delete feature", { addDrawFeatures: e.features });
|
|
7972
8324
|
syncRef.current();
|
|
7973
8325
|
onFeatureDelete == null ? void 0 : onFeatureDelete(deletedIds);
|
|
7974
8326
|
});
|
|
@@ -8008,6 +8360,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
8008
8360
|
});
|
|
8009
8361
|
mapInstance.on("click", (e) => {
|
|
8010
8362
|
var _a;
|
|
8363
|
+
if (!enableSelectionRef.current) return;
|
|
8011
8364
|
if (e.originalEvent.button !== 0) return;
|
|
8012
8365
|
if (contextMenuFiredRef.current) return;
|
|
8013
8366
|
if (Date.now() - shiftSelectionRef.current.completedAt < 300) return;
|
|
@@ -8284,6 +8637,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
8284
8637
|
listLayers: () => [...layersRef.current],
|
|
8285
8638
|
addLayer: (name, geojson, options) => {
|
|
8286
8639
|
if (!isMapLoadedRef.current) return "";
|
|
8640
|
+
if (options == null ? void 0 : options.recordHistory) saveStateForUndo(`add layer "${name}"`);
|
|
8287
8641
|
const layerId = `layer-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
8288
8642
|
const newLayer = {
|
|
8289
8643
|
id: layerId,
|
|
@@ -8376,9 +8730,10 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
8376
8730
|
}
|
|
8377
8731
|
return newLayer.id;
|
|
8378
8732
|
},
|
|
8379
|
-
removeLayer: (layerId) => {
|
|
8733
|
+
removeLayer: (layerId, options) => {
|
|
8380
8734
|
const layer = layersRef.current.find((l) => l.id === layerId);
|
|
8381
8735
|
if (!layer || !isMapLoadedRef.current) return false;
|
|
8736
|
+
if (options == null ? void 0 : options.recordHistory) saveStateForUndo(`remove layer "${layer.name}"`);
|
|
8382
8737
|
if (draw.current && !layer.readOnly) {
|
|
8383
8738
|
layer.featureIds.forEach((id) => {
|
|
8384
8739
|
try {
|
|
@@ -8455,10 +8810,11 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
8455
8810
|
syncRef.current();
|
|
8456
8811
|
});
|
|
8457
8812
|
},
|
|
8458
|
-
addFeatures: (layerId, features) => {
|
|
8813
|
+
addFeatures: (layerId, features, options) => {
|
|
8459
8814
|
var _a;
|
|
8460
8815
|
const layer = layersRef.current.find((l) => l.id === layerId);
|
|
8461
8816
|
if (!layer || !isMapLoadedRef.current) return [];
|
|
8817
|
+
if (options == null ? void 0 : options.recordHistory) saveStateForUndo("add features");
|
|
8462
8818
|
if (layer.readOnly) {
|
|
8463
8819
|
const existing = readOnlyFeatures.current.get(layerId) || [];
|
|
8464
8820
|
let layerHasTemporal = ((_a = layerTemporalCacheRef.current.get(layerId)) == null ? void 0 : _a.hasTemporal) ?? false;
|
|
@@ -8528,8 +8884,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
8528
8884
|
syncFeaturesToCustomLayers();
|
|
8529
8885
|
return addedIds;
|
|
8530
8886
|
},
|
|
8531
|
-
removeFeatures: (featureIds) => {
|
|
8887
|
+
removeFeatures: (featureIds, options) => {
|
|
8532
8888
|
if (!isMapLoaded) return;
|
|
8889
|
+
if (options == null ? void 0 : options.recordHistory) saveStateForUndo("remove features");
|
|
8533
8890
|
const idSet = new Set(featureIds);
|
|
8534
8891
|
if (draw.current) {
|
|
8535
8892
|
featureIds.forEach((id) => {
|
|
@@ -8905,6 +9262,13 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
8905
9262
|
end: ts.rangeEnd
|
|
8906
9263
|
};
|
|
8907
9264
|
},
|
|
9265
|
+
// --- Undo / redo (also driven by the toolbar buttons + Ctrl/Cmd+Z) ---
|
|
9266
|
+
undo: () => history.undo(),
|
|
9267
|
+
redo: () => history.redo(),
|
|
9268
|
+
canUndo: () => history.canUndo,
|
|
9269
|
+
canRedo: () => history.canRedo,
|
|
9270
|
+
clearHistory: () => history.clear(),
|
|
9271
|
+
pushHistory: (command) => history.push(command),
|
|
8908
9272
|
getMapUnsavedCount: () => {
|
|
8909
9273
|
if (!draw.current) return 0;
|
|
8910
9274
|
const allFeatures = draw.current.getAll().features;
|
|
@@ -8928,7 +9292,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
8928
9292
|
var _a;
|
|
8929
9293
|
(_a = restoreEnrichedGeoJSONRef.current) == null ? void 0 : _a.call(restoreEnrichedGeoJSONRef, enriched);
|
|
8930
9294
|
}
|
|
8931
|
-
}), [layers, isEditMode, isMapLoaded, getSelectedFeatures, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, onFeatureDelete, onTimelineChange, activeEditingLayerId, currentMapStyle, activeMode]);
|
|
9295
|
+
}), [layers, isEditMode, isMapLoaded, getSelectedFeatures, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, onFeatureDelete, onTimelineChange, activeEditingLayerId, currentMapStyle, activeMode, saveStateForUndo, history]);
|
|
8932
9296
|
const handleModeChange = useCallback((mode) => {
|
|
8933
9297
|
if (!draw.current || !isMapLoaded) return;
|
|
8934
9298
|
if (!hasVisibleLayers && mode !== "simple_select" && mode !== "view_select") {
|
|
@@ -8964,60 +9328,6 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
8964
9328
|
setActiveMode(mode);
|
|
8965
9329
|
draw.current.changeMode(mode);
|
|
8966
9330
|
}, [isMapLoaded, hasVisibleLayers, toast]);
|
|
8967
|
-
const handleUndo = useCallback(() => {
|
|
8968
|
-
if (undoStack.length === 0 || !draw.current) return;
|
|
8969
|
-
const currentState = {
|
|
8970
|
-
features: draw.current.getAll().features,
|
|
8971
|
-
layers: JSON.parse(JSON.stringify(layers)),
|
|
8972
|
-
selectedIds: [...selectedFeatureIds]
|
|
8973
|
-
};
|
|
8974
|
-
const prevState = undoStack[undoStack.length - 1];
|
|
8975
|
-
isSelectingReadOnlyRef.current = true;
|
|
8976
|
-
draw.current.deleteAll();
|
|
8977
|
-
isApiAddingRef.current = true;
|
|
8978
|
-
try {
|
|
8979
|
-
prevState.features.forEach((f) => draw.current.add(f));
|
|
8980
|
-
} finally {
|
|
8981
|
-
isApiAddingRef.current = false;
|
|
8982
|
-
}
|
|
8983
|
-
setLayers(prevState.layers);
|
|
8984
|
-
applySelectionState(prevState.selectedIds, { focusProperties: false });
|
|
8985
|
-
setUndoStack((prev) => prev.slice(0, -1));
|
|
8986
|
-
setRedoStack((prev) => [...prev, currentState]);
|
|
8987
|
-
updateFeatureCount();
|
|
8988
|
-
layerTemporalCacheRef.current.clear();
|
|
8989
|
-
scheduleTimelineUpdate();
|
|
8990
|
-
syncFeaturesToCustomLayers();
|
|
8991
|
-
layersRef.current = prevState.layers;
|
|
8992
|
-
onUndo == null ? void 0 : onUndo(computeUndoRedoEvent(currentState, prevState));
|
|
8993
|
-
}, [undoStack, layers, selectedFeatureIds, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, applySelectionState, onUndo]);
|
|
8994
|
-
const handleRedo = useCallback(() => {
|
|
8995
|
-
if (redoStack.length === 0 || !draw.current) return;
|
|
8996
|
-
const currentState = {
|
|
8997
|
-
features: draw.current.getAll().features,
|
|
8998
|
-
layers: JSON.parse(JSON.stringify(layers)),
|
|
8999
|
-
selectedIds: [...selectedFeatureIds]
|
|
9000
|
-
};
|
|
9001
|
-
const nextState = redoStack[redoStack.length - 1];
|
|
9002
|
-
isSelectingReadOnlyRef.current = true;
|
|
9003
|
-
draw.current.deleteAll();
|
|
9004
|
-
isApiAddingRef.current = true;
|
|
9005
|
-
try {
|
|
9006
|
-
nextState.features.forEach((f) => draw.current.add(f));
|
|
9007
|
-
} finally {
|
|
9008
|
-
isApiAddingRef.current = false;
|
|
9009
|
-
}
|
|
9010
|
-
setLayers(nextState.layers);
|
|
9011
|
-
applySelectionState(nextState.selectedIds, { focusProperties: false });
|
|
9012
|
-
setRedoStack((prev) => prev.slice(0, -1));
|
|
9013
|
-
setUndoStack((prev) => [...prev, currentState]);
|
|
9014
|
-
updateFeatureCount();
|
|
9015
|
-
layerTemporalCacheRef.current.clear();
|
|
9016
|
-
scheduleTimelineUpdate();
|
|
9017
|
-
syncFeaturesToCustomLayers();
|
|
9018
|
-
layersRef.current = nextState.layers;
|
|
9019
|
-
onRedo == null ? void 0 : onRedo(computeUndoRedoEvent(currentState, nextState));
|
|
9020
|
-
}, [redoStack, layers, selectedFeatureIds, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, applySelectionState, onRedo]);
|
|
9021
9331
|
const handleClear = useCallback(() => {
|
|
9022
9332
|
if (!draw.current) return;
|
|
9023
9333
|
const activeLayer = layersRef.current.find((l) => l.id === activeEditingLayerId);
|
|
@@ -9160,12 +9470,12 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9160
9470
|
const isCtrlOrCmd = e.ctrlKey || e.metaKey;
|
|
9161
9471
|
if (isCtrlOrCmd && key === "z" && !e.shiftKey) {
|
|
9162
9472
|
e.preventDefault();
|
|
9163
|
-
|
|
9473
|
+
history.undo();
|
|
9164
9474
|
return;
|
|
9165
9475
|
}
|
|
9166
9476
|
if (isCtrlOrCmd && (key === "y" || key === "z" && e.shiftKey)) {
|
|
9167
9477
|
e.preventDefault();
|
|
9168
|
-
|
|
9478
|
+
history.redo();
|
|
9169
9479
|
return;
|
|
9170
9480
|
}
|
|
9171
9481
|
if (key === "e" && !isCtrlOrCmd && !e.altKey) {
|
|
@@ -9217,7 +9527,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9217
9527
|
};
|
|
9218
9528
|
container.addEventListener("keydown", handleKeyDown);
|
|
9219
9529
|
return () => container.removeEventListener("keydown", handleKeyDown);
|
|
9220
|
-
}, [isMapLoaded, enableKeyboardShortcuts, isEditMode, activeMode, handleToggleEditMode,
|
|
9530
|
+
}, [isMapLoaded, enableKeyboardShortcuts, isEditMode, activeMode, handleToggleEditMode, history, handleModeChange, selectedFeatureIds, handleDeleteSelected, canDeleteSelected, hiddenDrawingTools]);
|
|
9221
9531
|
const createPointAtCoords = useCallback((lng, lat) => {
|
|
9222
9532
|
if (!draw.current || !isMapLoaded) return;
|
|
9223
9533
|
if (!isEditModeRef.current) {
|
|
@@ -10001,30 +10311,35 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
10001
10311
|
}, [loadBasemapStyle, setBasemapVisibility, moveLabelsBeforeBasemapSymbols]);
|
|
10002
10312
|
handleMapStyleChangeRef.current = handleMapStyleChange;
|
|
10003
10313
|
const handleUpdateTraceConfig = useCallback((layerId, config) => {
|
|
10314
|
+
saveStateForUndo("trace config", { coalesceKey: `traceConfig:${layerId}` });
|
|
10004
10315
|
setLayers((prev) => prev.map(
|
|
10005
10316
|
(l) => l.id === layerId ? { ...l, traceConfig: config } : l
|
|
10006
10317
|
));
|
|
10007
|
-
}, []);
|
|
10318
|
+
}, [saveStateForUndo]);
|
|
10008
10319
|
const handleUpdateHeatmapConfig = useCallback((layerId, config) => {
|
|
10320
|
+
saveStateForUndo("heatmap config", { coalesceKey: `heatmapConfig:${layerId}` });
|
|
10009
10321
|
setLayers((prev) => prev.map(
|
|
10010
10322
|
(l) => l.id === layerId ? { ...l, heatmapConfig: config } : l
|
|
10011
10323
|
));
|
|
10012
|
-
}, []);
|
|
10324
|
+
}, [saveStateForUndo]);
|
|
10013
10325
|
const handleUpdateClusterConfig = useCallback((layerId, config) => {
|
|
10326
|
+
saveStateForUndo("cluster config", { coalesceKey: `clusterConfig:${layerId}` });
|
|
10014
10327
|
setLayers((prev) => prev.map(
|
|
10015
10328
|
(l) => l.id === layerId ? { ...l, clusterConfig: config } : l
|
|
10016
10329
|
));
|
|
10017
|
-
}, []);
|
|
10330
|
+
}, [saveStateForUndo]);
|
|
10018
10331
|
const handleUpdateVisualConfig = useCallback((layerId, config) => {
|
|
10332
|
+
saveStateForUndo("style config", { coalesceKey: `visualConfig:${layerId}` });
|
|
10019
10333
|
setLayers((prev) => prev.map(
|
|
10020
10334
|
(l) => l.id === layerId ? { ...l, visualConfig: config } : l
|
|
10021
10335
|
));
|
|
10022
|
-
}, []);
|
|
10336
|
+
}, [saveStateForUndo]);
|
|
10023
10337
|
const handleUpdateAltitudeDisplayMode = useCallback((layerId, mode) => {
|
|
10338
|
+
saveStateForUndo("altitude mode", { coalesceKey: `altitude:${layerId}` });
|
|
10024
10339
|
setLayers((prev) => prev.map(
|
|
10025
10340
|
(l) => l.id === layerId ? { ...l, altitudeDisplayMode: mode } : l
|
|
10026
10341
|
));
|
|
10027
|
-
}, []);
|
|
10342
|
+
}, [saveStateForUndo]);
|
|
10028
10343
|
const handleUpdateAutoLabelConfig = useCallback((config) => {
|
|
10029
10344
|
setAutoLabelConfig(config);
|
|
10030
10345
|
}, []);
|
|
@@ -10409,6 +10724,14 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
10409
10724
|
useEffect(() => {
|
|
10410
10725
|
selectedFeatureIdsRef.current = selectedFeatureIds;
|
|
10411
10726
|
}, [selectedFeatureIds]);
|
|
10727
|
+
const enableSelectionRef = useRef(enableSelection);
|
|
10728
|
+
useEffect(() => {
|
|
10729
|
+
enableSelectionRef.current = enableSelection;
|
|
10730
|
+
}, [enableSelection]);
|
|
10731
|
+
const enableDrawingRef = useRef(enableDrawing);
|
|
10732
|
+
useEffect(() => {
|
|
10733
|
+
enableDrawingRef.current = enableDrawing;
|
|
10734
|
+
}, [enableDrawing]);
|
|
10412
10735
|
useEffect(() => {
|
|
10413
10736
|
if (!map.current || !isMapLoaded) {
|
|
10414
10737
|
return;
|
|
@@ -10907,6 +11230,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
10907
11230
|
},
|
|
10908
11231
|
geometry: circle.geometry
|
|
10909
11232
|
};
|
|
11233
|
+
saveStateForUndo("draw circle");
|
|
10910
11234
|
drawInstance.add(circleFeature);
|
|
10911
11235
|
const currentActiveEditingLayerId = activeEditingLayerIdRef.current;
|
|
10912
11236
|
setLayers((prev) => {
|
|
@@ -10922,12 +11246,6 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
10922
11246
|
syncFeaturesToCustomLayers();
|
|
10923
11247
|
const newCount = drawInstance.getAll().features.length;
|
|
10924
11248
|
setFeatureCount(newCount);
|
|
10925
|
-
setUndoStack((prev) => [...prev, {
|
|
10926
|
-
features: drawInstance.getAll().features,
|
|
10927
|
-
selectedIds: [featureId],
|
|
10928
|
-
layers: layersRef.current
|
|
10929
|
-
}]);
|
|
10930
|
-
setRedoStack([]);
|
|
10931
11249
|
drawInstance.changeMode("simple_select", { featureIds: [featureId] });
|
|
10932
11250
|
setActiveMode("simple_select");
|
|
10933
11251
|
setSelectedFeatureIds([featureId]);
|
|
@@ -11034,6 +11352,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
11034
11352
|
coordinates: [rectCoords]
|
|
11035
11353
|
}
|
|
11036
11354
|
};
|
|
11355
|
+
saveStateForUndo("draw rectangle");
|
|
11037
11356
|
drawInstance.add(rectFeature);
|
|
11038
11357
|
const currentActiveEditingLayerId = activeEditingLayerIdRef.current;
|
|
11039
11358
|
setLayers((prev) => {
|
|
@@ -11049,12 +11368,6 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
11049
11368
|
syncFeaturesToCustomLayers();
|
|
11050
11369
|
const newCount = drawInstance.getAll().features.length;
|
|
11051
11370
|
setFeatureCount(newCount);
|
|
11052
|
-
setUndoStack((prev) => [...prev, {
|
|
11053
|
-
features: drawInstance.getAll().features,
|
|
11054
|
-
selectedIds: [featureId],
|
|
11055
|
-
layers: layersRef.current
|
|
11056
|
-
}]);
|
|
11057
|
-
setRedoStack([]);
|
|
11058
11371
|
justCreatedRectangleRef.current = true;
|
|
11059
11372
|
drawInstance.changeMode("simple_select", { featureIds: [featureId] });
|
|
11060
11373
|
setActiveMode("simple_select");
|
|
@@ -12491,13 +12804,14 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
12491
12804
|
onModeChange: handleModeChange,
|
|
12492
12805
|
onClear: handleClear,
|
|
12493
12806
|
onDeleteSelected: handleDeleteSelected,
|
|
12494
|
-
onUndo:
|
|
12495
|
-
onRedo:
|
|
12807
|
+
onUndo: history.undo,
|
|
12808
|
+
onRedo: history.redo,
|
|
12496
12809
|
featureCount,
|
|
12497
12810
|
selectedCount: selectedFeatureIds.length,
|
|
12498
12811
|
canDeleteSelected,
|
|
12499
|
-
canUndo:
|
|
12500
|
-
canRedo:
|
|
12812
|
+
canUndo: history.canUndo,
|
|
12813
|
+
canRedo: history.canRedo,
|
|
12814
|
+
showUndoRedo: true,
|
|
12501
12815
|
disabled: !isMapLoaded,
|
|
12502
12816
|
isEditMode,
|
|
12503
12817
|
onToggleEditMode: handleToggleEditMode,
|