feat(workbench): expose junction geometry parameters

This commit is contained in:
que01 committed 2026-09-03 12:02:16 +08:00
1 parent f6f51fe90b
commit 60e28f6b7a
2 files changed
+80 -13

No files matched your search

+39 -1
View File
@@ -192,6 +192,21 @@ function App() {
const segmentOf = (roadId: string) => state.compiled.model.roads.find((road) => road.id === roadId)?.segmentId;
return handlesForSegment(manifest, selected?.segmentId ?? null, segmentOf);
}, [editMode, manifest, selected, state]);
// JunctionTools owns the three shape constraints for an ordinary node. Keep
// the same manifest objects and callbacks as the main parameter panel so
// number entry and dragging share one preview/undo protocol.
const junctionHandles = useMemo(() => {
if (!editMode || !junctionDescriptor || junctionDescriptor.ref.type !== 'node' || !manifest) return [];
const nodeIds = new Set(junctionDescriptor.nodeIds.map(String));
return manifest.handles.filter(
(handle) =>
(handle.kind === 'junction-approach-width' ||
handle.kind === 'junction-cutback' ||
handle.kind === 'junction-corner-radius') &&
'nodeId' in handle.anchor &&
nodeIds.has(String(handle.anchor.nodeId)),
);
}, [editMode, junctionDescriptor, manifest]);
// 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);
@@ -700,6 +715,14 @@ function App() {
(filter === 'candidates' ? Boolean(item.manualCandidates?.length) : !item.manualCandidates?.length)),
);
const openJunction = (ref: JunctionRef) => {
// Seed direct-edit selection with the first approach so the existing
// manifest request loads junction shape handles before the workspace opens.
const descriptor = state ? hotspotAt(junctionDescriptors(state), ref) : null;
const approach = descriptor?.approachRoadIds[0];
if (approach) {
const road = state?.compiled.model.roads.find((item) => item.id === approach);
if (road) setSelected(road);
}
window.history.pushState({}, '', `/junction/${ref.type}/${encodeURIComponent(ref.id)}`);
setJunctionRoute(ref);
};
@@ -855,8 +878,12 @@ function App() {
visible={layers}
scene={scene}
junctionHotspots={junctionHotspots}
onJunctionHotspot={(ref: JunctionRef) => {
onJunctionHotspot={(ref: JunctionRef, _coordinate, descriptor) => {
openJunction(ref);
const approachRoad = descriptor.approachRoadIds
.map((roadId) => state.compiled.model.roads.find((road) => road.id === roadId))
.find((road): road is Road => Boolean(road));
if (approachRoad) setSelected(approachRoad);
setStatus(ref.type === 'node' ? `已定位路口节点 ${ref.id}(可编辑)` : `已定位路口 ${ref.id}(只读)`);
}}
onSelectRoad={setSelected}
@@ -983,6 +1010,17 @@ function App() {
setStatus((error as Error).message);
}
}}
handles={junctionHandles}
onDraft={draftValue}
onSettle={(handle, value) => {
settleValue(handle, value);
setJunctionSession((current) => (current ? { ...current, status: 'draft', dirty: true } : current));
}}
onAbandon={abandonGesture}
onReset={(handle) => {
resetHandle(handle);
setJunctionSession((current) => (current ? { ...current, status: 'draft', dirty: true } : current));
}}
/>
) : null}
</>
@@ -2,6 +2,8 @@ import { useMemo } from 'react';
import type { JunctionDescriptor } from './hotspots';
import { canEditJunction, type JunctionSession } from './workspace';
import { Button } from '../ui/button';
import { ParameterPanel } from '../components/ParameterPanel';
import type { EditHandle } from '../edit/types';
interface Props {
descriptor: JunctionDescriptor;
@@ -10,9 +12,26 @@ interface Props {
onApply: () => void;
onDiscard: () => void;
onSave: () => void;
handles?: EditHandle[];
onDraft?: (handle: EditHandle, value: number) => void;
onSettle?: (handle: EditHandle, value: number) => void;
onAbandon?: () => void;
onReset?: (handle: EditHandle) => void;
}
export function JunctionWorkspace({ descriptor, session, onClose, onApply, onDiscard, onSave }: Props) {
export function JunctionWorkspace({
descriptor,
session,
onClose,
onApply,
onDiscard,
onSave,
handles = [],
onDraft,
onSettle,
onAbandon,
onReset,
}: Props) {
const editable = useMemo(() => canEditJunction(descriptor), [descriptor]);
return (
<section className="junction-workspace" aria-label="路口编辑工作区">
@@ -41,17 +60,27 @@ export function JunctionWorkspace({ descriptor, session, onClose, onApply, onDis
</dd>
</dl>
{editable ? (
<div className="junction-workspace__actions">
<Button onClick={onApply} disabled={!session.dirty}>
应用到工作区
</Button>
<Button onClick={onSave} disabled={session.dirty}>
保存
</Button>
<Button onClick={onDiscard} disabled={!session.dirty}>
放弃草稿
</Button>
</div>
<>
<ParameterPanel
handles={handles}
hasSelection
onDraft={onDraft ?? (() => undefined)}
onSettle={onSettle ?? (() => undefined)}
onAbandon={onAbandon ?? (() => undefined)}
onReset={onReset ?? (() => undefined)}
/>
<div className="junction-workspace__actions">
<Button onClick={onApply} disabled={!session.dirty}>
应用到工作区
</Button>
<Button onClick={onSave} disabled={session.dirty}>
保存
</Button>
<Button onClick={onDiscard} disabled={!session.dirty}>
放弃草稿
</Button>
</div>
</>
) : null}
</div>
</section>