feat: drag road handles with ghost and server preview

Three things, kept in one commit because they touch overlapping hunks of the
same two files and this environment has no interactive hunk staging. Splitting
them by file would have drawn boundaries that misrepresent what changed.

1. Step 4 of the map editor. A native OpenLayers PointerInteraction turns a
   drag into a clamped constraint value, the ghost source shows it immediately,
   and the solver's answer replaces a parallel set of preview layers while the
   baseline layers are hidden rather than overwritten. Preview requests debounce
   at 80 ms, pointerup flushes without waiting, and a newer request aborts the
   one in flight; EditSession decides which answers count. Handle positions come
   from the clamped value, so a handle stops at its limit instead of following
   the cursor. Three of the four drag capabilities are live: edge offset,
   sidewalk width, lane divider.

2. Road edge handles were drawn on the wrong side. offsetLine() offsets
   counter-clockwise from the direction of travel and sidewalks use
   `heading + (side === 'left' ? -90 : 90)`, so left is `tangent - 90`;
   makeRoadHandles() placed the left handle at `tangent + 90`, over the right
   kerb. Dragging the visually-left handle moved the right edge. Fixed on both
   sides of the wire, with regression tests that name the sides geographically
   rather than by axis sign.

3. Roads the junctions geometrically fill are now read-only. The 0.45 cap per
   reserve made the existing `unavailable` branch unreachable, so a 14.5 m stub
   between two junctions was offered a 1.5 m editable band with no room for the
   transitions a road-interval constraint needs. Greying only affects the
   manifest: constraints already saved against such a road keep being solved, so
   the geometry output is unchanged and the fixture baselines do not move.

Range handles are built and unit-tested but hidden behind
`intervalEditingSupported`: compileGeometry() reads neither profile.interval nor
profile.transitions, so every edit applies to the whole road and the control
would have had no effect. Recorded in research/interval-not-applied.md, which
also blocks one PRD acceptance criterion.

The ol-ext probe stays in the tree as a manual harness; ol-ext is still not a
dependency.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
que01andClaude Opus 5 committed 2026-08-27 17:38:34 +08:00
1 parent bc4b9a9717
commit 92297270f1
25 files changed
+1826 -58

No files matched your search

+52 -8
View File
@@ -6,13 +6,21 @@
// own range, and packaged as a `native-road-edits/v2` value. The client never
// writes a coordinate into a road polygon.
import { clamp, haversineMeters, polylineLengthMeters, signedMetersAlongAxis, type Coordinate } from './meters';
import {
clamp,
haversineMeters,
offsetCoordinate,
polylineLengthMeters,
signedMetersAlongAxis,
type Coordinate,
} from './meters';
import type {
AnchorSnapshot,
ConstraintValue,
EditHandle,
JunctionReserve,
RoadConstraint,
RoadEditOperation,
RoadIntervalAnchor,
Transition,
} from './types';
@@ -28,17 +36,21 @@ export interface IntervalWindow {
/**
* Turns "along axisAzimuth" into "outward" for a handle.
*
* `makeRoadHandles()` places the left handle at `tangent + 90` and the right one
* at `tangent - 90`, but reports `axisAzimuth = tangent + 90` for both. Since a
* positive `offsetMeters` / `widthMeters` always widens the road, a right-side
* drag measured along that axis has to be negated. Lane dividers are the
* exception: their offset is a signed lateral position already measured along
* the same axis, so the raw projection is the value.
* The manifest reports `axisAzimuth = tangent + 90` for both sides, which is the
* geometry compiler's *right*: `offsetLine()` treats a positive offset as
* counter-clockwise from the direction of travel, and sidewalks are placed at
* `heading + (side === 'left' ? -90 : 90)`. So the left kerb lies along the
* negative axis, and a left-side drag has to be negated for a positive
* `offsetMeters` / `widthMeters` to mean "wider" on both sides.
*
* Lane dividers are the exception: their offset is a signed lateral position
* already measured along the axis (left negative, right positive), so the raw
* projection is the value.
*/
function outwardSign(handle: EditHandle): number {
if (handle.kind === 'road-lane-divider') return 1;
const side = 'side' in handle.anchor ? handle.anchor.side : undefined;
return side === 'right' ? -1 : 1;
return side === 'left' ? -1 : 1;
}
/**
@@ -50,6 +62,21 @@ export function projectHandleValue(handle: EditHandle, from: Coordinate, to: Coo
return clamp(handle.value.current + delta, handle.value.min, handle.value.max);
}
/**
* Where the handle belongs for a given constraint value — the inverse of
* `projectHandleValue`, in EPSG:4326.
*
* This is what stops a handle running away from the geometry it controls. The
* ol-ext probe translated its proxy by the raw pointer delta, so a drag reading
* -24.1 m left the handle 24 m out while the constraint clamped at -5.4 m: the
* handle pointed at a road shape that could never exist. Deriving the position
* from the clamped value instead pins the handle to the limit.
*/
export function handlePositionFor(handle: EditHandle, value: number): Coordinate {
const outward = outwardSign(handle) < 0 ? handle.axisAzimuth + 180 : handle.axisAzimuth;
return offsetCoordinate(handle.position, outward, value - handle.value.current);
}
/** The manifest hangs `boundaryIndex` on the anchor; the document needs it in `value`. */
function boundaryIndexOf(handle: EditHandle): number {
const index = 'boundaryIndex' in handle.anchor ? handle.anchor.boundaryIndex : undefined;
@@ -141,6 +168,23 @@ export function anchorSnapshotFor(handle: EditHandle, centerline: Coordinate[],
};
}
/**
* The operation a drafted constraint has to travel with.
*
* `validateEditDocument()` rejects any constraint whose `provenance.operationId`
* is not a recorded operation, so sending constraints alone is a 400 — which is
* exactly how the first wiring of the preview request failed. Every caller that
* ships a constraint must ship this alongside it.
*/
export function operationFor(constraint: RoadConstraint): RoadEditOperation {
return {
id: constraint.provenance.operationId,
createdAt: constraint.provenance.createdAt,
constraintIds: [constraint.id],
...(constraint.provenance.author ? { author: constraint.provenance.author } : {}),
};
}
export interface DraftIdentity {
constraintId: string;
operationId: string;