feat(junction): edit complex crossing facilities
This commit is contained in:
1 parent
bb5dc01c07
commit
49a44fdf73
16 files changed
+307
-39
No files matched your search
@@ -316,9 +316,9 @@ then `structureFromTopology(topology, shape, center, features)`. Projection is
|
||||
`cluster:<id>`. The legacy singular field is null at this unscoped entry point.
|
||||
- `GET /api/edit-state?junction=<node>` preserves the node selection contract;
|
||||
`?cluster=<id>` selects a cluster. Preview uses the equivalent `selection`
|
||||
object. A selected editable cluster publishes `cluster-carriageway-width`,
|
||||
`cluster-carriageway-cutback`, and `cluster-corner-radius` handles only for
|
||||
its external geometry.
|
||||
object. A selected editable cluster publishes its external carriageway and
|
||||
corner handles plus `cluster-crossing-inset` and
|
||||
`cluster-stop-line-offset` for each external arm crossing.
|
||||
- A cluster carriageway anchor contains `clusterId`, stable
|
||||
`carriagewayKey`, `sourceNodeIds`, and `sourceRoadIds`. Replay matches all
|
||||
source identity; a missing or changed source is stale with `anchor-missing`.
|
||||
@@ -330,6 +330,14 @@ then `structureFromTopology(topology, shape, center, features)`. Projection is
|
||||
source-sorted arm grouping used by `resolveComplexJunctionTopology()`. The
|
||||
complex generator reads a local radius by that `cornerKey`; no other corner is
|
||||
rewritten.
|
||||
- A cluster crossing anchor contains `clusterId`, stable
|
||||
`crossingKey` (`crossing:<armKey>`), and its source-backed carriageway keys.
|
||||
Crosswalk inset is in `0..8` m; stop-line offset is in `0.5..12` m. Replay
|
||||
resolves the same arm grouping and marks a missing arm `stale/anchor-missing`.
|
||||
Generated crosswalk stripes and stop lines publish that `crossing_key`; the
|
||||
generator applies the inset once per stripe group and positions each incoming
|
||||
stop line relative to its matching crossing. Never identify these facilities
|
||||
by `crossing_node_id`, because complex members can share a node.
|
||||
- Preview and save both evaluate the same candidate through the resolver and
|
||||
`compileGeometry()`. Save rejects every `severity: error` diagnostic before
|
||||
writing the edit document.
|
||||
|
||||
@@ -285,10 +285,12 @@ requests so a cluster never falls back to the last selected road or node.
|
||||
|
||||
Complex JunctionTools consumes the same v2 `EditSession`, `PreviewRequester`,
|
||||
`ParameterPanel`, and map handle callbacks as ordinary junctions. Editable
|
||||
handles are `cluster-carriageway-width`, `cluster-carriageway-cutback`, and
|
||||
`cluster-corner-radius`. The first two use a `cluster-carriageway` anchor; a
|
||||
handles include `cluster-carriageway-width`, `cluster-carriageway-cutback`,
|
||||
`cluster-corner-radius`, `cluster-crossing-inset`, and
|
||||
`cluster-stop-line-offset`. The first two use a `cluster-carriageway` anchor; a
|
||||
corner anchor is resolved to its representative carriageway only to create the
|
||||
snapshot. Before edit mode, a selected cluster loads its scoped manifest so
|
||||
snapshot; crossing controls use `cluster-crossing` and its stable
|
||||
`crossingKey`. Before edit mode, a selected cluster loads its scoped manifest so
|
||||
`canEditJunction()` can use an editable server handle as the capability signal.
|
||||
Do not add a cluster-local draft, preview, undo, or save flow.
|
||||
|
||||
|
||||
@@ -151,7 +151,9 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
const crosswalks = [];
|
||||
const stopLines = [];
|
||||
const islands = [];
|
||||
const armCrosswalkRadius = coreRadius * 0.68;
|
||||
const crossingControls = helpers.clusterCrossingControls || new Map();
|
||||
const armCrosswalkRadiusFor = (arm) =>
|
||||
Math.max(1, coreRadius * 0.68 + (crossingControls.get(`crossing:${arm.key}`)?.crosswalkInsetMeters || 0));
|
||||
for (const item of carriageways) {
|
||||
// The approach plan owns the editable handoff distance. It shifts only this
|
||||
// carriageway's outer transition, leaving neighboring arms untouched.
|
||||
@@ -167,7 +169,11 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
if (incomingRoad) {
|
||||
// Keep the stop bar just outside the road crosswalk. The previous fixed
|
||||
// core-radius offset placed it nearly ten metres beyond the crossing.
|
||||
const stopCenter = pointOnCarriagewayRadius(item, center, armCrosswalkRadius + 3, helpers);
|
||||
const arm = arms.find((candidate) => candidate.members.includes(item));
|
||||
const crossingKey = `crossing:${arm.key}`;
|
||||
const crossingRadius = armCrosswalkRadiusFor(arm);
|
||||
const stopOffset = crossingControls.get(crossingKey)?.stopLineOffsetMeters || 3;
|
||||
const stopCenter = pointOnCarriagewayRadius(item, center, crossingRadius + stopOffset, helpers);
|
||||
const ring = [
|
||||
helpers.offsetCoordinate(
|
||||
helpers.offsetCoordinate(stopCenter, item.heading + 90, -outerHalf),
|
||||
@@ -200,6 +206,7 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
properties: {
|
||||
native_id: `complex-stop-line:${cluster.id}:${item.approach.segmentId}`,
|
||||
object_key: `stop-line:${item.key}`,
|
||||
crossing_key: crossingKey,
|
||||
arm_key: item.armKey,
|
||||
carriageway_key: item.key,
|
||||
cluster_id: cluster.id,
|
||||
@@ -217,6 +224,8 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
// crossing remains clipped to its OSM-derived road envelope. Corner islands
|
||||
// fill the remaining frame gaps; crossings must never do that job.
|
||||
for (const arm of arms) {
|
||||
const armCrosswalkRadius = armCrosswalkRadiusFor(arm);
|
||||
arm.crosswalkRadius = armCrosswalkRadius;
|
||||
const envelope = armEnvelopeAtRadius(arm, armCrosswalkRadius, center, helpers);
|
||||
if (!envelope) continue;
|
||||
arm.crosswalkFrame = {
|
||||
@@ -285,13 +294,14 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
properties: {
|
||||
native_id: `complex-crosswalk:${cluster.id}:${item.nodeId}:${item.approach.segmentId}:${stripe + 1}`,
|
||||
object_key: `crossing:${arm.key}`,
|
||||
crossing_key: `crossing:${arm.key}`,
|
||||
arm_key: arm.key,
|
||||
cluster_id: cluster.id,
|
||||
kind: 'complex-crosswalk',
|
||||
crossing_node_id: item.nodeId,
|
||||
road_id: item.approach.roadIds[0],
|
||||
direction: arm.heading,
|
||||
radial_distance_m: armCrosswalkRadius,
|
||||
radial_distance_m: arm.crosswalkRadius,
|
||||
span_m: usableSpan,
|
||||
road_envelope_span_m: arm.crosswalkFrame.envelopeWidthMeters,
|
||||
road_edge_inset_m: roadEdgeInset,
|
||||
|
||||
@@ -26,6 +26,8 @@ const SOLVED_KINDS = new Set([
|
||||
'cluster-carriageway-width',
|
||||
'cluster-carriageway-cutback',
|
||||
'cluster-corner-radius',
|
||||
'cluster-crossing-inset',
|
||||
'cluster-stop-line-offset',
|
||||
'junction-cutback',
|
||||
'junction-corner-radius',
|
||||
'junction-crosswalk-inset',
|
||||
@@ -41,6 +43,8 @@ const KINDS = [
|
||||
'cluster-carriageway-width',
|
||||
'cluster-carriageway-cutback',
|
||||
'cluster-corner-radius',
|
||||
'cluster-crossing-inset',
|
||||
'cluster-stop-line-offset',
|
||||
'junction-cutback',
|
||||
'junction-corner-radius',
|
||||
'junction-crosswalk-inset',
|
||||
@@ -179,6 +183,12 @@ function constraintFor(constraints, kind, anchor) {
|
||||
item.anchor.clusterId === anchor.clusterId &&
|
||||
item.anchor.cornerKey === anchor.cornerKey
|
||||
);
|
||||
if (kind === 'cluster-crossing-inset' || kind === 'cluster-stop-line-offset')
|
||||
return (
|
||||
item.anchor.type === 'cluster-crossing' &&
|
||||
item.anchor.clusterId === anchor.clusterId &&
|
||||
item.anchor.crossingKey === anchor.crossingKey
|
||||
);
|
||||
if (kind === 'junction-crosswalk-inset' || kind === 'junction-stop-line-offset')
|
||||
return (
|
||||
item.anchor.type === 'junction-crossing' &&
|
||||
@@ -417,6 +427,15 @@ function reconcileConstraints(model, constraints, base, junctionData, context) {
|
||||
if (versionChanged) return { ...constraint, status: 'recheck' };
|
||||
return constraint;
|
||||
}
|
||||
if (constraint.kind === 'cluster-crossing-inset' || constraint.kind === 'cluster-stop-line-offset') {
|
||||
const arm = clusterArms(
|
||||
String(constraint.anchor.clusterId),
|
||||
clusterItems.get(String(constraint.anchor.clusterId)) || [],
|
||||
).find((candidate) => `crossing:${candidate.key}` === constraint.anchor.crossingKey);
|
||||
if (!arm) return { ...constraint, status: 'stale', replayReason: 'anchor-missing' };
|
||||
if (versionChanged) return { ...constraint, status: 'recheck' };
|
||||
return constraint;
|
||||
}
|
||||
if (constraint.kind.startsWith('road-')) {
|
||||
const road = roadForAnchor(model, constraint.anchor.roadId);
|
||||
matched = Boolean(road);
|
||||
@@ -767,6 +786,7 @@ function solveConstraints(model, constraints, junctionData, diagnostics, cluster
|
||||
const clusterPlans = new Map();
|
||||
const clusterCutbacks = new Map();
|
||||
const clusterCorners = new Map();
|
||||
const clusterCrossings = new Map();
|
||||
const clusterItems = clusterCarriageways(model, junctionData, clusters);
|
||||
const states = [];
|
||||
for (const constraint of constraints) {
|
||||
@@ -800,6 +820,7 @@ function solveConstraints(model, constraints, junctionData, diagnostics, cluster
|
||||
const clusterSnapshot = new Map([...clusterPlans].map(([key, value]) => [key, new Map(value)]));
|
||||
const cutbackSnapshot = new Map([...clusterCutbacks].map(([key, value]) => [key, new Map(value)]));
|
||||
const cornerSnapshot = new Map([...clusterCorners].map(([key, value]) => [key, new Map(value)]));
|
||||
const crossingClusterSnapshot = new Map([...clusterCrossings].map(([key, value]) => [key, new Map(value)]));
|
||||
const junctionSnapshot = new Map(
|
||||
[...junctionPlans].map(([key, plan]) => [
|
||||
key,
|
||||
@@ -855,6 +876,30 @@ function solveConstraints(model, constraints, junctionData, diagnostics, cluster
|
||||
clusterCorners.get(String(cluster.id)).set(String(constraint.anchor.cornerKey), radius);
|
||||
applied = true;
|
||||
}
|
||||
} else if (constraint.kind === 'cluster-crossing-inset' || constraint.kind === 'cluster-stop-line-offset') {
|
||||
const clusterId = String(constraint.anchor?.clusterId);
|
||||
const arm = clusterArms(clusterId, clusterItems.get(clusterId) || []).find(
|
||||
(candidate) => `crossing:${candidate.key}` === constraint.anchor?.crossingKey,
|
||||
);
|
||||
const value = Number(constraint.value?.insetMeters ?? constraint.value?.offsetMeters);
|
||||
const min = constraint.kind === 'cluster-crossing-inset' ? 0 : MIN_STOP_LINE_OFFSET_METERS;
|
||||
const max = constraint.kind === 'cluster-crossing-inset' ? MAX_CROSSWALK_INSET_METERS : 12;
|
||||
if (!arm || !Number.isFinite(value) || value < min || value > max) {
|
||||
blocking(
|
||||
diagnostics,
|
||||
constraint,
|
||||
'direct-edit-cluster-crossing-invalid',
|
||||
'复杂路口过街控制元素超出当前可用范围。',
|
||||
);
|
||||
applied = false;
|
||||
} else {
|
||||
if (!clusterCrossings.has(clusterId)) clusterCrossings.set(clusterId, new Map());
|
||||
const control = clusterCrossings.get(clusterId).get(constraint.anchor.crossingKey) || {};
|
||||
if (constraint.kind === 'cluster-crossing-inset') control.crosswalkInsetMeters = value;
|
||||
else control.stopLineOffsetMeters = value;
|
||||
clusterCrossings.get(clusterId).set(constraint.anchor.crossingKey, control);
|
||||
applied = true;
|
||||
}
|
||||
} else if (constraint.kind === 'lane-maneuver') {
|
||||
const laneId = constraint.anchor?.laneId;
|
||||
const laneExists = Boolean(roadForLaneAnchor(model, laneId));
|
||||
@@ -896,6 +941,8 @@ function solveConstraints(model, constraints, junctionData, diagnostics, cluster
|
||||
for (const [key, value] of cutbackSnapshot) clusterCutbacks.set(key, value);
|
||||
clusterCorners.clear();
|
||||
for (const [key, value] of cornerSnapshot) clusterCorners.set(key, value);
|
||||
clusterCrossings.clear();
|
||||
for (const [key, value] of crossingClusterSnapshot) clusterCrossings.set(key, value);
|
||||
}
|
||||
states.push(constraintState(constraint, applied, applied ? null : 'invalid'));
|
||||
}
|
||||
@@ -907,6 +954,7 @@ function solveConstraints(model, constraints, junctionData, diagnostics, cluster
|
||||
clusterPlans,
|
||||
clusterCutbacks,
|
||||
clusterCorners,
|
||||
clusterCrossings,
|
||||
states,
|
||||
};
|
||||
}
|
||||
@@ -1406,6 +1454,56 @@ function makeClusterCornerHandles(model, junctionData, constraints, clusters) {
|
||||
return handles;
|
||||
}
|
||||
|
||||
function makeClusterCrossingHandles(model, junctionData, constraints, clusters) {
|
||||
const handles = [];
|
||||
const itemsByCluster = clusterCarriageways(model, junctionData, clusters);
|
||||
for (const cluster of clusters) {
|
||||
if (cluster.template !== 'complex-junction-v1') continue;
|
||||
const clusterId = String(cluster.id);
|
||||
for (const arm of clusterArms(clusterId, itemsByCluster.get(clusterId) || [])) {
|
||||
const item = arm.representative;
|
||||
const line = clusterApproachLine(item);
|
||||
const length = polylineLength(line);
|
||||
if (length <= 0) continue;
|
||||
const crossingKey = `crossing:${arm.key}`;
|
||||
const anchor = {
|
||||
type: 'cluster-crossing',
|
||||
clusterId,
|
||||
crossingKey,
|
||||
carriagewayKeys: arm.members.map((member) => member.key).sort(),
|
||||
};
|
||||
const pointAt = (distance) => coordinateAt(line, Math.min(0.9, Math.max(0.05, distance / length)));
|
||||
const insetConstraint = constraintFor(constraints, 'cluster-crossing-inset', anchor);
|
||||
const inset = numericValue(insetConstraint, 'insetMeters', 0);
|
||||
handles.push({
|
||||
handleId: `handle:cluster-crossing-inset:${crossingKey}`,
|
||||
kind: 'cluster-crossing-inset',
|
||||
anchor,
|
||||
position: pointAt(Math.max(2, item.approach.cutback * 0.68) + inset),
|
||||
axisAzimuth: arm.heading,
|
||||
value: { current: inset, min: 0, max: MAX_CROSSWALK_INSET_METERS, unit: 'meter' },
|
||||
...(insetConstraint ? { constraintId: insetConstraint.id } : {}),
|
||||
affects: [`complex-crosswalk:${clusterId}`],
|
||||
editable: true,
|
||||
});
|
||||
const stopConstraint = constraintFor(constraints, 'cluster-stop-line-offset', anchor);
|
||||
const offset = numericValue(stopConstraint, 'offsetMeters', 3);
|
||||
handles.push({
|
||||
handleId: `handle:cluster-stop-line-offset:${crossingKey}`,
|
||||
kind: 'cluster-stop-line-offset',
|
||||
anchor,
|
||||
position: pointAt(Math.max(2, item.approach.cutback * 0.68) + inset + offset),
|
||||
axisAzimuth: arm.heading,
|
||||
value: { current: offset, min: MIN_STOP_LINE_OFFSET_METERS, max: 12, unit: 'meter' },
|
||||
...(stopConstraint ? { constraintId: stopConstraint.id } : {}),
|
||||
affects: [`complex-stop-line:${clusterId}`],
|
||||
editable: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
return handles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Which handles a selection wants.
|
||||
*
|
||||
@@ -1469,6 +1567,7 @@ function resolveDirectEditConstraints(model, editDocument = null, context = {})
|
||||
...makeJunctionHandles(model || {}, junctionData, reconciled),
|
||||
...makeClusterCarriagewayHandles(model || {}, junctionData, reconciled, clusters),
|
||||
...makeClusterCornerHandles(model || {}, junctionData, reconciled, clusters),
|
||||
...makeClusterCrossingHandles(model || {}, junctionData, reconciled, clusters),
|
||||
...makeLaneManeuverHandles(model || {}, reconciled),
|
||||
],
|
||||
model || {},
|
||||
@@ -1483,6 +1582,7 @@ function resolveDirectEditConstraints(model, editDocument = null, context = {})
|
||||
clusterPlans: solved.clusterPlans,
|
||||
clusterCutbacks: solved.clusterCutbacks,
|
||||
clusterCorners: solved.clusterCorners,
|
||||
clusterCrossings: solved.clusterCrossings,
|
||||
laneManeuvers: solved.laneManeuvers,
|
||||
handles,
|
||||
constraintStates: solved.states,
|
||||
|
||||
@@ -16,6 +16,8 @@ const CONSTRAINT_ANCHORS = {
|
||||
'cluster-carriageway-width': 'cluster-carriageway',
|
||||
'cluster-carriageway-cutback': 'cluster-carriageway',
|
||||
'cluster-corner-radius': 'cluster-corner',
|
||||
'cluster-crossing-inset': 'cluster-crossing',
|
||||
'cluster-stop-line-offset': 'cluster-crossing',
|
||||
'junction-cutback': 'junction-approach',
|
||||
'junction-corner-radius': 'junction-corner',
|
||||
'junction-crosswalk-inset': 'junction-approach',
|
||||
@@ -32,6 +34,7 @@ const ANCHOR_TYPES = new Set([
|
||||
'junction-corner',
|
||||
'cluster-carriageway',
|
||||
'cluster-corner',
|
||||
'cluster-crossing',
|
||||
'lane',
|
||||
]);
|
||||
const CONSTRAINT_STATUSES = new Set(['exact', 'recheck', 'pending', 'conflicted', 'stale']);
|
||||
@@ -122,6 +125,15 @@ function validateAnchor(scope, kind, anchor) {
|
||||
!anchor.carriagewayKeys.every((key) => typeof key === 'string' && key)
|
||||
)
|
||||
fail(scope, 'anchor.carriagewayKeys', 'must contain exactly two carriageway keys');
|
||||
} else if (expected === 'cluster-crossing') {
|
||||
requireString(scope, 'anchor.clusterId', anchor.clusterId);
|
||||
requireString(scope, 'anchor.crossingKey', anchor.crossingKey);
|
||||
if (
|
||||
!Array.isArray(anchor.carriagewayKeys) ||
|
||||
!anchor.carriagewayKeys.length ||
|
||||
!anchor.carriagewayKeys.every((key) => typeof key === 'string' && key)
|
||||
)
|
||||
fail(scope, 'anchor.carriagewayKeys', 'must contain carriageway keys');
|
||||
} else if (expected === 'junction-crossing') {
|
||||
requireString(scope, 'anchor.crossingId', anchor.crossingId);
|
||||
requireString(scope, 'anchor.nodeId', anchor.nodeId);
|
||||
@@ -169,7 +181,7 @@ function validateValue(scope, kind, value) {
|
||||
} else if (kind === 'junction-corner-radius' || kind === 'cluster-corner-radius') {
|
||||
if (!isFiniteNumber(value.radiusMeters) || value.radiusMeters < 0)
|
||||
fail(scope, 'value.radiusMeters', 'must be a non-negative number of meters');
|
||||
} else if (kind === 'junction-crosswalk-inset') {
|
||||
} else if (kind === 'junction-crosswalk-inset' || kind === 'cluster-crossing-inset') {
|
||||
// How far the zebra sits back from the junction boundary. Negative would put
|
||||
// it inside the intersection surface.
|
||||
if (!isFiniteNumber(value.insetMeters) || value.insetMeters < 0)
|
||||
@@ -182,7 +194,7 @@ function validateValue(scope, kind, value) {
|
||||
fail(scope, 'value.depthMeters', 'must be a positive number of meters');
|
||||
if (!Number.isInteger(value.stripeCount) || value.stripeCount < 2)
|
||||
fail(scope, 'value.stripeCount', 'must be an integer of at least 2');
|
||||
} else if (kind === 'junction-stop-line-offset') {
|
||||
} else if (kind === 'junction-stop-line-offset' || kind === 'cluster-stop-line-offset') {
|
||||
// Distance from the crossing back along the approach. Zero would put the stop
|
||||
// line on the crosswalk itself.
|
||||
if (!isFiniteNumber(value.offsetMeters) || value.offsetMeters <= 0)
|
||||
|
||||
@@ -770,6 +770,7 @@ function compileGeometry(model, overrides = { overrides: [] }, options = {}) {
|
||||
headingVector,
|
||||
circleRing,
|
||||
clusterCornerRadii: options.directEdit?.clusterCorners?.get(String(cluster.id)),
|
||||
clusterCrossingControls: options.directEdit?.clusterCrossings?.get(String(cluster.id)),
|
||||
});
|
||||
features.push(...generated.features);
|
||||
if (generated.crosswalks) generatedComplexCrosswalks.push(...generated.crosswalks);
|
||||
|
||||
@@ -248,8 +248,13 @@ test.describe('workbench editing shell', () => {
|
||||
expect(
|
||||
scoped.handles.handles.every(
|
||||
(handle: { kind: string; editable: boolean }) =>
|
||||
['cluster-carriageway-width', 'cluster-carriageway-cutback', 'cluster-corner-radius'].includes(handle.kind) &&
|
||||
handle.editable,
|
||||
[
|
||||
'cluster-carriageway-width',
|
||||
'cluster-carriageway-cutback',
|
||||
'cluster-corner-radius',
|
||||
'cluster-crossing-inset',
|
||||
'cluster-stop-line-offset',
|
||||
].includes(handle.kind) && handle.editable,
|
||||
),
|
||||
).toBe(true);
|
||||
expect(scoped.junctionStructure.topologyFingerprint).toBe(structure.topologyFingerprint);
|
||||
|
||||
@@ -40,6 +40,13 @@ function anchorFor(kind) {
|
||||
cornerKey: 'corner:one>two',
|
||||
carriagewayKeys: ['carriageway:one', 'carriageway:two'],
|
||||
};
|
||||
if (type === 'cluster-crossing')
|
||||
return {
|
||||
type,
|
||||
clusterId: 'cluster/9',
|
||||
crossingKey: 'crossing:cluster:cluster%2F9:arm:one',
|
||||
carriagewayKeys: ['carriageway:one'],
|
||||
};
|
||||
if (type === 'lane') return { type, laneId: 'lane:road:way/1:forward:1' };
|
||||
return { type, nodeId: 'node/9', incomingRoadId: 'road:way/1:forward', outgoingRoadId: 'road:way/2:forward' };
|
||||
}
|
||||
@@ -63,6 +70,10 @@ function valueFor(kind) {
|
||||
return { cutbackMeters: 4 };
|
||||
case 'cluster-corner-radius':
|
||||
return { radiusMeters: 6 };
|
||||
case 'cluster-crossing-inset':
|
||||
return { insetMeters: 1.5 };
|
||||
case 'cluster-stop-line-offset':
|
||||
return { offsetMeters: 2.7 };
|
||||
case 'junction-cutback':
|
||||
return { cutbackMeters: 4 };
|
||||
case 'junction-corner-radius':
|
||||
@@ -126,6 +137,8 @@ assert.deepEqual(CONSTRAINT_KINDS, [
|
||||
'cluster-carriageway-width',
|
||||
'cluster-carriageway-cutback',
|
||||
'cluster-corner-radius',
|
||||
'cluster-crossing-inset',
|
||||
'cluster-stop-line-offset',
|
||||
'junction-cutback',
|
||||
'junction-corner-radius',
|
||||
'junction-crosswalk-inset',
|
||||
|
||||
@@ -258,7 +258,13 @@ const complexArea = compileInput(complexInput).area;
|
||||
const clusterState = editState(complexArea, selectionFrom({ cluster: cluster.id }));
|
||||
assert.ok(
|
||||
clusterState.handles.handles.every((handle) =>
|
||||
['cluster-carriageway-width', 'cluster-carriageway-cutback', 'cluster-corner-radius'].includes(handle.kind),
|
||||
[
|
||||
'cluster-carriageway-width',
|
||||
'cluster-carriageway-cutback',
|
||||
'cluster-corner-radius',
|
||||
'cluster-crossing-inset',
|
||||
'cluster-stop-line-offset',
|
||||
].includes(handle.kind),
|
||||
),
|
||||
'cluster selection publishes only scoped complex geometry handles',
|
||||
);
|
||||
@@ -322,6 +328,50 @@ assert.notDeepEqual(
|
||||
complexSurface(clusterPreview).geometry,
|
||||
'a cluster carriageway constraint must change compiled complex geometry',
|
||||
);
|
||||
const complexCrossingHandle = clusterState.handles.handles.find((handle) => handle.kind === 'cluster-crossing-inset');
|
||||
assert.ok(complexCrossingHandle, 'the complex fixture must publish grouped crossing handles');
|
||||
const complexCrossingConstraint = {
|
||||
id: 'constraint:complex-crossing',
|
||||
kind: 'cluster-crossing-inset',
|
||||
anchor: complexCrossingHandle.anchor,
|
||||
anchorSnapshot: {
|
||||
coordinate: complexCrossingHandle.position,
|
||||
tangentAzimuth: complexCrossingHandle.axisAzimuth,
|
||||
roadLengthMeters: 120,
|
||||
osmNodeIds: cluster.nodeIds,
|
||||
},
|
||||
value: { insetMeters: complexCrossingHandle.value.max },
|
||||
enabled: true,
|
||||
status: 'exact',
|
||||
provenance: { operationId: 'operation:complex-crossing', createdAt: '2026-09-08T00:00:00.000Z' },
|
||||
};
|
||||
const movedCrossingPreview = editPreview(complexArea, {
|
||||
document: {
|
||||
...emptyDocument,
|
||||
constraints: [complexCrossingConstraint],
|
||||
operations: [
|
||||
{
|
||||
id: 'operation:complex-crossing',
|
||||
createdAt: '2026-09-08T00:00:00.000Z',
|
||||
constraintIds: [complexCrossingConstraint.id],
|
||||
},
|
||||
],
|
||||
},
|
||||
selection: { cluster: cluster.id },
|
||||
});
|
||||
const crossingGeometry = (preview) =>
|
||||
preview.layers.crosswalks.features.find(
|
||||
(feature) => feature.properties.crossing_key === complexCrossingHandle.anchor.crossingKey,
|
||||
)?.geometry;
|
||||
assert.deepEqual(
|
||||
movedCrossingPreview.constraintStates?.map((state) => state.applied),
|
||||
[true],
|
||||
);
|
||||
assert.notDeepEqual(
|
||||
crossingGeometry(movedCrossingPreview),
|
||||
crossingGeometry(clusterPreview),
|
||||
'a complex crossing inset must move only its keyed stripe group',
|
||||
);
|
||||
const complexCornerHandle = clusterState.handles.handles.find((handle) => handle.kind === 'cluster-corner-radius');
|
||||
assert.ok(complexCornerHandle, 'the complex fixture must publish stable corner-radius handles');
|
||||
const complexCornerConstraint = {
|
||||
|
||||
@@ -268,7 +268,9 @@ function App() {
|
||||
(handle) =>
|
||||
(handle.kind === 'cluster-carriageway-width' ||
|
||||
handle.kind === 'cluster-carriageway-cutback' ||
|
||||
handle.kind === 'cluster-corner-radius') &&
|
||||
handle.kind === 'cluster-corner-radius' ||
|
||||
handle.kind === 'cluster-crossing-inset' ||
|
||||
handle.kind === 'cluster-stop-line-offset') &&
|
||||
'clusterId' in handle.anchor &&
|
||||
handle.anchor.clusterId === junctionDescriptor.ref.id,
|
||||
);
|
||||
@@ -334,16 +336,17 @@ function App() {
|
||||
const [element, setElement] = useState<ElementSelection | null>(null);
|
||||
const visibleEditHandles = useMemo(() => {
|
||||
if (!element || element.kind === 'lane-maneuver') return editHandles;
|
||||
const constraintKind = specOfKind(element.kind).constraintKind;
|
||||
const constraintKind = element.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.startsWith('junction-cross') && !handle.kind.startsWith('cluster-cross')) ||
|
||||
(handle.kind === constraintKind &&
|
||||
handle.anchor.type === 'junction-crossing' &&
|
||||
String(handle.anchor.crossingId) === String(element.crossingNodeId)),
|
||||
((handle.anchor.type === 'junction-crossing' &&
|
||||
String(handle.anchor.crossingId) === String(element.crossingNodeId)) ||
|
||||
(handle.anchor.type === 'cluster-crossing' && handle.anchor.crossingKey === element.crossingNodeId))),
|
||||
);
|
||||
}, [editHandles, element]);
|
||||
/**
|
||||
@@ -1316,6 +1319,7 @@ function App() {
|
||||
const feature = source?.features.find((item) => {
|
||||
if (facility.kind === 'signal')
|
||||
return String(item.properties?.signal_uid) === facility.id.slice('signal:'.length);
|
||||
if (facility.crossingKey) return String(item.properties?.crossing_key) === facility.crossingKey;
|
||||
return String(item.properties?.crossing_node_id) === facility.id.split(':').slice(1).join(':');
|
||||
});
|
||||
if (feature) handleFeature(feature.properties ?? {});
|
||||
|
||||
@@ -25,6 +25,8 @@ import { azimuthBetween, eastNorthMeters, haversineMeters, offsetCoordinate, typ
|
||||
export const CROSSWALK_PROVENANCE = 'native-road-crosswalk/v1';
|
||||
/** Stop lines share `controlFeature()`; kept so the two are never confused. */
|
||||
export const STOP_LINE_PROVENANCE = 'native-road-stop-line/v1';
|
||||
export const COMPLEX_CROSSWALK_PROVENANCE = 'native-road-complex-junction-crosswalk/v6-road-clipped';
|
||||
export const COMPLEX_STOP_LINE_PROVENANCE = 'native-road-complex-junction-stop-line/v1';
|
||||
/** Turn arrows are grouped by both the lane and the rendered maneuver. */
|
||||
export const TURN_ARROW_PROVENANCE = 'native-road-turn-arrow/v1';
|
||||
/** Lane centerlines are the entry point for lanes which do not yet draw an arrow. */
|
||||
@@ -50,7 +52,8 @@ export interface ElementSpec {
|
||||
/** Layer the members live in, in both `state.layers` and a preview. */
|
||||
layer: 'crosswalks' | 'vehicleStopLines' | 'turnArrows';
|
||||
/** The constraint that moves this control element. */
|
||||
constraintKind?: 'junction-crosswalk-inset' | 'junction-stop-line-offset';
|
||||
constraintKind?:
|
||||
'junction-crosswalk-inset' | 'junction-stop-line-offset' | 'cluster-crossing-inset' | 'cluster-stop-line-offset';
|
||||
label: string;
|
||||
/** Properties whose ordered values group rendered parts together. */
|
||||
groupProperties: readonly string[];
|
||||
@@ -72,6 +75,24 @@ export const ELEMENT_SPECS: readonly ElementSpec[] = [
|
||||
label: '斑马线',
|
||||
groupProperties: ['crossing_node_id'],
|
||||
},
|
||||
{
|
||||
kind: 'crosswalk',
|
||||
provenance: COMPLEX_CROSSWALK_PROVENANCE,
|
||||
idPrefix: 'complex-crosswalk:',
|
||||
layer: 'crosswalks',
|
||||
constraintKind: 'cluster-crossing-inset',
|
||||
label: '斑马线',
|
||||
groupProperties: ['crossing_key'],
|
||||
},
|
||||
{
|
||||
kind: 'stop-line',
|
||||
provenance: COMPLEX_STOP_LINE_PROVENANCE,
|
||||
idPrefix: 'complex-stop-line:',
|
||||
layer: 'vehicleStopLines',
|
||||
constraintKind: 'cluster-stop-line-offset',
|
||||
label: '停止线',
|
||||
groupProperties: ['crossing_key'],
|
||||
},
|
||||
{
|
||||
kind: 'stop-line',
|
||||
provenance: STOP_LINE_PROVENANCE,
|
||||
@@ -110,6 +131,7 @@ export interface ControlElementSelection {
|
||||
roadId: string;
|
||||
/** `native_id` of every member, for highlight and preview scoping. */
|
||||
featureIds: string[];
|
||||
constraintKind?: NonNullable<ElementSpec['constraintKind']>;
|
||||
}
|
||||
|
||||
/** A discrete v1 override target, selected from an arrow or a lane centerline. */
|
||||
@@ -215,7 +237,7 @@ export function elementSelectionFor(
|
||||
}
|
||||
: null;
|
||||
}
|
||||
const crossingNodeId = text(first.crossing_node_id);
|
||||
const crossingNodeId = text(first.crossing_key) ?? text(first.crossing_node_id);
|
||||
if (!crossingNodeId) return null;
|
||||
return {
|
||||
kind: spec.kind,
|
||||
@@ -223,6 +245,7 @@ export function elementSelectionFor(
|
||||
crossingNodeId,
|
||||
roadId,
|
||||
featureIds: members.map((member) => text(member.properties?.native_id)).filter((id): id is string => Boolean(id)),
|
||||
...(spec.constraintKind?.startsWith('cluster-') ? { constraintKind: spec.constraintKind } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -259,20 +282,31 @@ export function handleForElement<T extends { kind: string; anchor: Record<string
|
||||
handles: readonly T[],
|
||||
): T | null {
|
||||
const spec = specOfKind(element.kind);
|
||||
const constraintKind =
|
||||
element.constraintKind ?? (element.kind === 'crosswalk' ? 'junction-crosswalk-inset' : 'junction-stop-line-offset');
|
||||
if (constraintKind?.startsWith('cluster-'))
|
||||
return (
|
||||
handles.find(
|
||||
(handle) =>
|
||||
handle.kind === constraintKind &&
|
||||
handle.anchor.type === 'cluster-crossing' &&
|
||||
String(handle.anchor.crossingKey) === String(element.crossingNodeId),
|
||||
) ?? null
|
||||
);
|
||||
const road = roads.find((item) => item.id === element.roadId);
|
||||
const nodeId = road?.sourceNodeIds.at(-1);
|
||||
if (!road || nodeId === undefined) return null;
|
||||
return (
|
||||
handles.find(
|
||||
(handle) =>
|
||||
handle.kind === spec.constraintKind &&
|
||||
handle.kind === 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.kind === constraintKind &&
|
||||
handle.anchor.segmentId === road.segmentId &&
|
||||
String(handle.anchor.nodeId) === String(nodeId),
|
||||
) ??
|
||||
|
||||
@@ -116,6 +116,8 @@ const KIND_LABELS: Record<ConstraintKind, string> = {
|
||||
'cluster-carriageway-width': '车行道宽度',
|
||||
'cluster-carriageway-cutback': '车行道收口距离',
|
||||
'cluster-corner-radius': '角部圆角',
|
||||
'cluster-crossing-inset': '斑马线退让',
|
||||
'cluster-stop-line-offset': '停止线偏移',
|
||||
'junction-cutback': '进口收口距离',
|
||||
'junction-corner-radius': '角部圆角',
|
||||
'junction-crosswalk-inset': '斑马线退让',
|
||||
|
||||
@@ -113,8 +113,10 @@ export function constraintValueFor(
|
||||
case 'junction-corner-radius':
|
||||
return { radiusMeters: Math.max(0, scalar) };
|
||||
case 'junction-crosswalk-inset':
|
||||
case 'cluster-crossing-inset':
|
||||
return { insetMeters: Math.max(0, scalar) };
|
||||
case 'junction-stop-line-offset':
|
||||
case 'cluster-stop-line-offset':
|
||||
return { offsetMeters: Math.max(0, scalar) };
|
||||
case 'junction-crosswalk-size':
|
||||
// Size is a pair — depth and stripe count — so no single dragged scalar
|
||||
|
||||
@@ -23,7 +23,12 @@ export const ROAD_KINDS = ['road-edge-offset', 'road-sidewalk-width', 'road-lane
|
||||
* offers this edit. Placement of the zebra and the stop line is therefore the main
|
||||
* map's, and JunctionTools keeps the three shape kinds below.
|
||||
*/
|
||||
export const CONTROL_KINDS = ['junction-crosswalk-inset', 'junction-stop-line-offset'] as const;
|
||||
export const CONTROL_KINDS = [
|
||||
'junction-crosswalk-inset',
|
||||
'junction-stop-line-offset',
|
||||
'cluster-crossing-inset',
|
||||
'cluster-stop-line-offset',
|
||||
] as const;
|
||||
export const JUNCTION_KINDS = [
|
||||
'junction-approach-width',
|
||||
'cluster-carriageway-width',
|
||||
@@ -61,6 +66,7 @@ export type SemanticAnchor =
|
||||
// in projection.ts is the only place that moves it across.
|
||||
boundaryIndex?: number;
|
||||
}
|
||||
| { type: 'cluster-crossing'; clusterId: string; crossingKey: string; carriagewayKeys: string[] }
|
||||
| { type: 'cluster-corner'; clusterId: string; cornerKey: string; carriagewayKeys: string[] }
|
||||
| { type: 'junction-approach'; nodeId: string; segmentId: string; side?: Side }
|
||||
| {
|
||||
|
||||
@@ -41,7 +41,11 @@ interface Props {
|
||||
roads?: Road[];
|
||||
junctionCoordinate?: Coordinate;
|
||||
selectedFacility?: ElementSelection | null;
|
||||
onSelectFacility?: (facility: { id: string; kind: 'crosswalk' | 'stop-line' | 'signal' }) => void;
|
||||
onSelectFacility?: (facility: {
|
||||
id: string;
|
||||
kind: 'crosswalk' | 'stop-line' | 'signal';
|
||||
crossingKey?: string;
|
||||
}) => void;
|
||||
signalUids?: readonly string[];
|
||||
selectedSignalUid?: string | null;
|
||||
onSignalStatus?: (message: string) => void;
|
||||
@@ -420,7 +424,8 @@ export function JunctionWorkspace({
|
||||
(facility.kind === 'signal' && selectedSignalUid === facility.id.slice('signal:'.length)) ||
|
||||
(selectedFacility &&
|
||||
selectedFacility.kind === facility.kind &&
|
||||
String(selectedFacility.crossingNodeId) === facility.id.split(':').slice(1).join(':'))
|
||||
String(selectedFacility.crossingNodeId) ===
|
||||
(facility.crossingKey ?? facility.id.split(':').slice(1).join(':')))
|
||||
? 'is-selected'
|
||||
: undefined
|
||||
}
|
||||
@@ -428,7 +433,8 @@ export function JunctionWorkspace({
|
||||
(facility.kind === 'signal' && selectedSignalUid === facility.id.slice('signal:'.length)) ||
|
||||
(selectedFacility &&
|
||||
selectedFacility.kind === facility.kind &&
|
||||
String(selectedFacility.crossingNodeId) === facility.id.split(':').slice(1).join(':'))
|
||||
String(selectedFacility.crossingNodeId) ===
|
||||
(facility.crossingKey ?? facility.id.split(':').slice(1).join(':')))
|
||||
? 'true'
|
||||
: undefined
|
||||
}
|
||||
@@ -477,12 +483,18 @@ export function JunctionWorkspace({
|
||||
selectedFacility && selectedFacility.kind !== 'lane-maneuver'
|
||||
? handles.find(
|
||||
(handle) =>
|
||||
handle.anchor.type === 'junction-crossing' &&
|
||||
String(handle.anchor.crossingId) === String(selectedFacility.crossingNodeId) &&
|
||||
handle.kind ===
|
||||
(selectedFacility.kind === 'crosswalk'
|
||||
? 'junction-crosswalk-inset'
|
||||
: 'junction-stop-line-offset'),
|
||||
(handle.anchor.type === 'junction-crossing' &&
|
||||
String(handle.anchor.crossingId) === String(selectedFacility.crossingNodeId) &&
|
||||
handle.kind ===
|
||||
(selectedFacility.kind === 'crosswalk'
|
||||
? 'junction-crosswalk-inset'
|
||||
: 'junction-stop-line-offset')) ||
|
||||
(handle.anchor.type === 'cluster-crossing' &&
|
||||
String(handle.anchor.crossingKey) === String(selectedFacility.crossingNodeId) &&
|
||||
handle.kind ===
|
||||
(selectedFacility.kind === 'crosswalk'
|
||||
? 'cluster-crossing-inset'
|
||||
: 'cluster-stop-line-offset')),
|
||||
)?.handleId
|
||||
: undefined
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ export interface JunctionFacility {
|
||||
id: string;
|
||||
kind: 'crosswalk' | 'stop-line' | 'signal';
|
||||
label: string;
|
||||
crossingKey?: string;
|
||||
}
|
||||
|
||||
function text(value: unknown): string | null {
|
||||
@@ -33,21 +34,27 @@ export function junctionFacilities(
|
||||
const nodes = new Set(nodeIds.map(String));
|
||||
const result = new Map<string, JunctionFacility>();
|
||||
for (const feature of state.layers.crosswalks?.features ?? []) {
|
||||
const crossingKey = text(feature.properties?.crossing_key) ?? text(feature.properties?.object_key);
|
||||
const crossing = text(feature.properties?.crossing_node_id);
|
||||
if (!crossing || !nodes.has(crossing)) continue;
|
||||
result.set(`crosswalk:${crossing}`, {
|
||||
id: `crosswalk:${crossing}`,
|
||||
if ((!crossing || !nodes.has(crossing)) && !crossingKey) continue;
|
||||
const id = `crosswalk:${crossingKey ?? crossing}`;
|
||||
result.set(id, {
|
||||
id,
|
||||
kind: 'crosswalk',
|
||||
label: `斑马线 · ${roadLabel(feature, roads)}`,
|
||||
crossingKey: crossingKey ?? undefined,
|
||||
});
|
||||
}
|
||||
for (const feature of state.layers.vehicleStopLines?.features ?? []) {
|
||||
const crossingKey = text(feature.properties?.crossing_key);
|
||||
const crossing = text(feature.properties?.crossing_node_id);
|
||||
if (!crossing || !nodes.has(crossing)) continue;
|
||||
result.set(`stop-line:${crossing}`, {
|
||||
id: `stop-line:${crossing}`,
|
||||
if ((!crossing || !nodes.has(crossing)) && !crossingKey) continue;
|
||||
const id = `stop-line:${crossingKey ?? crossing}`;
|
||||
result.set(id, {
|
||||
id,
|
||||
kind: 'stop-line',
|
||||
label: `停止线 · ${roadLabel(feature, roads)}`,
|
||||
crossingKey: crossingKey ?? undefined,
|
||||
});
|
||||
}
|
||||
for (const feature of state.trafficSignals.assemblies.features) {
|
||||
|
||||
Reference in new issue
Block a user