feat: override which turn arrow a lane shows

The arrow on a lane came from the OSM turn:lanes tag with no way to change it,
and a lane the tag skipped got no arrow at all. lane-maneuver is a v1 override
that sets it.

v1 rather than a v2 constraint, because "which arrow" is a discrete attribute of
a lane with no station to anchor to, while every v2 anchor is positional. The
existing road override already covers OSM-derived values this way — laneCount,
width, sidewalks — and this is the same kind of thing. Arrow *placement* is the
positional half and stays out; it also still has an open question about whether
a group is a lane or a single arrow.

Three behaviours, each measured against compiled output: an override replaces
the tag's maneuver, it adds arrows to a lane the tag never marked, and '' removes
one the tag asked for. The empty string is therefore distinguished from "no
override" rather than falling through to the tag. An empty override set leaves
the arrows byte-identical and the fixtures untouched.

Validation lists the accepted maneuvers and rejects anything else, including
correctly-spelled components in the wrong order. It cannot be left to
normalizeManeuver(), which returns unrecognised input unchanged — a typo would
otherwise reach the template lookup and silently produce no arrow.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
que01andClaude Opus 5 committed 2026-08-31 18:00:53 +08:00
1 parent 15d41be444
commit 335c8ea68a
7 files changed
+173 -2

No files matched your search

+35 -1
View File
@@ -51,6 +51,17 @@ const DEFAULT_WIDTHS = {
service: 4,
};
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;
@@ -264,6 +275,8 @@ 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))
@@ -325,6 +338,16 @@ 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.`,
);
} else if (item.kind === 'junction-connection') {
if (
typeof item.fromEndpointId !== 'string' ||
@@ -1521,7 +1544,12 @@ function compileLaneMarkings(model, overrides, lanes, diagnostics, junctionPlans
const maneuvers = turns ? String(turns).split('|') : [];
for (let index = 0; index < roadLanes.length; index += 1) {
const lane = roadLanes[index];
const explicitManeuver = maneuvers[index];
// An override wins over the tag, and can put an arrow on a lane OSM never
// 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 explicitManeuver = override !== undefined ? override : maneuvers[index];
if (!explicitManeuver) continue;
const maneuver = normalizeManeuver(explicitManeuver);
if (!lane) {
@@ -2338,6 +2366,12 @@ 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) {
const item = (overrides?.overrides || []).find((entry) => entry.kind === 'lane-maneuver' && entry.laneId === laneId);
return item ? item.maneuver : undefined;
}
function laneOverride(overrides, fromLaneId, toLaneId) {
return overrides.overrides.find(
(item) => item.kind === 'lane-connection' && item.fromLaneId === fromLaneId && item.toLaneId === toLaneId,