feat: edit lane turn arrows in workbench

This commit is contained in:
que01 committed 2026-09-01 09:17:24 +08:00
1 parent 8b84166e6f
commit e48eb15827
9 files changed
+330 -28

No files matched your search

+67 -6
View File
@@ -7,6 +7,7 @@ import {
elementSelectionFor,
groupMembers,
handleForElement,
isControlElement,
orientedBoundsOf,
specFor,
specOfKind,
@@ -187,7 +188,7 @@ function App() {
* dot — no second drag path, no second constraint.
*/
const elementOutline = useMemo<ElementOutline | null>(() => {
if (!directEditEnabled || !element || !state) return null;
if (!directEditEnabled || !element || !isControlElement(element) || !state) return null;
const handle = handleForElement(element, state.compiled.model.roads, editHandles);
if (!handle?.editable) return null;
// Read the preview when there is one. `state.layers` is the last *compiled*
@@ -504,10 +505,15 @@ function App() {
// zebra with the stop line protecting it. Clicking anything else drops the
// selection, because a box left around what the user navigated away from
// reads as a stuck UI.
if (directEditEnabled) {
const spec = specFor(properties);
setElement(spec ? elementSelectionFor(properties, state.layers[spec.layer]?.features ?? []) : null);
}
const spec = specFor(properties);
const nextElement = elementSelectionFor(
properties,
spec ? (state.layers[spec.layer]?.features ?? []) : (state.layers.laneCenterlines?.features ?? []),
);
// lane-maneuver is a regular v1 override, not a direct-edit constraint, so
// it remains available in the shipped workbench. The flag still contains
// control-marking outlines and all v2 handles behind the experimental path.
setElement(directEditEnabled || nextElement?.kind === 'lane-maneuver' ? nextElement : null);
const uid = properties.signal_uid;
if (typeof uid === 'string') setStatus(`已选中原生红绿灯 ${uid}`);
else if (properties.effective_style) setStatus('已选中标线,可在右侧暂存样式');
@@ -525,7 +531,9 @@ function App() {
<span className={editDiagnostics.some((item) => item.severity === 'error') ? 'dirty' : ''}>
{editDiagnostics.find((item) => item.severity === 'error')?.message ||
(element
? `已选中${specOfKind(element.kind).label} ${element.crossingNodeId}(${element.featureIds.length} 条)`
? element.kind === 'lane-maneuver'
? `已选中第 ${laneIndex(element.laneId)} 车道(${element.featureIds.length} 个箭头 part)`
: `已选中${specOfKind(element.kind).label} ${element.crossingNodeId}(${element.featureIds.length} 条)`
: editHandles.length
? `手柄 ${editHandles.length} 个`
: selected
@@ -658,6 +666,7 @@ function App() {
state={state}
staged={staged}
marking={marking}
element={element}
stage={stage}
status={setStatus}
setState={setState}
@@ -706,6 +715,7 @@ function Inspector({
state,
staged,
marking,
element,
stage,
status,
setState,
@@ -714,6 +724,7 @@ function Inspector({
state: WorkbenchState;
staged: Override[];
marking: Record<string, unknown> | null;
element: ElementSelection | null;
stage: (item: Override) => void;
status: (value: string) => void;
setState: (next: WorkbenchState) => void;
@@ -892,6 +903,7 @@ function Inspector({
) : null;
})}
<MarkingEditor marking={marking} stage={stage} />
<LaneManeuverEditor element={element} overrides={[...state.overrides.overrides, ...staged]} stage={stage} />
<SignalEditor state={state} signal={signal} status={status} update={updateSignal} />
<Candidates state={state} setState={setState} status={status} />
<details>
@@ -907,6 +919,55 @@ function Inspector({
</>
);
}
const MANEUVER_OPTIONS: Array<[string, string]> = [
['', '无箭头'],
['through', '直行'],
['left', '左转'],
['right', '右转'],
['through;left', '直行或左转'],
['through;right', '直行或右转'],
['through;left;right', '直行、左转或右转'],
];
function LaneManeuverEditor({
element,
overrides,
stage,
}: {
element: ElementSelection | null;
overrides: Override[];
stage: (item: Override) => void;
}) {
if (!element || element.kind !== 'lane-maneuver') return null;
// Old override files may use arbitrary ids. Reuse the latest matching entry
// so staging replaces it instead of leaving two conflicting maneuvers on one lane.
const override = [...overrides]
.reverse()
.find((item) => item.kind === 'lane-maneuver' && item.laneId === element.laneId);
const id = override?.id || `车道转向:${element.laneId}`;
const maneuver = typeof override?.maneuver === 'string' ? override.maneuver : element.maneuver;
return (
<form>
<hr />
<h2>车道转向箭头</h2>
<output>第 {laneIndex(element.laneId)} 车道</output>
<label>
转向
<select
value={maneuver}
onChange={(event) =>
stage({ id, kind: 'lane-maneuver', laneId: element.laneId, maneuver: event.target.value })
}
>
{MANEUVER_OPTIONS.map(([value, label]) => (
<option value={value} key={value}>
{label}
</option>
))}
</select>
</label>
</form>
);
}
function MarkingEditor({
marking,
stage,