feat: add complex junction selection markers
This commit is contained in:
1 parent
57248f1aa4
commit
38ea779d9b
18 files changed
+685
-48
No files matched your search
@@ -13,6 +13,7 @@ import CircleStyle from 'ol/style/Circle';
|
||||
import Fill from 'ol/style/Fill';
|
||||
import Stroke from 'ol/style/Stroke';
|
||||
import Style from 'ol/style/Style';
|
||||
import Text from 'ol/style/Text';
|
||||
import { createEmpty, extend } from 'ol/extent';
|
||||
import { click } from 'ol/events/condition';
|
||||
import type { GeoJson, Road, WorkbenchState } from '../types/state';
|
||||
@@ -76,6 +77,7 @@ interface Props {
|
||||
focusJunctionId?: string | null;
|
||||
junctionHotspots?: boolean;
|
||||
onJunctionHotspot?: (ref: JunctionRef, coordinate: Coordinate, descriptor: JunctionDescriptor) => void;
|
||||
junctionNodeMarkers?: Array<{ coordinate: Coordinate; label: string; selected: boolean }>;
|
||||
}
|
||||
export function MapCanvas({
|
||||
state,
|
||||
@@ -111,6 +113,7 @@ export function MapCanvas({
|
||||
focusJunctionId = null,
|
||||
junctionHotspots = true,
|
||||
onJunctionHotspot,
|
||||
junctionNodeMarkers = [],
|
||||
}: Props) {
|
||||
const target = useRef<HTMLDivElement>(null);
|
||||
const mapRef = useRef<Map | null>(null);
|
||||
@@ -124,6 +127,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 junctionNodeMarkerSourceRef = useRef<VectorSource | null>(null);
|
||||
const laneSelectionFeaturesRef = useRef<Feature[]>([]);
|
||||
const laneSelectionAnchorRef = useRef<Coordinate | null>(null);
|
||||
const hiddenMarkingIdsRef = useRef<ReadonlySet<string>>(new Set());
|
||||
@@ -223,6 +227,28 @@ export function MapCanvas({
|
||||
});
|
||||
signalTransformSourceRef.current = signalTransformSource;
|
||||
signalTransformLayerRef.current = signalTransformLayer;
|
||||
const junctionNodeMarkerSource = new VectorSource();
|
||||
const junctionNodeMarkerLayer = new VectorLayer({
|
||||
source: junctionNodeMarkerSource,
|
||||
zIndex: 110,
|
||||
style: (feature) => {
|
||||
const selected = feature.get('junction_node_selected') === true;
|
||||
const color = selected ? '#0e7490' : '#64748b';
|
||||
return new Style({
|
||||
image: new CircleStyle({
|
||||
radius: 12,
|
||||
fill: new Fill({ color }),
|
||||
stroke: new Stroke({ color: '#fff', width: 2 }),
|
||||
}),
|
||||
text: new Text({
|
||||
text: String(feature.get('junction_node_label') || ''),
|
||||
fill: new Fill({ color: '#fff' }),
|
||||
font: '700 12px sans-serif',
|
||||
}),
|
||||
});
|
||||
},
|
||||
});
|
||||
junctionNodeMarkerSourceRef.current = junctionNodeMarkerSource;
|
||||
// Direct-edit sources are always installed; visibility and hit testing follow
|
||||
// the in-page browser/edit switch.
|
||||
const handleLayer = new EditHandleLayer();
|
||||
@@ -241,6 +267,7 @@ export function MapCanvas({
|
||||
...(previewLayer ? previewLayer.all() : []),
|
||||
laneSelectionLayer,
|
||||
signalTransformLayer,
|
||||
junctionNodeMarkerLayer,
|
||||
...(handleLayer ? [handleLayer.layer] : []),
|
||||
...(ghost ? [ghost.layer] : []),
|
||||
],
|
||||
@@ -418,12 +445,41 @@ export function MapCanvas({
|
||||
select.on('select', listener);
|
||||
return () => {
|
||||
select.un('select', listener);
|
||||
junctionNodeMarkerSourceRef.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 source = junctionNodeMarkerSourceRef.current;
|
||||
if (!source) return;
|
||||
source.clear();
|
||||
source.addFeatures(
|
||||
junctionNodeMarkers.map((marker) => {
|
||||
const feature = new Feature({ geometry: new Point(fromLonLat(marker.coordinate)) });
|
||||
feature.set('junction_node_label', marker.label);
|
||||
feature.set('junction_node_selected', marker.selected);
|
||||
return feature;
|
||||
}),
|
||||
);
|
||||
const map = mapRef.current;
|
||||
if (map && junctionNodeMarkers.length) {
|
||||
const extent = createEmpty();
|
||||
junctionNodeMarkers.forEach((marker) => {
|
||||
const point = fromLonLat(marker.coordinate);
|
||||
extend(extent, [point[0], point[1], point[0], point[1]]);
|
||||
});
|
||||
if (Number.isFinite(extent[0])) {
|
||||
map.getView().fit(extent, {
|
||||
padding: [96, 520, 96, 96],
|
||||
maxZoom: 20,
|
||||
duration: 180,
|
||||
});
|
||||
}
|
||||
}
|
||||
}, [junctionNodeMarkers]);
|
||||
useEffect(() => {
|
||||
const layers = layersRef.current;
|
||||
const map = mapRef.current;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useState, type ReactNode } from 'react';
|
||||
import { Candidates, LaneManeuverEditor, MarkingEditor, SignalEditor } from './ElementEditors';
|
||||
import { LaneManeuverEditor, MarkingEditor, SignalEditor } from './ElementEditors';
|
||||
import { InspectorSection } from './InspectorSection';
|
||||
import type { EditSession } from '../edit/session';
|
||||
import type { ElementSelection } from '../edit/element';
|
||||
@@ -19,7 +19,6 @@ export function WorkbenchInspector({
|
||||
session,
|
||||
onLaneManeuverChange,
|
||||
updateSignal,
|
||||
onAcceptCandidate,
|
||||
children,
|
||||
}: {
|
||||
road: Road | null;
|
||||
@@ -32,7 +31,6 @@ export function WorkbenchInspector({
|
||||
session: EditSession | null;
|
||||
onLaneManeuverChange: (maneuver: string, placementDistanceMeters: number) => void;
|
||||
updateSignal: (features: GeoFeature[]) => Promise<void>;
|
||||
onAcceptCandidate: (index: number) => void;
|
||||
children?: ReactNode;
|
||||
}) {
|
||||
const [width, setWidth] = useState(0);
|
||||
@@ -258,7 +256,6 @@ export function WorkbenchInspector({
|
||||
})}
|
||||
</InspectorSection>
|
||||
<InspectorSection title="高级" summary="候选与来源" open={open === 'advanced'} onToggle={section('advanced')}>
|
||||
<Candidates state={state} onAccept={onAcceptCandidate} />
|
||||
<details>
|
||||
<summary>技术详情与来源</summary>
|
||||
<pre>
|
||||
|
||||
Reference in new issue
Block a user