feat(workbench): drag traffic signal assemblies

This commit is contained in:
que01 committed 2026-09-02 09:05:56 +08:00
1 parent cf5bc0602b
commit 9c83392b97
1 file changed
+32
@@ -47,6 +47,8 @@ interface Props {
/** Receives the axis-projected final map coordinate. */ /** Receives the axis-projected final map coordinate. */
onLaneSelectionDrag?: (from: Coordinate, to: Coordinate) => void; onLaneSelectionDrag?: (from: Coordinate, to: Coordinate) => void;
onLaneSelectionDragEnd?: (from: Coordinate, to: Coordinate) => void; onLaneSelectionDragEnd?: (from: Coordinate, to: Coordinate) => void;
onSignalDrag?: (signalUid: string, coordinate: Coordinate) => void;
onSignalDragEnd?: (signalUid: string, coordinate: Coordinate) => void;
/** Authoritative preview geometry; null returns the map to the baseline. */ /** Authoritative preview geometry; null returns the map to the baseline. */
preview?: Partial<Record<PreviewLayerName, GeoJson | null>> | null; preview?: Partial<Record<PreviewLayerName, GeoJson | null>> | null;
/** Live value during a drag — the caller debounces the preview request. */ /** Live value during a drag — the caller debounces the preview request. */
@@ -79,6 +81,8 @@ export function MapCanvas({
laneSelectionAxisAzimuth, laneSelectionAxisAzimuth,
onLaneSelectionDrag, onLaneSelectionDrag,
onLaneSelectionDragEnd, onLaneSelectionDragEnd,
onSignalDrag,
onSignalDragEnd,
preview, preview,
onHandleDrag, onHandleDrag,
onHandleDragEnd, onHandleDragEnd,
@@ -116,6 +120,8 @@ export function MapCanvas({
onRangeEnd, onRangeEnd,
onLaneSelectionDragEnd, onLaneSelectionDragEnd,
onLaneSelectionDrag, onLaneSelectionDrag,
onSignalDrag,
onSignalDragEnd,
laneSelectionAxisAzimuth, laneSelectionAxisAzimuth,
ghostPending, ghostPending,
}); });
@@ -127,6 +133,8 @@ export function MapCanvas({
onRangeEnd, onRangeEnd,
onLaneSelectionDragEnd, onLaneSelectionDragEnd,
onLaneSelectionDrag, onLaneSelectionDrag,
onSignalDrag,
onSignalDragEnd,
laneSelectionAxisAzimuth, laneSelectionAxisAzimuth,
ghostPending, ghostPending,
}; };
@@ -201,6 +209,30 @@ export function MapCanvas({
style: null, style: null,
}); });
map.addInteraction(select); map.addInteraction(select);
let signalUid: string | null = null;
map.addInteraction(
new PointerInteraction({
handleDownEvent: (event) => {
if (!editModeRef.current) return false;
const hit = event.map.forEachFeatureAtPixel(event.pixel, (feature) => feature, {
layerFilter: (layer) => layer === layers.signals,
hitTolerance: 10,
});
const uid = hit?.get('signal_uid');
if (typeof uid !== 'string' || hit?.get('signal_component')) return false;
signalUid = uid;
return true;
},
handleDragEvent: (event) => {
if (signalUid) dragRef.current.onSignalDrag?.(signalUid, toLonLat(event.coordinate as Coordinate));
},
handleUpEvent: (event) => {
if (signalUid) dragRef.current.onSignalDragEnd?.(signalUid, toLonLat(event.coordinate as Coordinate));
signalUid = null;
return false;
},
}),
);
let laneDragOrigin: Coordinate | null = null; let laneDragOrigin: Coordinate | null = null;
let laneDragAnchor: Coordinate | null = null; let laneDragAnchor: Coordinate | null = null;
let laneDragFeatures: Feature[] = []; let laneDragFeatures: Feature[] = [];