feat(workbench): organize map editing panels

This commit is contained in:
que01 committed 2026-09-01 13:47:30 +08:00
1 parent 6d80597642
commit bb108267e3
8 files changed
+556 -242

No files matched your search

+10 -4
View File
@@ -91,6 +91,8 @@ export function MapCanvas({
const handleLayerRef = useRef<EditHandleLayer | null>(null);
const ghostRef = useRef<EditGhostLayer | null>(null);
const previewRef = useRef<EditPreviewLayer | null>(null);
/** Auto-fit is for a newly loaded area, never for a recompile of the same one. */
const fittedAreaIdRef = useRef<string | null>(null);
const laneSelectionSourceRef = useRef<VectorSource | null>(null);
const laneSelectionFeaturesRef = useRef<Feature[]>([]);
const laneSelectionAnchorRef = useRef<Coordinate | null>(null);
@@ -139,6 +141,9 @@ export function MapCanvas({
laneSelectionAnchorRef.current = laneSelectionAnchor ?? null;
useEffect(() => {
if (!target.current) return;
// StrictMode intentionally tears this effect down and creates a fresh map.
// A fresh view starts at [0, 0], so it must receive its own initial fit.
fittedAreaIdRef.current = null;
const layers = createLayers(
() => selectedRef.current,
() => sceneRef.current,
@@ -290,7 +295,10 @@ export function MapCanvas({
if (!layers || !map) return;
updateLayers(layers, state, selected);
const extent = layers.osm.getSource()!.getExtent();
if (extent && Number.isFinite(extent[0])) map.getView().fit(extent, { padding: [48, 48, 48, 48], maxZoom: 19 });
if (fittedAreaIdRef.current !== state.areaId && extent && Number.isFinite(extent[0])) {
map.getView().fit(extent, { padding: [48, 48, 48, 48], maxZoom: 19 });
fittedAreaIdRef.current = state.areaId;
}
}, [state]);
useEffect(() => {
const layers = layersRef.current;
@@ -344,9 +352,7 @@ export function MapCanvas({
if (!layers) return;
Object.entries(visible).forEach(([name, enabled]) =>
layers[name as LayerName]?.setVisible(
!scene || !['osm', 'lanes', 'reference', 'gaodeReference', 'connectors'].includes(name)
? enabled !== false
: false,
!scene || !['osm', 'lanes', 'connectors'].includes(name) ? enabled !== false : false,
),
);
layers.native.changed();