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

@@ -1,5 +1,6 @@
import { useEffect, useRef } from 'react';
import Feature from 'ol/Feature';
import GeoJSON from 'ol/format/GeoJSON';
import LineString from 'ol/geom/LineString';
import Map from 'ol/Map';
import Point from 'ol/geom/Point';
@@ -78,6 +79,8 @@ interface Props {
junctionHotspots?: boolean;
onJunctionHotspot?: (ref: JunctionRef, coordinate: Coordinate, descriptor: JunctionDescriptor) => void;
junctionNodeMarkers?: Array<{ coordinate: Coordinate; label: string; selected: boolean }>;
/** Read-only semantic object selection from the compiler's stable object keys. */
junctionSelectionFeatures?: GeoJson['features'];
referenceOpacity?: number;
}
export function MapCanvas({
@@ -115,6 +118,7 @@ export function MapCanvas({
junctionHotspots = true,
onJunctionHotspot,
junctionNodeMarkers = [],
junctionSelectionFeatures,
referenceOpacity = 0.55,
}: Props) {
const target = useRef<HTMLDivElement>(null);
@@ -129,6 +133,7 @@ export function MapCanvas({
const laneSelectionLayerRef = useRef<VectorLayer<VectorSource> | null>(null);
const signalTransformSourceRef = useRef<VectorSource | null>(null);
const signalTransformLayerRef = useRef<VectorLayer<VectorSource> | null>(null);
const junctionSelectionLayerRef = useRef<VectorLayer<VectorSource> | null>(null);
const junctionNodeMarkerSourceRef = useRef<VectorSource | null>(null);
const laneSelectionFeaturesRef = useRef<Feature[]>([]);
const laneSelectionAnchorRef = useRef<Coordinate | null>(null);
@@ -285,6 +290,7 @@ export function MapCanvas({
// road inspector, and dragging is owned by the edit interaction.
layers: (layer) =>
layer !== layers.selectedRoad &&
layer !== junctionSelectionLayerRef.current &&
layer !== handleLayer?.layer &&
layer !== laneSelectionLayer &&
layer !== signalTransformLayer &&
@@ -448,12 +454,40 @@ export function MapCanvas({
return () => {
select.un('select', listener);
junctionNodeMarkerSourceRef.current = null;
junctionSelectionLayerRef.current = null;
map.setTarget(undefined);
delete (target.current as HTMLDivElement & { __roadWorkbenchMap?: Map })?.__roadWorkbenchMap;
};
// Map construction must be once per mounted canvas; state changes update sources below.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
useEffect(() => {
const map = mapRef.current;
if (!map) return;
let layer = junctionSelectionLayerRef.current;
if (!layer && junctionSelectionFeatures?.length) {
layer = new VectorLayer({
source: new VectorSource(),
zIndex: 89,
style: new Style({
stroke: new Stroke({ color: '#0891b2', width: 3 }),
fill: new Fill({ color: 'rgba(8,145,178,0.16)' }),
image: new CircleStyle({ radius: 8, stroke: new Stroke({ color: '#0891b2', width: 3 }) }),
}),
});
junctionSelectionLayerRef.current = layer;
map.addLayer(layer);
}
const source = layer?.getSource();
if (!source) return;
source.clear();
source.addFeatures(
new GeoJSON().readFeatures(
{ type: 'FeatureCollection', features: junctionSelectionFeatures || [] },
{ dataProjection: 'EPSG:4326', featureProjection: 'EPSG:3857' },
),
);
}, [junctionSelectionFeatures]);
useEffect(() => {
const source = junctionNodeMarkerSourceRef.current;
if (!source) return;