feat(workbench): preview and drag lane turn arrows

This commit is contained in:
que01 committed 2026-09-01 11:47:35 +08:00
1 parent 9cb715a592
commit 6d80597642
8 files changed
+260 -17

No files matched your search

+26 -5
View File
@@ -41,7 +41,11 @@ interface Props {
laneSelectionBounds?: Coordinate[] | null;
/** Polygon parts copied to the drag feedback layer; baseline parts are hidden by id. */
laneSelectionFeatures?: GeoJson['features'];
laneSelectionHiddenIds?: string[];
/** The lane centerline point that anchors every part of the selected arrow. */
laneSelectionAnchor?: Coordinate | null;
laneSelectionAxisAzimuth?: number | null;
/** Receives the axis-projected final map coordinate. */
onLaneSelectionDragEnd?: (from: Coordinate, to: Coordinate) => void;
/** Authoritative preview geometry; null returns the map to the baseline. */
preview?: Partial<Record<PreviewLayerName, GeoJson | null>> | null;
@@ -69,6 +73,8 @@ export function MapCanvas({
element,
laneSelectionBounds,
laneSelectionFeatures,
laneSelectionHiddenIds,
laneSelectionAnchor,
laneSelectionAxisAzimuth,
onLaneSelectionDragEnd,
preview,
@@ -87,6 +93,7 @@ export function MapCanvas({
const previewRef = useRef<EditPreviewLayer | null>(null);
const laneSelectionSourceRef = useRef<VectorSource | null>(null);
const laneSelectionFeaturesRef = useRef<Feature[]>([]);
const laneSelectionAnchorRef = useRef<Coordinate | null>(null);
const hiddenMarkingIdsRef = useRef<ReadonlySet<string>>(new Set());
const visibleRef = useRef(visible);
visibleRef.current = visible;
@@ -124,10 +131,12 @@ export function MapCanvas({
stateRef.current = state;
sceneRef.current = scene;
hiddenMarkingIdsRef.current = new Set(
(laneSelectionFeatures ?? [])
.map((feature) => feature.properties?.native_id)
.filter((id): id is string => typeof id === 'string'),
laneSelectionHiddenIds ??
(laneSelectionFeatures ?? [])
.map((feature) => feature.properties?.native_id)
.filter((id): id is string => typeof id === 'string'),
);
laneSelectionAnchorRef.current = laneSelectionAnchor ?? null;
useEffect(() => {
if (!target.current) return;
const layers = createLayers(
@@ -181,6 +190,7 @@ export function MapCanvas({
});
map.addInteraction(select);
let laneDragOrigin: Coordinate | null = null;
let laneDragAnchor: Coordinate | null = null;
let laneDragFeatures: Feature[] = [];
map.addInteraction(
new PointerInteraction({
@@ -191,8 +201,9 @@ export function MapCanvas({
});
if (!hit) return false;
laneDragOrigin = event.coordinate as Coordinate;
laneDragAnchor = laneSelectionAnchorRef.current ? fromLonLat(laneSelectionAnchorRef.current) : null;
laneDragFeatures = laneSelectionFeaturesRef.current.map((feature) => feature.clone());
return true;
return Boolean(laneDragAnchor);
},
handleDragEvent: (event) => {
const axis = dragRef.current.laneSelectionAxisAzimuth;
@@ -214,8 +225,18 @@ export function MapCanvas({
});
},
handleUpEvent: (event) => {
if (laneDragOrigin) dragRef.current.onLaneSelectionDragEnd?.(laneDragOrigin, event.coordinate as Coordinate);
const axis = dragRef.current.laneSelectionAxisAzimuth;
if (laneDragOrigin && laneDragAnchor && axis !== null && axis !== undefined) {
const to = event.coordinate as Coordinate;
const projectedPointer = fromLonLat(
offsetCoordinate(toLonLat(laneDragOrigin), axis, signedMetersAlongAxis(laneDragOrigin, to, axis)),
);
const dx = projectedPointer[0] - laneDragOrigin[0];
const dy = projectedPointer[1] - laneDragOrigin[1];
dragRef.current.onLaneSelectionDragEnd?.(laneDragOrigin, [laneDragAnchor[0] + dx, laneDragAnchor[1] + dy]);
}
laneDragOrigin = null;
laneDragAnchor = null;
laneDragFeatures = [];
return false;
},