feat(workbench): unify lane maneuver edits in v2

This commit is contained in:
que01 committed 2026-09-01 16:46:22 +08:00
1 parent 118dc8e9aa
commit c804a373ca
15 files changed
+337 -263

No files matched your search

+2 -29
View File
@@ -54,14 +54,6 @@ const DEFAULT_SIDEWALK_WIDTH_METERS = 2;
// The maneuvers `turn-lane-arrows.js` has templates for. `normalizeManeuver()`
// returns unknown input unchanged rather than failing, so an override has to be
// checked here — it cannot lean on normalisation to reject a typo.
const SUPPORTED_MANEUVERS = new Set([
'through',
'left',
'right',
'through;left',
'through;right',
'through;left;right',
]);
const DIRECTION_ARROW_INTERVAL_METERS = 32;
const DIRECTION_ARROW_ENDPOINT_BUFFER_METERS = 14;
const STOP_LINE_MAX_APPROACH_DISTANCE_METERS = 25;
@@ -275,8 +267,6 @@ function staleOverrideTarget(item, sets) {
if (item.kind === 'road' && typeof item.roadId === 'string' && !sets.roadIds.has(item.roadId)) return item.roadId;
if (item.kind === 'lane-separator-style' && typeof item.roadId === 'string' && !sets.roadIds.has(item.roadId))
return item.roadId;
if (item.kind === 'lane-maneuver' && typeof item.laneId === 'string' && !sets.laneIds.has(item.laneId))
return item.laneId;
if (item.kind === 'edge-line-style' && typeof item.roadId === 'string' && !sets.directionalRoadIds.has(item.roadId))
return item.roadId;
if (item.kind === 'center-line-style' && typeof item.segmentId === 'string' && !sets.segmentIds.has(item.segmentId))
@@ -338,21 +328,6 @@ function validateOverrides(value, model, options = {}) {
throw new Error(`Invalid road override ${key}.`);
for (const key of ['sidewalkLeft', 'sidewalkRight'])
if (item[key] !== undefined && typeof item[key] !== 'boolean') throw new Error(`Invalid road override ${key}.`);
} else if (item.kind === 'lane-maneuver') {
if (typeof item.laneId !== 'string' || (laneIds && !laneIds.has(item.laneId)))
throw new Error(`Unknown lane maneuver override target: ${item.laneId}`);
// '' is meaningful: it removes an arrow OSM asked for. Anything else must be
// a maneuver there is a template for.
if (typeof item.maneuver !== 'string' || (item.maneuver !== '' && !SUPPORTED_MANEUVERS.has(item.maneuver)))
throw new Error(
`Invalid lane maneuver override: ${item.maneuver}. Use '' to remove an arrow, or one of ` +
`${[...SUPPORTED_MANEUVERS].join(', ')} — components must be in that order.`,
);
if (
item.placementDistanceMeters !== undefined &&
(!Number.isFinite(item.placementDistanceMeters) || item.placementDistanceMeters < 0)
)
throw new Error(`Invalid lane maneuver placement: ${item.placementDistanceMeters}.`);
} else if (item.kind === 'junction-connection') {
if (
typeof item.fromEndpointId !== 'string' ||
@@ -1553,7 +1528,8 @@ function compileLaneMarkings(model, overrides, lanes, diagnostics, junctionPlans
// marked — the tag being absent is exactly the case a user needs to fix.
// An empty string is a deliberate "no arrow here", so it is distinguished
// from "no override" rather than falling through to the tag.
const override = lane ? laneManeuverOverride(overrides, lane.id) : undefined;
const v2Override = lane ? options.directEdit?.laneManeuvers?.get?.(lane.id) : undefined;
const override = v2Override;
const explicitManeuver = override ? override.maneuver : maneuvers[index];
if (!explicitManeuver) continue;
const maneuver = normalizeManeuver(explicitManeuver);
@@ -2375,9 +2351,6 @@ function compileConnectors(model, lanes, diagnostics, overrides, junctionPlans)
return { features, movements };
}
/** The maneuver an override sets for a lane, or `undefined` when none applies. */
function laneManeuverOverride(overrides, laneId) {
return (overrides?.overrides || []).find((entry) => entry.kind === 'lane-maneuver' && entry.laneId === laneId);
}
function safeTurnArrowPlacement(line, maneuver, axis, distance, controls) {
return (