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
@@ -1,7 +1,10 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { Download, RefreshCw, Save, Upload } from 'lucide-react';
|
||||
import { api } from './lib/api';
|
||||
import { MapCanvas } from './components/MapCanvas';
|
||||
import { directEditEnabled } from './edit/flag';
|
||||
import { disabledReasonOf, handlesForSegment } from './edit/selection';
|
||||
import type { HandleManifest } from './edit/types';
|
||||
import { Button } from './ui/button';
|
||||
import type { GeoFeature, Override, Road, WorkbenchState } from './types/state';
|
||||
import type { LayerName } from './map/layers';
|
||||
@@ -89,6 +92,30 @@ function App() {
|
||||
})
|
||||
.catch((error: Error) => setStatus(error.message));
|
||||
}, []);
|
||||
const [manifest, setManifest] = useState<HandleManifest | null>(null);
|
||||
useEffect(() => {
|
||||
// Flag off: no manifest request at all, so the network trace matches main.
|
||||
if (!directEditEnabled) return;
|
||||
api
|
||||
.editState()
|
||||
.then((value) => {
|
||||
if ('handles' in value) setManifest(value.handles);
|
||||
})
|
||||
// A manifest failure must not take the workbench down with it; the map just
|
||||
// shows no handles.
|
||||
.catch((error: Error) => setStatus(`直接编辑手柄不可用:${error.message}`));
|
||||
}, []);
|
||||
const editHandles = useMemo(() => {
|
||||
if (!directEditEnabled || !state) return [];
|
||||
// Handle anchors carry a directional road id while reserves are keyed by
|
||||
// segment, so resolve through the compiled model rather than parsing ids.
|
||||
const segmentOf = (roadId: string) => state.compiled.model.roads.find((road) => road.id === roadId)?.segmentId;
|
||||
return handlesForSegment(manifest, selected?.segmentId ?? null, segmentOf);
|
||||
}, [manifest, selected, state]);
|
||||
// A greyed handle without a reason reads as a bug rather than an ownership
|
||||
// boundary, so the first blocked handle explains itself in the header.
|
||||
const blockedHandle = editHandles.find((handle) => !handle.editable);
|
||||
const blockedReason = blockedHandle ? disabledReasonOf(blockedHandle) : undefined;
|
||||
const stage = (change: Override) =>
|
||||
setStaged((current) => [...current.filter((item) => item.id !== change.id), change]);
|
||||
const save = async () => {
|
||||
@@ -152,6 +179,16 @@ function App() {
|
||||
<span className={staged.length ? 'dirty' : ''}>
|
||||
{staged.length ? `未保存修改 ${staged.length} 项` : '所有修改已保存'}
|
||||
</span>
|
||||
{directEditEnabled ? (
|
||||
<span>
|
||||
{editHandles.length
|
||||
? `手柄 ${editHandles.length} 个`
|
||||
: selected
|
||||
? '当前道路无可编辑手柄'
|
||||
: '选中道路以显示手柄'}
|
||||
{blockedReason ? `|${blockedReason}` : ''}
|
||||
</span>
|
||||
) : null}
|
||||
<label className="scene">
|
||||
<input type="checkbox" checked={scene} onChange={(event) => setScene(event.target.checked)} /> 场景效果
|
||||
</label>
|
||||
@@ -213,6 +250,7 @@ function App() {
|
||||
scene={scene}
|
||||
onSelectRoad={setSelected}
|
||||
onFeature={handleFeature}
|
||||
handles={editHandles}
|
||||
/>
|
||||
<Inspector
|
||||
road={selected}
|
||||
|
||||
Reference in new issue
Block a user