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
@@ -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