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

+57 -11
View File
@@ -15,7 +15,15 @@ import {
} from './edit/element';
import { directEditEnabled, intervalEditingSupported } from './edit/flag';
import type { ElementOutline } from './edit/handle-layer';
import { azimuthBetween, signedMetersAlongAxis, type Coordinate } from './edit/meters';
import {
azimuthBetween,
coordinateAtStation,
metersAlongPolyline,
polylineLengthMeters,
toLonLat,
type Coordinate,
} from './edit/meters';
import { previewArrowFeatures } from './edit/arrow-preview';
import { rendersSame } from './edit/parameter';
import { PreviewRequester, type PreviewDraft } from './edit/preview-request';
import { anchorSnapshotFor, constraintValueFor, draftConstraint, operationFor } from './edit/projection';
@@ -215,13 +223,29 @@ function App() {
const laneSelectionFeatures = useMemo(() => {
if (!element || element.kind !== 'lane-maneuver' || !state) return [];
const ids = new Set(element.featureIds);
return (
const existing =
state.layers.turnArrows?.features.filter((feature) => {
const nativeId = feature.properties?.native_id;
return typeof nativeId === 'string' && ids.has(nativeId);
}) ?? []
}) ?? [];
const effective = [...state.overrides.overrides, ...staged]
.reverse()
.find((item) => item.kind === 'lane-maneuver' && item.laneId === element.laneId);
const maneuver = typeof effective?.maneuver === 'string' ? effective.maneuver : element.maneuver;
const placementDistanceMeters =
typeof effective?.placementDistanceMeters === 'number'
? effective.placementDistanceMeters
: element.placementDistanceMeters;
if (existing.length && maneuver === element.maneuver && placementDistanceMeters === element.placementDistanceMeters)
return existing;
const lane = state.layers.laneCenterlines?.features.find(
(feature) => feature.properties?.native_id === element.laneId,
);
}, [element, state]);
const line = lane?.geometry?.type === 'LineString' ? (lane.geometry.coordinates as Coordinate[]) : null;
const distance = placementDistanceMeters ?? 6;
if (!line || line.length < 2 || !maneuver) return [];
return previewArrowFeatures(element.laneId, maneuver, line, distance);
}, [element, staged, state]);
const laneSelectionAxisAzimuth = useMemo(() => {
if (!element || element.kind !== 'lane-maneuver' || !state) return null;
const road = state.compiled.model.roads.find((item) => item.id === element.roadId);
@@ -229,6 +253,23 @@ function App() {
const end = road?.centerline.at(-1);
return previous && end ? azimuthBetween(previous, end) : null;
}, [element, state]);
const laneSelectionAnchor = useMemo<Coordinate | null>(() => {
if (!element || element.kind !== 'lane-maneuver' || !state) return null;
const lane = state.layers.laneCenterlines?.features.find(
(feature) => feature.properties?.native_id === element.laneId,
);
const line = lane?.geometry?.type === 'LineString' ? (lane.geometry.coordinates as Coordinate[]) : null;
if (!line || line.length < 2) return null;
const effective = [...state.overrides.overrides, ...staged]
.reverse()
.find((item) => item.kind === 'lane-maneuver' && item.laneId === element.laneId);
const distance =
typeof effective?.placementDistanceMeters === 'number'
? effective.placementDistanceMeters
: (element.placementDistanceMeters ?? 6);
const length = polylineLengthMeters(line);
return length > 0 ? coordinateAtStation(line, 1 - distance / length) : null;
}, [element, staged, state]);
const sessionRef = useRef<EditSession | null>(null);
if (directEditEnabled && !sessionRef.current) sessionRef.current = new EditSession();
// Per-frame drag feedback reaches the panel through this rather than through
@@ -653,14 +694,19 @@ function App() {
element={elementOutline}
laneSelectionBounds={laneSelectionBounds}
laneSelectionFeatures={laneSelectionFeatures}
laneSelectionHiddenIds={element?.kind === 'lane-maneuver' ? element.featureIds : []}
laneSelectionAnchor={laneSelectionAnchor}
laneSelectionAxisAzimuth={laneSelectionAxisAzimuth}
onLaneSelectionDragEnd={(from, to) => {
if (!element || element.kind !== 'lane-maneuver' || element.placementDistanceMeters === undefined) return;
const road = state.compiled.model.roads.find((item) => item.id === element.roadId);
const previous = road?.centerline.at(-2);
const end = road?.centerline.at(-1);
if (!previous || !end) return;
const deltaTowardJunction = signedMetersAlongAxis(from, to, azimuthBetween(previous, end));
if (!element || element.kind !== 'lane-maneuver') return;
const lane = state.layers.laneCenterlines?.features.find(
(feature) => feature.properties?.native_id === element.laneId,
);
const line = lane?.geometry?.type === 'LineString' ? (lane.geometry.coordinates as Coordinate[]) : null;
if (!line || line.length < 2) return;
const along = metersAlongPolyline(line, toLonLat(to));
const length = polylineLengthMeters(line);
if (along === null || !(length > 0)) return;
const existing = [...state.overrides.overrides, ...staged]
.reverse()
.find((item) => item.kind === 'lane-maneuver' && item.laneId === element.laneId);
@@ -669,7 +715,7 @@ function App() {
kind: 'lane-maneuver',
laneId: element.laneId,
maneuver: typeof existing?.maneuver === 'string' ? existing.maneuver : element.maneuver,
placementDistanceMeters: Math.max(0, element.placementDistanceMeters - deltaTowardJunction),
placementDistanceMeters: Math.max(0, length - along),
});
setStatus('箭头位置已暂存;保存并重新生成后应用。');
}}