feat(junction): establish stable complex junction structure

This commit is contained in:
que01 committed 2026-09-08 11:25:57 +08:00
1 parent bd8b55e58b
commit 0a5a229ce3
22 files changed
+1386 -125

No files matched your search

+35 -15
View File
@@ -57,6 +57,12 @@ import type { JunctionRef } from './junction/hotspots';
import { candidateForJunction, junctionDescriptors, hotspotAt } from './junction/hotspots';
import { JunctionWorkspace } from './junction/JunctionWorkspace';
import { localJunctionPreview, localJunctionState } from './junction/local-state';
import {
junctionEditSelection,
junctionObjectFeatures,
junctionObjectKeyForFeature,
structureForJunction,
} from './junction/structure';
import {
applyJunctionDraft,
cancelJunctionSession,
@@ -164,7 +170,7 @@ function App() {
editMode,
state,
selectedSegmentId: selected?.segmentId,
selectedJunctionId: junctionRoute?.type === 'node' ? junctionRoute.id : undefined,
selectedJunction: junctionRoute,
setStatus,
});
const {
@@ -206,6 +212,17 @@ function App() {
() => (state && junctionDescriptor && junctionRoute ? localJunctionState(state, junctionDescriptor) : state),
[junctionDescriptor, junctionRoute, state],
);
const junctionStructure = useMemo(
() => (junctionRoute ? structureForJunction(state, junctionRoute) : null),
[junctionRoute, state],
);
const junctionSelectionFeatures = useMemo(
() => junctionObjectFeatures(state, junctionStructure, selectedObjectKey),
[state, junctionStructure, selectedObjectKey],
);
useEffect(() => {
setSelectedObjectKey(null);
}, [junctionRoute]);
const junctionMapPreview = useMemo(
() =>
state && junctionDescriptor && junctionRoute
@@ -417,12 +434,11 @@ function App() {
// fall back to the approach segment here: doing so makes an accepted preview
// replace the junction manifest with a road-scoped one, which drops the
// width/cutback/radius rows immediately after the first edit.
selectionRef.current =
junctionRoute?.type === 'node'
? { junction: junctionRoute.id }
: selected?.segmentId
? { segment: selected.segmentId }
: undefined;
selectionRef.current = junctionRoute
? junctionEditSelection(junctionRoute)
: selected?.segmentId
? { segment: selected.segmentId }
: undefined;
/**
* One gesture, one operation id. Minted on the first draft of a drag and cleared
* on release: reusing an id across gestures would put two operations with the
@@ -902,13 +918,15 @@ function App() {
};
const handleFeature = (properties: Record<string, unknown>) => {
setMarking(properties);
const objectKey = properties.signal_uid
? `signal:${String(properties.signal_uid)}`
: properties.crossing_node_id
? `${properties.provenance === 'stop-line' ? 'stop-line' : 'crossing'}:${String(properties.crossing_node_id)}`
: properties.road_id
? `road-arm:${String(properties.road_id)}`
: null;
const objectKey = junctionStructure
? junctionObjectKeyForFeature(junctionStructure, properties)
: properties.signal_uid
? `signal:${String(properties.signal_uid)}`
: properties.crossing_node_id
? `${properties.provenance === 'stop-line' ? 'stop-line' : 'crossing'}:${String(properties.crossing_node_id)}`
: properties.road_id
? `road-arm:${String(properties.road_id)}`
: null;
setSelectedObjectKey(objectKey);
// A crosswalk is six features but one editable thing; a stop line is one.
// `provenance` picks which, and therefore which layer holds its siblings —
@@ -1065,6 +1083,7 @@ function App() {
scene={scene}
junctionHotspots={junctionHotspots}
junctionNodeMarkers={junctionNodeMarkers}
junctionSelectionFeatures={junctionSelectionFeatures}
referenceOpacity={referenceOpacity}
onJunctionHotspot={(ref: JunctionRef, _coordinate, descriptor) => {
openJunction(ref);
@@ -1080,6 +1099,7 @@ function App() {
onBackground={() => {
setElement(null);
setMarking(null);
setSelectedObjectKey(null);
}}
onSignalDrag={moveSignal}
onSignalDragEnd={finishSignalMove}
@@ -1178,7 +1198,7 @@ function App() {
descriptor={junctionDescriptor}
session={junctionSession}
dirty={Boolean(junctionSession.dirty || signalDirty)}
state={state}
state={junctionMapState}
diagnostics={junctionDiagnostics}
selectedObjectKey={selectedObjectKey}
onSelectObject={(key) => setSelectedObjectKey(key)}