diff --git a/.trellis/spec/frontend/direct-edit-client.md b/.trellis/spec/frontend/direct-edit-client.md index 1d911e4..06edcb7 100644 --- a/.trellis/spec/frontend/direct-edit-client.md +++ b/.trellis/spec/frontend/direct-edit-client.md @@ -151,6 +151,12 @@ With edit mode off, selecting a turn-arrow part may still show read-only element information, but it must not create a manifest request, ghost, preview, handle, or staged lane-maneuver override. +Crosswalk inset and stop-line offset follow the same element ownership rule. New +manifests use a `junction-crossing` anchor containing `crossingId` plus its road +context; legacy `junction-approach` anchors remain readable for document replay. +The crossing values must be kept separate from junction approach width/cutback +plans so editing one crossing cannot move the road geometry or another crossing. + --- ## 10. Saving is not the same as applying diff --git a/src/compile/direct-edit-solver.js b/src/compile/direct-edit-solver.js index 0e991d2..642731a 100644 --- a/src/compile/direct-edit-solver.js +++ b/src/compile/direct-edit-solver.js @@ -154,6 +154,14 @@ function constraintFor(constraints, kind, anchor) { item.anchor.incomingRoadId === anchor.incomingRoadId && item.anchor.outgoingRoadId === anchor.outgoingRoadId ); + if (kind === 'junction-crosswalk-inset' || kind === 'junction-stop-line-offset') + return ( + item.anchor.type === 'junction-crossing' && + item.anchor.crossingId === anchor.crossingId && + item.anchor.nodeId === anchor.nodeId && + item.anchor.segmentId === anchor.segmentId && + item.anchor.roadId === anchor.roadId + ); return ( item.anchor.type === 'junction-approach' && item.anchor.nodeId === anchor.nodeId && @@ -437,8 +445,40 @@ function applyRoadConstraint(model, constraint, profiles, diagnostics) { return true; } -function applyJunctionConstraint(model, constraint, junctionPlans, junctionData, diagnostics) { +function applyJunctionConstraint(model, constraint, junctionPlans, junctionData, diagnostics, crossingControls) { const anchor = constraint.anchor || {}; + if (anchor.type === 'junction-crossing') { + const crossing = (model.crossings || []).find((item) => String(item.id) === String(anchor.crossingId)); + const road = (model.roads || []).find((item) => item.id === anchor.roadId); + const approach = crossing && road ? approachForCrossing(model, crossing) : null; + if ( + !crossing || + !road || + !approach || + approach.road.id !== road.id || + String(road.segmentId) !== String(anchor.segmentId) + ) { + blocking(diagnostics, constraint, 'direct-edit-crossing-anchor-missing', '直接编辑约束的控制元素锚点不存在。'); + return false; + } + const value = Number(constraint.value?.insetMeters ?? constraint.value?.offsetMeters); + const valid = + constraint.kind === 'junction-crosswalk-inset' + ? Number.isFinite(value) && value >= 0 && value <= MAX_CROSSWALK_INSET_METERS + : Number.isFinite(value) && value >= MIN_STOP_LINE_OFFSET_METERS && value <= approach.junctionDistanceMeters; + if (!valid) { + blocking(diagnostics, constraint, 'direct-edit-crossing-value-invalid', '控制线位置超出当前元素可用范围。'); + return false; + } + // Keep the geometry value in a separate per-crossing map. Multiple crossings + // may share one approach, so storing this on the approach would couple them. + const crossingKey = String(anchor.crossingId); + const control = crossingControls.get(crossingKey) || {}; + crossingControls.set(crossingKey, control); + if (constraint.kind === 'junction-crosswalk-inset') control.crosswalkInsetMeters = value; + else control.stopLineOffsetMeters = value; + return true; + } const approaches = junctionData.approaches.get(String(anchor.nodeId)); const approach = approaches?.find((item) => item.segmentId === anchor.segmentId); if (constraint.kind !== 'junction-corner-radius' && !approach) { @@ -564,6 +604,7 @@ function solveConstraints(model, constraints, junctionData, diagnostics) { const roadProfiles = new Map(); const junctionPlans = new Map(); const laneManeuvers = new Map(); + const crossingControls = new Map(); const states = []; for (const constraint of constraints) { if (!constraint.enabled) { @@ -592,6 +633,7 @@ function solveConstraints(model, constraints, junctionData, diagnostics) { ]), ); const laneSnapshot = new Map(laneManeuvers); + const crossingSnapshot = new Map([...crossingControls].map(([key, value]) => [key, { ...value }])); const junctionSnapshot = new Map( [...junctionPlans].map(([key, plan]) => [ key, @@ -627,7 +669,7 @@ function solveConstraints(model, constraints, junctionData, diagnostics) { } else { applied = constraint.kind.startsWith('road-') ? applyRoadConstraint(model, constraint, roadProfiles, diagnostics) - : applyJunctionConstraint(model, constraint, junctionPlans, junctionData, diagnostics); + : applyJunctionConstraint(model, constraint, junctionPlans, junctionData, diagnostics, crossingControls); } if (!applied) { roadProfiles.clear(); @@ -636,10 +678,12 @@ function solveConstraints(model, constraints, junctionData, diagnostics) { for (const [key, plan] of junctionSnapshot) junctionPlans.set(key, plan); laneManeuvers.clear(); for (const [key, value] of laneSnapshot) laneManeuvers.set(key, value); + crossingControls.clear(); + for (const [key, value] of crossingSnapshot) crossingControls.set(key, value); } states.push(constraintState(constraint, applied, applied ? null : 'invalid')); } - return { roadProfiles, junctionPlans, laneManeuvers, states }; + return { roadProfiles, junctionPlans, laneManeuvers, crossingControls, states }; } function roadAffects(roads, model, side, boundaryIndex) { @@ -820,15 +864,7 @@ function junctionAffects(model, nodeId, segmentIds) { function makeJunctionHandles(model, junctionData, constraints) { const handles = []; - // Which crossing each approach road serves, so the crosswalk handle can publish - // a ceiling that actually moves the zebra. Built once: `approachForCrossing()` - // scans the roads per crossing. - const crossingByRoadId = new Map(); const arrivals = arrivalEndpointIds(model || {}); - for (const crossing of model.crossings || []) { - const match = approachForCrossing(model, crossing, arrivals); - if (match) crossingByRoadId.set(match.road.id, match); - } for (const [nodeId, approaches] of junctionData.approaches) { const segmentIds = new Set(approaches.map((item) => item.segmentId)); for (const approach of approaches) { @@ -886,60 +922,106 @@ function makeJunctionHandles(model, junctionData, constraints) { tangent, cutbackConstraint, ); - // Control markings sit inside the reserve but are not junction *shape*, so - // they drag along the approach tangent like the cutback does. - // - // The ceiling is per-approach, not the flat MAX_CROSSWALK_INSET_METERS this - // used to publish: `crossingJunctionInset()` saturates once the inset - // reaches the cutback, and sooner when the crossing sits far from the - // junction. Measured across eight groups the real ceiling ran 1.0–4.5m - // against a declared 8, leaving 44–88% of the range moving nothing and - // saying nothing — the dead-control failure `flag.ts` exists to prevent. - // `approach.items` can hold both directional roads of a segment, and each - // may serve a different crossing at a different junction. Take the one that - // actually ends here — the same last-source-node rule - // `crossingJunctionInset()` uses to find its junction plan. Without the - // filter, two handles on one segment published the same ceiling, and one of - // them was wrong. - const crossing = approach.items - .filter((item) => String(item.road.sourceNodeIds?.at(-1)) === String(nodeId)) - .map((item) => crossingByRoadId.get(item.road.id)) - .find(Boolean); - const crosswalkConstraint = constraintFor(constraints, 'junction-crosswalk-inset', anchor); - const insetValue = numericValue(crosswalkConstraint, 'insetMeters', CROSSWALK_JUNCTION_INSET_METERS); - const cutbackValue = numericValue(cutbackConstraint, 'cutbackMeters', approach.cutback); - const ceiling = crossing - ? effectiveCrosswalkInsetMax(cutbackValue, crossing.junctionDistanceMeters) - : MAX_CROSSWALK_INSET_METERS; - // Never below the value already in force: a max under `current` would be a - // manifest that contradicts itself. Equal to it is honest — it says this - // approach has no headroom left, which is a real state. + // Synthetic models used by older resolver consumers may not carry crossing + // features. Keep their approach-level controls for compatibility; real + // models below always publish element-owned crossing handles. + if (!(model.crossings || []).length) { + const insetConstraint = constraintFor(constraints, 'junction-crosswalk-inset', anchor); + const insetValue = numericValue(insetConstraint, 'insetMeters', CROSSWALK_JUNCTION_INSET_METERS); + add( + 'junction-crosswalk-inset', + insetValue, + 0, + MAX_CROSSWALK_INSET_METERS, + (tangent + 180) % 360, + insetConstraint, + controlPoint(insetValue, -1), + ); + const stopConstraint = constraintFor(constraints, 'junction-stop-line-offset', anchor); + const stopValue = numericValue(stopConstraint, 'offsetMeters', STOP_LINE_OFFSET_METERS); + add( + 'junction-stop-line-offset', + stopValue, + MIN_STOP_LINE_OFFSET_METERS, + Math.max(MIN_STOP_LINE_OFFSET_METERS, approach.length * 0.45), + tangent, + stopConstraint, + controlPoint(stopValue, 1), + ); + } + } + // Control-marking handles are element-owned. A single approach may serve + // multiple crossings, so each handle carries the crossing id as well as the + // road context needed to resolve its geometry. + for (const crossing of model.crossings || []) { + const match = approachForCrossing(model, crossing, arrivals); + if (!match || String(match.road.sourceNodeIds?.at(-1)) !== String(nodeId)) continue; + const approach = approaches.find((item) => item.segmentId === match.road.segmentId); + if (!approach) continue; + const road = match.road; + const line = approach.endpoint.side === 'start' ? road.centerline : [...road.centerline].reverse(); + const tangent = tangentAzimuth(line, Math.min(0.95, approach.cutback / approach.length)); + const placementAzimuth = tangent; + const anchorBase = { + type: 'junction-crossing', + crossingId: String(crossing.id), + nodeId: String(nodeId), + segmentId: approach.segmentId, + roadId: road.id, + }; + const controlPoint = (offsetMeters, lateralMeters = 0) => { + const point = coordinateAt(line, Math.min(0.98, Math.max(0.02, offsetMeters / Math.max(approach.length, 1)))); + return lateralMeters ? offsetCoordinate(point, (tangent + 90) % 360, lateralMeters) : point; + }; + const insetConstraint = constraintFor(constraints, 'junction-crosswalk-inset', anchorBase); + const insetValue = numericValue(insetConstraint, 'insetMeters', CROSSWALK_JUNCTION_INSET_METERS); + // The solver may saturate the inset at the junction boundary; the + // configured value is still the closest stable client-side knob position. + const insetApplied = insetValue; const insetMax = Math.min( MAX_CROSSWALK_INSET_METERS, - Math.max(insetValue, Number.isFinite(ceiling) ? ceiling : MAX_CROSSWALK_INSET_METERS), - ); - add( - 'junction-crosswalk-inset', - insetValue, - 0, - insetMax, - // The approach tangent points away from the junction. Increasing an - // inset moves the crosswalk toward the junction, so expose the inverse - // axis to keep positive drag values aligned with the handle's meaning. - (tangent + 180) % 360, - crosswalkConstraint, - controlPoint(insetValue, -1), - ); - const stopLineConstraint = constraintFor(constraints, 'junction-stop-line-offset', anchor); - add( - 'junction-stop-line-offset', - numericValue(stopLineConstraint, 'offsetMeters', STOP_LINE_OFFSET_METERS), - MIN_STOP_LINE_OFFSET_METERS, - Math.max(MIN_STOP_LINE_OFFSET_METERS, approach.length * 0.45), - tangent, - stopLineConstraint, - controlPoint(numericValue(stopLineConstraint, 'offsetMeters', STOP_LINE_OFFSET_METERS), 1), + Math.max(insetValue, effectiveCrosswalkInsetMax(approach.cutback, match.junctionDistanceMeters) || insetValue), ); + handles.push({ + handleId: `handle:junction-crosswalk-inset:crossing/${crossing.id}`, + kind: 'junction-crosswalk-inset', + anchor: anchorBase, + // Anchor the knob to the actual crossing feature. The inset is a value + // along the approach, not a reliable screen station from the junction; + // deriving the point from junction distance put the knob off the zebra. + position: offsetCoordinate(crossing.coordinate, placementAzimuth, insetApplied), + axisAzimuth: (tangent + 180) % 360, + value: { current: insetValue, min: 0, max: insetMax, unit: 'meter' }, + ...(insetConstraint ? { constraintId: insetConstraint.id } : {}), + affects: [`crosswalk:node/${crossing.id}`], + editable: true, + }); + const stopConstraint = constraintFor(constraints, 'junction-stop-line-offset', anchorBase); + const stopValue = numericValue(stopConstraint, 'offsetMeters', STOP_LINE_OFFSET_METERS); + handles.push({ + handleId: `handle:junction-stop-line-offset:crossing/${crossing.id}`, + kind: 'junction-stop-line-offset', + anchor: anchorBase, + // The stop line is measured back from the crossing, so its knob follows + // the rendered line while remaining independent of the road cutback. + position: offsetCoordinate( + offsetCoordinate(crossing.coordinate, placementAzimuth, insetApplied), + placementAzimuth, + -stopValue, + ), + // The compiled stop line applies `-offset` along the approach axis, so + // this tangent is the positive drag direction for increasing offset. + axisAzimuth: tangent, + value: { + current: stopValue, + min: MIN_STOP_LINE_OFFSET_METERS, + max: Math.max(MIN_STOP_LINE_OFFSET_METERS, approach.length * 0.45), + unit: 'meter', + }, + ...(stopConstraint ? { constraintId: stopConstraint.id } : {}), + affects: [`stop-line:node/${crossing.id}:1`], + editable: true, + }); } const ordered = [...approaches].sort((a, b) => a.segmentId.localeCompare(b.segmentId)); for (let index = 0; index < ordered.length; index += 1) { @@ -1048,6 +1130,7 @@ function resolveDirectEditConstraints(model, editDocument = null, context = {}) schema: RESOLUTION_SCHEMA, roadProfiles: solved.roadProfiles, junctionPlans: solved.junctionPlans, + crossingControls: solved.crossingControls, laneManeuvers: solved.laneManeuvers, handles, constraintStates: solved.states, diff --git a/src/compile/native-road-edits.js b/src/compile/native-road-edits.js index e9c009a..d62a3d9 100644 --- a/src/compile/native-road-edits.js +++ b/src/compile/native-road-edits.js @@ -21,7 +21,14 @@ const CONSTRAINT_ANCHORS = { 'lane-maneuver': 'lane', }; const CONSTRAINT_KINDS = Object.freeze(Object.keys(CONSTRAINT_ANCHORS)); -const ANCHOR_TYPES = new Set(['road-station', 'road-interval', 'junction-approach', 'junction-corner', 'lane']); +const ANCHOR_TYPES = new Set([ + 'road-station', + 'road-interval', + 'junction-approach', + 'junction-crossing', + 'junction-corner', + 'lane', +]); const CONSTRAINT_STATUSES = new Set(['exact', 'recheck', 'pending', 'conflicted', 'stale']); const TRANSITIONS = new Set(['smoothstep', 'linear']); const SIDES = new Set(['left', 'right']); @@ -63,7 +70,11 @@ function validateAnchor(scope, kind, anchor) { const expected = CONSTRAINT_ANCHORS[kind]; if (!anchor || typeof anchor !== 'object') fail(scope, 'anchor', 'is required'); if (!ANCHOR_TYPES.has(anchor.type)) fail(scope, 'anchor.type', `is not a known anchor type (got ${anchor.type})`); - if (anchor.type !== expected) fail(scope, 'anchor.type', `must be ${expected} for kind ${kind} (got ${anchor.type})`); + // Existing v2 documents used junction-approach for control markings. Accept + // those anchors for replay while new manifests write element-level crossings. + const crossingControl = expected === 'junction-approach' && anchor.type === 'junction-crossing'; + if (anchor.type !== expected && !crossingControl) + fail(scope, 'anchor.type', `must be ${expected} for kind ${kind} (got ${anchor.type})`); if (anchor.side !== undefined && !SIDES.has(anchor.side)) fail(scope, 'anchor.side', 'must be left or right'); if (expected === 'road-station') { requireString(scope, 'anchor.roadId', anchor.roadId); @@ -74,9 +85,19 @@ function validateAnchor(scope, kind, anchor) { requireStation(scope, 'anchor.endStation', anchor.endStation); if (anchor.startStation >= anchor.endStation) fail(scope, 'anchor.startStation', 'must be strictly less than anchor.endStation'); + } else if (crossingControl) { + requireString(scope, 'anchor.crossingId', anchor.crossingId); + requireString(scope, 'anchor.nodeId', anchor.nodeId); + requireString(scope, 'anchor.segmentId', anchor.segmentId); + requireString(scope, 'anchor.roadId', anchor.roadId); } else if (expected === 'junction-approach') { requireString(scope, 'anchor.nodeId', anchor.nodeId); requireString(scope, 'anchor.segmentId', anchor.segmentId); + } else if (expected === 'junction-crossing') { + requireString(scope, 'anchor.crossingId', anchor.crossingId); + requireString(scope, 'anchor.nodeId', anchor.nodeId); + requireString(scope, 'anchor.segmentId', anchor.segmentId); + requireString(scope, 'anchor.roadId', anchor.roadId); } else if (expected === 'junction-corner') { requireString(scope, 'anchor.nodeId', anchor.nodeId); requireString(scope, 'anchor.incomingRoadId', anchor.incomingRoadId); diff --git a/src/compile/native-road.js b/src/compile/native-road.js index bee74fd..ea3b7bb 100644 --- a/src/compile/native-road.js +++ b/src/compile/native-road.js @@ -777,7 +777,13 @@ function compileGeometry(model, overrides = { overrides: [] }, options = {}) { }); const edgeLines = options.edgeLines === false ? [] : compileEdgeLines(model, overrides, junctionPlans, options, features); - const controls = compileControlMarkings(model, lanes, diagnostics, junctionPlans); + const controls = compileControlMarkings( + model, + lanes, + diagnostics, + junctionPlans, + options.directEdit?.crossingControls, + ); const allControls = { crosswalks: [...controls.crosswalks, ...generatedComplexCrosswalks], stopLines: [...controls.stopLines, ...generatedComplexStopLines], @@ -1223,7 +1229,7 @@ function edgeLineStyle(overrides, roadId, side) { return value ? { color: value.color, pattern: value.pattern } : { color: 'white', pattern: 'solid' }; } -function compileControlMarkings(model, lanes, diagnostics, junctionPlans = new Map()) { +function compileControlMarkings(model, lanes, diagnostics, junctionPlans = new Map(), crossingControls = new Map()) { const crosswalks = []; const stopLines = []; const arrivalEndpointIds = new Set( @@ -1267,7 +1273,10 @@ function compileControlMarkings(model, lanes, diagnostics, junctionPlans = new M (a, b) => a.junctionDistanceMeters - b.junctionDistanceMeters || a.placement.distance - b.placement.distance, )[0]; const crosswalkCandidate = approach || candidate; - const junctionInsetMeters = approach ? crossingJunctionInset(approach, junctionPlans, model) : 0; + const crossingOverride = crossingControls.get(String(crossing.id)); + const junctionInsetMeters = approach + ? crossingJunctionInset(approach, junctionPlans, model, crossingOverride?.crosswalkInsetMeters) + : 0; const controlCenter = offsetByMeters(crossing.coordinate, crosswalkCandidate.placement.axis, junctionInsetMeters); const { axis } = crosswalkCandidate.placement; const across = [-axis[1], axis[0]]; @@ -1314,7 +1323,9 @@ function compileControlMarkings(model, lanes, diagnostics, junctionPlans = new M const stopCenter = offsetByMeters( laneCenterAtCrossing, approach.placement.axis, - -approachControls(junctionPlans, approach.road, model).stopLineOffsetMeters, + -(Number.isFinite(crossingOverride?.stopLineOffsetMeters) + ? crossingOverride.stopLineOffsetMeters + : approachControls(junctionPlans, approach.road, model).stopLineOffsetMeters), ); stopLines.push( controlFeature( @@ -1379,11 +1390,13 @@ function approachControls(junctionPlans, road, model) { }; } -function crossingJunctionInset(candidate, junctionPlans, model) { +function crossingJunctionInset(candidate, junctionPlans, model, overrideInset) { const junctionNodeId = candidate.road.sourceNodeIds.at(-1); const plan = junctionPlans.get(junctionNodeId); if (!plan) return 0; - const inset = approachControls(junctionPlans, candidate.road, model).crosswalkInsetMeters; + const inset = Number.isFinite(overrideInset) + ? overrideInset + : approachControls(junctionPlans, candidate.road, model).crosswalkInsetMeters; const targetDistance = Math.max(0, plan.cutbackMeters - inset); return Math.min(CROSSWALK_MAX_JUNCTION_INSET_METERS, Math.max(0, candidate.junctionDistanceMeters - targetDistance)); } diff --git a/workbench/client/src/App.tsx b/workbench/client/src/App.tsx index 588093b..a3e6da9 100644 --- a/workbench/client/src/App.tsx +++ b/workbench/client/src/App.tsx @@ -170,6 +170,20 @@ function App() { * element box and its controls hang off this. */ const [element, setElement] = useState(null); + const visibleEditHandles = useMemo(() => { + if (!element || element.kind === 'lane-maneuver') return editHandles; + const constraintKind = specOfKind(element.kind).constraintKind; + // Control markings use the selected outline itself as their drag target, + // exactly like lane-maneuver. Keep the selected control in the index so the + // outline can resolve its semantics, while the layer hides its duplicate dot. + return editHandles.filter( + (handle) => + !handle.kind.startsWith('junction-cross') || + (handle.kind === constraintKind && + handle.anchor.type === 'junction-crossing' && + String(handle.anchor.crossingId) === String(element.crossingNodeId)), + ); + }, [editHandles, element]); /** * The selected element as something to draw and grab. * @@ -189,7 +203,7 @@ function App() { const layer = specOfKind(element.kind).layer; const drawn = preview?.[layer] ?? state.layers[layer]; const bounds = orientedBoundsOf(groupMembers(drawn?.features ?? [], element.elementId)); - return bounds ? { handleId: handle.handleId, bounds } : null; + return bounds ? { handleId: handle.handleId, bounds, hideOtherHandles: true } : null; }, [editMode, element, editHandles, state, preview]); const laneSelectionBounds = useMemo(() => { if (!element || element.kind !== 'lane-maneuver' || !state || !element.featureIds.length) return null; @@ -785,7 +799,7 @@ function App() { onSignalDragEnd={finishSignalMove} onSignalRotate={rotateSignal} onSignalRotateEnd={finishSignalRotate} - handles={editHandles} + handles={visibleEditHandles} ranges={editRanges} element={elementOutline} laneSelectionBounds={laneSelectionBounds} diff --git a/workbench/client/src/edit/element.ts b/workbench/client/src/edit/element.ts index b475a8e..a6771af 100644 --- a/workbench/client/src/edit/element.ts +++ b/workbench/client/src/edit/element.ts @@ -263,12 +263,20 @@ export function handleForElement + handle.kind === spec.constraintKind && + handle.anchor.type === 'junction-crossing' && + String(handle.anchor.crossingId) === String(element.crossingNodeId), + ) ?? + // Accept legacy manifests while a saved server document is being upgraded. handles.find( (handle) => handle.kind === spec.constraintKind && handle.anchor.segmentId === road.segmentId && String(handle.anchor.nodeId) === String(nodeId), - ) ?? null + ) ?? + null ); } diff --git a/workbench/client/src/edit/ghost-layer.ts b/workbench/client/src/edit/ghost-layer.ts index 02398ac..7cedbac 100644 --- a/workbench/client/src/edit/ghost-layer.ts +++ b/workbench/client/src/edit/ghost-layer.ts @@ -82,6 +82,14 @@ export class EditGhostLayer { * whether you have hit the limit. */ show(handle: EditHandle, value: number): void { + // Control markings are dragged from their selected outline, like lane + // maneuvers. The generic scalar knob/readout would reintroduce a confusing + // blue point and "+N 米" label, so let the preview outline be the only feedback. + if (handle.kind === 'junction-crosswalk-inset' || handle.kind === 'junction-stop-line-offset') { + this.pending = false; + this.source.clear(); + return; + } const clamped = value >= handle.value.max - 1e-6 || value <= handle.value.min + 1e-6; const delta = value - handle.value.current; this.pending = false; diff --git a/workbench/client/src/edit/handle-layer.ts b/workbench/client/src/edit/handle-layer.ts index 3c016bc..81ac8eb 100644 --- a/workbench/client/src/edit/handle-layer.ts +++ b/workbench/client/src/edit/handle-layer.ts @@ -34,6 +34,8 @@ export interface ElementOutline { handleId: string; /** Four corners, EPSG:4326, oriented along the element. */ bounds: Coordinate[]; + /** Hide every point handle while a control element owns the gesture. */ + hideOtherHandles?: boolean; } const EDITABLE_STYLE: Record = { @@ -96,6 +98,7 @@ export class EditHandleLayer { private index = new Map(); private ranges = new Map(); private elementIds = new Set(); + private hideOtherHandles = false; constructor() { this.layer = new VectorLayer({ @@ -104,10 +107,17 @@ export class EditHandleLayer { zIndex: 100, style: (feature) => { const id = String(feature.get(HANDLE_ID)); - if (this.elementIds.has(id)) return ELEMENT_STYLE; + if (this.elementIds.has(id)) { + // The selected element outline owns the drag gesture. Its companion + // point is kept in the semantic index but must not be painted as a + // confusing second red/green control dot. + return feature.getGeometry()?.getType() === 'Polygon' ? ELEMENT_STYLE : undefined; + } + if (this.hideOtherHandles && feature.getGeometry()?.getType() === 'Point') return undefined; if (this.ranges.has(id)) return RANGE_STYLE; const handle = this.index.get(id); if (!handle) return undefined; + if (handle.kind === 'junction-crosswalk-inset' || handle.kind === 'junction-stop-line-offset') return undefined; return handle.editable ? EDITABLE_STYLE[handle.kind] : DISABLED_STYLE; }, }); @@ -126,6 +136,7 @@ export class EditHandleLayer { this.index = new Map(handles.map((handle) => [handle.handleId, handle])); this.ranges = new Map(ranges.map((range) => [range.handleId, range])); this.elementIds = new Set(element ? [element.handleId] : []); + this.hideOtherHandles = element?.hideOtherHandles === true; this.source.clear(); if (element) this.source.addFeatures([ @@ -134,8 +145,11 @@ export class EditHandleLayer { [HANDLE_ID]: element.handleId, }), ]); + const renderedHandles = element?.hideOtherHandles + ? handles.filter((handle) => handle.handleId === element.handleId) + : handles; this.source.addFeatures( - [...handles, ...ranges].map( + [...renderedHandles, ...(element?.hideOtherHandles ? [] : ranges)].map( (handle) => new Feature({ geometry: new Point(fromLonLat(handle.position)), @@ -149,6 +163,7 @@ export class EditHandleLayer { this.index = new Map(); this.ranges = new Map(); this.elementIds = new Set(); + this.hideOtherHandles = false; this.source.clear(); } diff --git a/workbench/client/src/edit/types.ts b/workbench/client/src/edit/types.ts index 43f5eb7..764454b 100644 --- a/workbench/client/src/edit/types.ts +++ b/workbench/client/src/edit/types.ts @@ -59,6 +59,7 @@ export type SemanticAnchor = boundaryIndex?: number; } | { type: 'junction-approach'; nodeId: string; segmentId: string; side?: Side } + | { type: 'junction-crossing'; crossingId: string; nodeId: string; segmentId: string; roadId: string } | { type: 'junction-corner'; nodeId: string; incomingRoadId: string; outgoingRoadId: string }; export type RoadIntervalAnchor = Extract;