feat: complete complex junction transition editing

This commit is contained in:
que01 committed 2026-09-09 16:57:47 +08:00
1 parent 801d8be980
commit 79f83412e6
18 files changed
+400 -59

No files matched your search

+15 -2
View File
@@ -269,6 +269,7 @@ function App() {
(handle) =>
(handle.kind === 'cluster-carriageway-width' ||
handle.kind === 'cluster-carriageway-cutback' ||
handle.kind === 'cluster-carriageway-transition-length' ||
handle.kind === 'cluster-corner-radius' ||
handle.kind === 'cluster-crossing-inset' ||
handle.kind === 'cluster-stop-line-offset') &&
@@ -1272,7 +1273,12 @@ function App() {
<JunctionWorkspace
descriptor={junctionDescriptor}
session={junctionSession}
dirty={Boolean(junctionSession.dirty || signalDirty)}
dirty={Boolean(junctionSession.dirty || session?.dirty || signalDirty)}
onUndo={undoEdit}
onRedo={redoEdit}
canUndo={Boolean(session?.canUndo || signalUndoRef.current.length)}
canRedo={Boolean(session?.canRedo || signalRedoRef.current.length)}
status={status}
state={junctionMapState}
diagnostics={junctionDiagnostics}
selectedObjectKey={selectedObjectKey}
@@ -1318,7 +1324,14 @@ function App() {
onDiscard={discardJunctionDraft}
onSave={() =>
void compile().then((ok) => {
if (ok) setJunctionSession((current) => (current ? saveJunctionSession(current, editRevision) : current));
// The API checks documentVersion. editRevision is only a render counter
// and advances during this save, so it cannot validate its completion.
if (ok)
setJunctionSession((current) =>
current?.ref.type === junctionDescriptor.ref.type && current.ref.id === junctionDescriptor.ref.id
? saveJunctionSession(current)
: current,
);
})
}
editMode={editMode}
@@ -382,7 +382,8 @@ function GroupedParameterList({
max: Math.min(...items.map((item) => item.value.max)),
},
};
const expandedGroup = Boolean(expanded[kind]);
const hasSharedRange = globalHandle.value.min <= globalHandle.value.max;
const expandedGroup = !hasSharedRange || Boolean(expanded[kind]);
const globalDraft =
callbacks.onDraftGroup ?? ((group: EditHandle[], value: number) => callbacks.onDraft?.(group[0], value));
const globalSettle =
@@ -392,25 +393,32 @@ function GroupedParameterList({
<div className="parameter-group__header">
<span>
<strong>{groupLabel(kind, representative)}</strong>
<small>统一设置 · {items.length} 项</small>
<small>
{hasSharedRange ? '统一设置' : '单独设置'} · {items.length} 项
</small>
</span>
<button
type="button"
className="parameter-group__toggle"
disabled={!hasSharedRange}
onClick={() => setExpanded((current) => ({ ...current, [kind]: !expandedGroup }))}
>
{expandedGroup ? '收起单独定制' : '展开单独定制'}
</button>
</div>
<ParameterRow
handle={globalHandle}
register={register}
{...callbacks}
highlightedHandleId={highlightedHandleId}
onDraft={(handle, value) => globalDraft(items, value)}
onSettle={(handle, value) => globalSettle(items, value)}
labelForHandle={() => '统一值'}
/>
{hasSharedRange ? (
<ParameterRow
handle={globalHandle}
register={register}
{...callbacks}
highlightedHandleId={highlightedHandleId}
onDraft={(handle, value) => globalDraft(items, value)}
onSettle={(handle, value) => globalSettle(items, value)}
labelForHandle={() => '统一值'}
/>
) : (
<p>各项允许范围没有交集,请分别调整。</p>
)}
{expandedGroup ? (
<ul className="parameter-group__details">
{items.map((handle) => (
+1
View File
@@ -115,6 +115,7 @@ const KIND_LABELS: Record<ConstraintKind, string> = {
'junction-approach-width': '进口宽度',
'cluster-carriageway-width': '车行道宽度',
'cluster-carriageway-cutback': '车行道收口距离',
'cluster-carriageway-transition-length': '车行道过渡长度',
'cluster-corner-radius': '角部圆角',
'cluster-crossing-inset': '斑马线退让',
'cluster-stop-line-offset': '停止线偏移',
@@ -328,3 +328,25 @@ describe('draft constraint', () => {
expect(operationFor(constraint).author).toBe('dingkang');
});
});
describe('complex transition length projection', () => {
it('maps dragging to a bounded length constraint', () => {
const handle = makeHandle(
'cluster-carriageway-transition-length',
{
type: 'cluster-carriageway',
clusterId: 'cluster-1',
carriagewayKey: 'entry-1',
sourceNodeIds: ['node-1'],
sourceRoadIds: ['road-1'],
},
12,
8,
20,
);
const scalar = projectHandleValue(handle, ...dragBy(handle.axisAzimuth, 2));
expect(scalar).toBeCloseTo(14, 3);
expect(constraintValueFor(handle, scalar)).toEqual({ transitionLengthMeters: scalar });
expect(projectHandleValue(handle, ...dragBy(handle.axisAzimuth, 100))).toBe(20);
});
});
+2
View File
@@ -106,6 +106,8 @@ export function constraintValueFor(
return { widthMeters: Math.max(0, scalar) };
case 'cluster-carriageway-cutback':
return { cutbackMeters: Math.max(0, scalar) };
case 'cluster-carriageway-transition-length':
return { transitionLengthMeters: Math.max(0, scalar) };
case 'cluster-corner-radius':
return { radiusMeters: Math.max(0, scalar) };
case 'junction-cutback':
+2
View File
@@ -33,6 +33,7 @@ export const JUNCTION_KINDS = [
'junction-approach-width',
'cluster-carriageway-width',
'cluster-carriageway-cutback',
'cluster-carriageway-transition-length',
'cluster-corner-radius',
'junction-cutback',
'junction-corner-radius',
@@ -126,6 +127,7 @@ export type ConstraintValue =
| { boundaryIndex: number; offsetMeters: number; transition?: Transition }
| { depthMeters: number; stripeCount: number }
| { cutbackMeters: number }
| { transitionLengthMeters: number }
| { radiusMeters: number }
| { insetMeters: number };
export interface LaneManeuverValue {
@@ -26,6 +26,11 @@ interface Props {
onApply: () => void;
onDiscard: () => void;
onSave: () => void;
onUndo?: () => void;
onRedo?: () => void;
canUndo?: boolean;
canRedo?: boolean;
status?: string;
editMode?: boolean;
onEnableEdit?: () => void;
onEnableComplex?: (nodeIds: string[]) => void;
@@ -61,6 +66,11 @@ export function JunctionWorkspace({
onApply,
onDiscard,
onSave,
onUndo,
onRedo,
canUndo = false,
canRedo = false,
status,
editMode = false,
onEnableEdit,
onEnableComplex,
@@ -202,8 +212,8 @@ export function JunctionWorkspace({
{complexEnabled
? editable
? editMode
? '可编辑外部车行道宽度'
: '当前按复杂路口渲染,开启编辑后可调整外部车行道宽度'
? '可编辑车行道与路口几何参数'
: '当前按复杂路口渲染,开启编辑后可调整几何参数'
: '当前按复杂路口渲染'
: descriptor.status === 'candidate'
? '当前按普通路口渲染,可切换为复杂路口'
@@ -519,7 +529,14 @@ export function JunctionWorkspace({
update={onUpdateSignal}
/>
) : null}
{status ? <p role="status">{status}</p> : null}
<div className="junction-workspace__actions">
<Button onClick={onUndo} disabled={!canUndo}>
撤销
</Button>
<Button onClick={onRedo} disabled={!canRedo}>
重做
</Button>
<Button onClick={onApply} disabled={!dirty}>
应用到工作区
</Button>
+3 -1
View File
@@ -60,7 +60,9 @@ export function junctionLabelForHandle(handle: EditHandle, roads: Road[], juncti
}
const clusterAnchor = handle.anchor;
if (
(handle.kind === 'cluster-carriageway-width' || handle.kind === 'cluster-carriageway-cutback') &&
(handle.kind === 'cluster-carriageway-width' ||
handle.kind === 'cluster-carriageway-cutback' ||
handle.kind === 'cluster-carriageway-transition-length') &&
clusterAnchor.type === 'cluster-carriageway'
) {
const road = roads.find((item) => clusterAnchor.sourceRoadIds.includes(item.id));