feat: add direct edit handles behind directEdit flag
Steps 1-3 of the main map road interval editor. EditSession keeps the command stack, undo/redo and previewSeq arbitration as pure logic with no OpenLayers reference, so all of it is unit-tested in node. Pointer displacement converts to meters through EPSG:4326 and spherical distance: treating a 3857 delta as meters desyncs the geometry from the cursor by 1/cos(latitude). Handle drags project onto the axis the manifest declares and clamp to its range, so the client never writes a coordinate into a road polygon. All of it sits behind a directEdit flag that defaults to off. With the flag off the workbench requests no manifest, creates no extra source and registers no interaction, so behaviour matches main. The ol-ext probe passed its three gates but is not adopted for road handles. Transform translates by the raw pointer delta, so a handle detaches from its clamped constraint value: a drag reading -24.1 m produced a draft of -5.4 m. Production needs the handle position derived from the constraint instead, which means owning the position update, so native OL PointerInteraction will carry the drag. ol-ext stays out of package.json; the probe is kept as a manual harness. Reserve handles are unreachable with the current solver, recorded in research/ rather than worked around. Also names the dead backend when an API response is empty, instead of surfacing "Unexpected end of JSON input" from response.json(). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
e25c564bb9
commit
bc4b9a9717
25 files changed
+2463
-22
No files matched your search
@@ -5,6 +5,9 @@ import Select from 'ol/interaction/Select';
|
||||
import { click } from 'ol/events/condition';
|
||||
import type { Road, WorkbenchState } from '../types/state';
|
||||
import { createLayers, updateLayers, updateSelectedRoad, type LayerName } from '../map/layers';
|
||||
import { directEditEnabled } from '../edit/flag';
|
||||
import { EditHandleLayer } from '../edit/handle-layer';
|
||||
import type { EditHandle } from '../edit/types';
|
||||
|
||||
interface Props {
|
||||
state: WorkbenchState;
|
||||
@@ -13,11 +16,14 @@ interface Props {
|
||||
scene: boolean;
|
||||
onSelectRoad: (road: Road) => void;
|
||||
onFeature: (properties: Record<string, unknown>) => void;
|
||||
/** Already filtered to the selected road. Ignored unless `directEdit` is on. */
|
||||
handles?: EditHandle[];
|
||||
}
|
||||
export function MapCanvas({ state, selected, visible, scene, onSelectRoad, onFeature }: Props) {
|
||||
export function MapCanvas({ state, selected, visible, scene, onSelectRoad, onFeature, handles }: Props) {
|
||||
const target = useRef<HTMLDivElement>(null);
|
||||
const mapRef = useRef<Map | null>(null);
|
||||
const layersRef = useRef<ReturnType<typeof createLayers> | null>(null);
|
||||
const handleLayerRef = useRef<EditHandleLayer | null>(null);
|
||||
const selectedRef = useRef<Road | null>(selected);
|
||||
const stateRef = useRef(state);
|
||||
const sceneRef = useRef(scene);
|
||||
@@ -31,15 +37,21 @@ export function MapCanvas({ state, selected, visible, scene, onSelectRoad, onFea
|
||||
() => 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 handleLayer = directEditEnabled ? new EditHandleLayer() : null;
|
||||
handleLayerRef.current = handleLayer;
|
||||
const map = new Map({
|
||||
target: target.current,
|
||||
layers: Object.values(layers),
|
||||
layers: handleLayer ? [...Object.values(layers), handleLayer.layer] : Object.values(layers),
|
||||
view: new View({ center: [0, 0], zoom: 2 }),
|
||||
});
|
||||
mapRef.current = map;
|
||||
const select = new Select({
|
||||
condition: click,
|
||||
layers: (layer) => layer !== layers.selectedRoad,
|
||||
// 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,
|
||||
hitTolerance: 12,
|
||||
style: null,
|
||||
});
|
||||
@@ -79,6 +91,11 @@ export function MapCanvas({ state, selected, visible, scene, onSelectRoad, onFea
|
||||
updateSelectedRoad(layers, selected);
|
||||
layers.osm.changed();
|
||||
}, [selected]);
|
||||
useEffect(() => {
|
||||
// Null when the flag is off, so this whole path is inert on main.
|
||||
// Only the editHandles source is replaced; baseline layers are never touched.
|
||||
handleLayerRef.current?.render(handles ?? []);
|
||||
}, [handles]);
|
||||
useEffect(() => {
|
||||
const layers = layersRef.current;
|
||||
if (!layers) return;
|
||||
|
||||
Reference in new issue
Block a user