fix: outline selected turn arrows
This commit is contained in:
1 parent
2415733597
commit
3d135761e7
2 files changed
+49
-3
No files matched your search
@@ -15,6 +15,7 @@ import {
|
||||
} from './edit/element';
|
||||
import { directEditEnabled, intervalEditingSupported } from './edit/flag';
|
||||
import type { ElementOutline } from './edit/handle-layer';
|
||||
import type { Coordinate } from './edit/meters';
|
||||
import { rendersSame } from './edit/parameter';
|
||||
import { PreviewRequester, type PreviewDraft } from './edit/preview-request';
|
||||
import { anchorSnapshotFor, constraintValueFor, draftConstraint, operationFor } from './edit/projection';
|
||||
@@ -201,6 +202,16 @@ function App() {
|
||||
const bounds = orientedBoundsOf(groupMembers(drawn?.features ?? [], element.elementId));
|
||||
return bounds ? { handleId: handle.handleId, bounds } : null;
|
||||
}, [element, editHandles, state, preview]);
|
||||
const laneSelectionBounds = useMemo<Coordinate[] | null>(() => {
|
||||
if (!element || element.kind !== 'lane-maneuver' || !state || !element.featureIds.length) return null;
|
||||
const ids = new Set(element.featureIds);
|
||||
return orientedBoundsOf(
|
||||
state.layers.turnArrows?.features.filter((feature) => {
|
||||
const nativeId = feature.properties?.native_id;
|
||||
return typeof nativeId === 'string' && ids.has(nativeId);
|
||||
}) ?? [],
|
||||
);
|
||||
}, [element, state]);
|
||||
const sessionRef = useRef<EditSession | null>(null);
|
||||
if (directEditEnabled && !sessionRef.current) sessionRef.current = new EditSession();
|
||||
// Per-frame drag feedback reaches the panel through this rather than through
|
||||
@@ -623,6 +634,7 @@ function App() {
|
||||
handles={editHandles}
|
||||
ranges={editRanges}
|
||||
element={elementOutline}
|
||||
laneSelectionBounds={laneSelectionBounds}
|
||||
preview={preview}
|
||||
ghostPending={session?.degraded ?? false}
|
||||
onHandleDrag={(handle, value) => {
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
import Feature from 'ol/Feature';
|
||||
import Map from 'ol/Map';
|
||||
import Polygon from 'ol/geom/Polygon';
|
||||
import View from 'ol/View';
|
||||
import Select from 'ol/interaction/Select';
|
||||
import VectorLayer from 'ol/layer/Vector';
|
||||
import VectorSource from 'ol/source/Vector';
|
||||
import Fill from 'ol/style/Fill';
|
||||
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';
|
||||
@@ -10,6 +17,7 @@ import { createHandleDragInteraction } from '../edit/drag-interaction';
|
||||
import { EditGhostLayer } from '../edit/ghost-layer';
|
||||
import { EditHandleLayer, type ElementOutline } from '../edit/handle-layer';
|
||||
import { EditPreviewLayer } from '../edit/preview-layer';
|
||||
import { fromLonLat, type Coordinate } from '../edit/meters';
|
||||
import type { IntervalRangeHandle } from '../edit/selection';
|
||||
import type { EditHandle, PreviewLayerName, RoadIntervalAnchor } from '../edit/types';
|
||||
|
||||
@@ -28,6 +36,8 @@ interface Props {
|
||||
ranges?: IntervalRangeHandle[];
|
||||
/** The selected element's box, grabbable as the control that moves it. */
|
||||
element?: ElementOutline | null;
|
||||
/** A display-only outline for the selected v1 turn arrow. */
|
||||
laneSelectionBounds?: Coordinate[] | null;
|
||||
/** Authoritative preview geometry; null returns the map to the baseline. */
|
||||
preview?: Partial<Record<PreviewLayerName, GeoJson | null>> | null;
|
||||
/** Live value during a drag — the caller debounces the preview request. */
|
||||
@@ -52,6 +62,7 @@ export function MapCanvas({
|
||||
handles,
|
||||
ranges,
|
||||
element,
|
||||
laneSelectionBounds,
|
||||
preview,
|
||||
onHandleDrag,
|
||||
onHandleDragEnd,
|
||||
@@ -66,6 +77,7 @@ export function MapCanvas({
|
||||
const handleLayerRef = useRef<EditHandleLayer | null>(null);
|
||||
const ghostRef = useRef<EditGhostLayer | null>(null);
|
||||
const previewRef = useRef<EditPreviewLayer | null>(null);
|
||||
const laneSelectionSourceRef = useRef<VectorSource | null>(null);
|
||||
const visibleRef = useRef(visible);
|
||||
visibleRef.current = visible;
|
||||
// Callbacks live in refs so the map is built once and never rebuilt when a
|
||||
@@ -90,8 +102,18 @@ export function MapCanvas({
|
||||
() => sceneRef.current,
|
||||
);
|
||||
layersRef.current = layers;
|
||||
// With `directEdit` off nothing below exists: no extra source, no layer, no
|
||||
// interaction — the canvas is byte-for-byte the shipped behaviour.
|
||||
const laneSelectionSource = new VectorSource();
|
||||
const laneSelectionLayer = new VectorLayer({
|
||||
source: laneSelectionSource,
|
||||
zIndex: 90,
|
||||
style: new Style({
|
||||
stroke: new Stroke({ color: '#d49318', width: 2, lineDash: [6, 4] }),
|
||||
fill: new Fill({ color: 'rgba(212, 147, 24, 0.12)' }),
|
||||
}),
|
||||
});
|
||||
laneSelectionSourceRef.current = laneSelectionSource;
|
||||
// The v2 direct-edit sources below remain absent with the flag off. The lane
|
||||
// selection layer above is a regular v1 override affordance, not an edit source.
|
||||
const handleLayer = directEditEnabled ? new EditHandleLayer() : null;
|
||||
const ghost = directEditEnabled ? new EditGhostLayer() : null;
|
||||
const previewLayer = directEditEnabled
|
||||
@@ -108,6 +130,7 @@ export function MapCanvas({
|
||||
layers: [
|
||||
...Object.values(layers),
|
||||
...(previewLayer ? previewLayer.all() : []),
|
||||
laneSelectionLayer,
|
||||
...(handleLayer ? [handleLayer.layer] : []),
|
||||
...(ghost ? [ghost.layer] : []),
|
||||
],
|
||||
@@ -118,7 +141,7 @@ export function MapCanvas({
|
||||
condition: click,
|
||||
// Handles are not selectable features: clicking one must not re-target the
|
||||
// road inspector, and dragging is owned by the edit interaction.
|
||||
layers: (layer) => layer !== layers.selectedRoad && layer !== handleLayer?.layer,
|
||||
layers: (layer) => layer !== layers.selectedRoad && layer !== handleLayer?.layer && layer !== laneSelectionLayer,
|
||||
hitTolerance: 12,
|
||||
style: null,
|
||||
});
|
||||
@@ -184,6 +207,17 @@ export function MapCanvas({
|
||||
// Only the editHandles source is replaced; baseline layers are never touched.
|
||||
handleLayerRef.current?.render(handles ?? [], ranges ?? [], element ?? null);
|
||||
}, [handles, ranges, element]);
|
||||
useEffect(() => {
|
||||
const source = laneSelectionSourceRef.current;
|
||||
if (!source) return;
|
||||
source.clear();
|
||||
if (laneSelectionBounds && laneSelectionBounds.length >= 3)
|
||||
source.addFeature(
|
||||
new Feature({
|
||||
geometry: new Polygon([[...laneSelectionBounds, laneSelectionBounds[0]].map(fromLonLat)]),
|
||||
}),
|
||||
);
|
||||
}, [laneSelectionBounds]);
|
||||
useEffect(() => {
|
||||
// A non-degraded answer means the pending ghost has been superseded by real
|
||||
// geometry. Clearing an empty ghost is a no-op, so this is safe mid-drag.
|
||||
|
||||
Reference in new issue
Block a user