feat(workbench): add junction hotspot entry points
This commit is contained in:
1 parent
bd7b049930
commit
7d9b0f46d4
6 files changed
+288
-6
No files matched your search
@@ -15,7 +15,8 @@ import Stroke from 'ol/style/Stroke';
|
||||
import Style from 'ol/style/Style';
|
||||
import { click } from 'ol/events/condition';
|
||||
import type { GeoJson, Road, WorkbenchState } from '../types/state';
|
||||
import { createLayers, updateLayers, updateSelectedRoad, type LayerName } from '../map/layers';
|
||||
import { createLayers, updateJunctionHotspots, updateLayers, updateSelectedRoad, type LayerName } from '../map/layers';
|
||||
import { junctionDescriptors, type JunctionDescriptor, type JunctionRef } from '../junction/hotspots';
|
||||
import { createHandleDragInteraction } from '../edit/drag-interaction';
|
||||
import { EditGhostLayer } from '../edit/ghost-layer';
|
||||
import { EditHandleLayer, type ElementOutline } from '../edit/handle-layer';
|
||||
@@ -70,6 +71,8 @@ interface Props {
|
||||
/** Last solve came back degraded; hold the ghost instead of clearing it. */
|
||||
ghostPending?: boolean;
|
||||
editMode?: boolean;
|
||||
junctionHotspots?: boolean;
|
||||
onJunctionHotspot?: (ref: JunctionRef, coordinate: Coordinate, descriptor: JunctionDescriptor) => void;
|
||||
}
|
||||
export function MapCanvas({
|
||||
state,
|
||||
@@ -102,6 +105,8 @@ export function MapCanvas({
|
||||
onRangeEnd,
|
||||
ghostPending,
|
||||
editMode = false,
|
||||
junctionHotspots = true,
|
||||
onJunctionHotspot,
|
||||
}: Props) {
|
||||
const target = useRef<HTMLDivElement>(null);
|
||||
const mapRef = useRef<Map | null>(null);
|
||||
@@ -155,8 +160,8 @@ export function MapCanvas({
|
||||
laneSelectionAxisAzimuth,
|
||||
ghostPending,
|
||||
};
|
||||
const selectRef = useRef({ onSelectRoad, onFeature, onBackground });
|
||||
selectRef.current = { onSelectRoad, onFeature, onBackground };
|
||||
const selectRef = useRef({ onSelectRoad, onFeature, onBackground, onJunctionHotspot });
|
||||
selectRef.current = { onSelectRoad, onFeature, onBackground, onJunctionHotspot };
|
||||
const selectedRef = useRef<Road | null>(selected);
|
||||
const stateRef = useRef(state);
|
||||
const sceneRef = useRef(scene);
|
||||
@@ -249,11 +254,22 @@ export function MapCanvas({
|
||||
layer !== layers.selectedRoad &&
|
||||
layer !== handleLayer?.layer &&
|
||||
layer !== laneSelectionLayer &&
|
||||
layer !== signalTransformLayer,
|
||||
layer !== signalTransformLayer &&
|
||||
layer !== layers.junctionHotspots,
|
||||
hitTolerance: 12,
|
||||
style: null,
|
||||
});
|
||||
map.addInteraction(select);
|
||||
map.on('singleclick', (event) => {
|
||||
const hit = map.forEachFeatureAtPixel(event.pixel, (feature) => feature, {
|
||||
layerFilter: (layer) => layer === layers.junctionHotspots,
|
||||
hitTolerance: 12,
|
||||
});
|
||||
const ref = hit?.get('junction_ref');
|
||||
const descriptor = hit?.get('junction_descriptor');
|
||||
if (!ref || !descriptor) return;
|
||||
selectRef.current.onJunctionHotspot?.(ref, toLonLat(event.coordinate as Coordinate), descriptor);
|
||||
});
|
||||
let signalUid: string | null = null;
|
||||
let rotatePivot: Coordinate | null = null;
|
||||
map.addInteraction(
|
||||
@@ -409,12 +425,13 @@ export function MapCanvas({
|
||||
const map = mapRef.current;
|
||||
if (!layers || !map) return;
|
||||
updateLayers(layers, state, selected);
|
||||
updateJunctionHotspots(layers, junctionDescriptors(state), junctionHotspots);
|
||||
const extent = layers.osm.getSource()!.getExtent();
|
||||
if (fittedAreaIdRef.current !== state.areaId && extent && Number.isFinite(extent[0])) {
|
||||
map.getView().fit(extent, { padding: [48, 48, 48, 48], maxZoom: 19 });
|
||||
fittedAreaIdRef.current = state.areaId;
|
||||
}
|
||||
}, [state]);
|
||||
}, [state, junctionHotspots]);
|
||||
useEffect(() => {
|
||||
const layers = layersRef.current;
|
||||
if (!layers) return;
|
||||
|
||||
Reference in new issue
Block a user