feat(workbench): unify lane maneuver edits in v2
This commit is contained in:
1 parent
118dc8e9aa
commit
c804a373ca
15 files changed
+337
-263
No files matched your search
@@ -13,7 +13,6 @@ import Style from 'ol/style/Style';
|
||||
import { click } from 'ol/events/condition';
|
||||
import type { GeoJson, Road, WorkbenchState } from '../types/state';
|
||||
import { createLayers, updateLayers, updateSelectedRoad, type LayerName } from '../map/layers';
|
||||
import { directEditEnabled } from '../edit/flag';
|
||||
import { createHandleDragInteraction } from '../edit/drag-interaction';
|
||||
import { EditGhostLayer } from '../edit/ghost-layer';
|
||||
import { EditHandleLayer, type ElementOutline } from '../edit/handle-layer';
|
||||
@@ -60,6 +59,7 @@ interface Props {
|
||||
onRangeEnd?: (range: IntervalRangeHandle, anchor: RoadIntervalAnchor) => void;
|
||||
/** Last solve came back degraded; hold the ghost instead of clearing it. */
|
||||
ghostPending?: boolean;
|
||||
editMode?: boolean;
|
||||
}
|
||||
export function MapCanvas({
|
||||
state,
|
||||
@@ -86,6 +86,7 @@ export function MapCanvas({
|
||||
onRangeDrag,
|
||||
onRangeEnd,
|
||||
ghostPending,
|
||||
editMode = false,
|
||||
}: Props) {
|
||||
const target = useRef<HTMLDivElement>(null);
|
||||
const mapRef = useRef<Map | null>(null);
|
||||
@@ -96,6 +97,7 @@ export function MapCanvas({
|
||||
/** 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 laneSelectionLayerRef = useRef<VectorLayer<VectorSource> | null>(null);
|
||||
const laneSelectionFeaturesRef = useRef<Feature[]>([]);
|
||||
const laneSelectionAnchorRef = useRef<Coordinate | null>(null);
|
||||
const hiddenMarkingIdsRef = useRef<ReadonlySet<string>>(new Set());
|
||||
@@ -133,9 +135,11 @@ export function MapCanvas({
|
||||
const selectedRef = useRef<Road | null>(selected);
|
||||
const stateRef = useRef(state);
|
||||
const sceneRef = useRef(scene);
|
||||
const editModeRef = useRef(editMode);
|
||||
selectedRef.current = selected;
|
||||
stateRef.current = state;
|
||||
sceneRef.current = scene;
|
||||
editModeRef.current = editMode;
|
||||
hiddenMarkingIdsRef.current = new Set(
|
||||
laneSelectionHiddenIds ??
|
||||
(laneSelectionFeatures ?? [])
|
||||
@@ -164,16 +168,15 @@ export function MapCanvas({
|
||||
}),
|
||||
});
|
||||
laneSelectionSourceRef.current = laneSelectionSource;
|
||||
laneSelectionLayerRef.current = laneSelectionLayer;
|
||||
// The v2 direct-edit sources below remain absent with the flag off. The lane
|
||||
// selection layer above is a regular v1 override affordance, not an edit source.
|
||||
const handleLayer = directEditEnabled ? new EditHandleLayer() : null;
|
||||
const ghost = directEditEnabled ? new EditGhostLayer() : null;
|
||||
const previewLayer = directEditEnabled
|
||||
? new EditPreviewLayer(
|
||||
() => selectedRef.current,
|
||||
() => sceneRef.current,
|
||||
)
|
||||
: null;
|
||||
const handleLayer = new EditHandleLayer();
|
||||
const ghost = new EditGhostLayer();
|
||||
const previewLayer = new EditPreviewLayer(
|
||||
() => selectedRef.current,
|
||||
() => sceneRef.current,
|
||||
);
|
||||
handleLayerRef.current = handleLayer;
|
||||
ghostRef.current = ghost;
|
||||
previewRef.current = previewLayer;
|
||||
@@ -204,6 +207,7 @@ export function MapCanvas({
|
||||
map.addInteraction(
|
||||
new PointerInteraction({
|
||||
handleDownEvent: (event) => {
|
||||
if (!editModeRef.current) return false;
|
||||
const hit = event.map.forEachFeatureAtPixel(event.pixel, (feature) => feature, {
|
||||
layerFilter: (layer) => layer === laneSelectionLayer,
|
||||
hitTolerance: 10,
|
||||
@@ -258,8 +262,8 @@ export function MapCanvas({
|
||||
createHandleDragInteraction({
|
||||
layer: handleLayer.layer,
|
||||
ghost,
|
||||
handleAt: (handleId) => handleLayer.handle(handleId),
|
||||
rangeAt: (handleId) => handleLayer.range(handleId),
|
||||
handleAt: (handleId) => (editModeRef.current ? handleLayer.handle(handleId) : undefined),
|
||||
rangeAt: (handleId) => (editModeRef.current ? handleLayer.range(handleId) : undefined),
|
||||
onDrag: (handle, value) => dragRef.current.onHandleDrag?.(handle, value),
|
||||
onEnd: (handle, value) => dragRef.current.onHandleDragEnd?.(handle, value),
|
||||
onRangeDrag: (range, anchor) => dragRef.current.onRangeDrag?.(range, anchor),
|
||||
@@ -320,6 +324,7 @@ export function MapCanvas({
|
||||
useEffect(() => {
|
||||
const source = laneSelectionSourceRef.current;
|
||||
if (!source) return;
|
||||
laneSelectionLayerRef.current?.setVisible(editMode);
|
||||
source.clear();
|
||||
const parts = (laneSelectionFeatures ?? []).flatMap((feature) => {
|
||||
const coordinates = feature.geometry?.coordinates;
|
||||
|
||||
Reference in new issue
Block a user