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
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user