feat(junction): edit complex crossing facilities

This commit is contained in:
que01 committed 2026-09-08 15:05:00 +08:00
1 parent bb5dc01c07
commit 49a44fdf73
16 files changed
+307 -39

No files matched your search

+13 -3
View File
@@ -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,
+100
View File
@@ -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,
+14 -2
View File
@@ -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)
+1
View File
@@ -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);