feat(junction): enable complex carriageway width editing

This commit is contained in:
que01 committed 2026-09-08 12:09:44 +08:00
1 parent 56647fcdaa
commit c4bcbe8ff9
22 files changed
+449 -52

No files matched your search

+12 -3
View File
@@ -262,7 +262,14 @@ function App() {
// 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 [];
if (!junctionDescriptor || !manifest) return [];
if (junctionDescriptor.ref.type === 'cluster')
return manifest.handles.filter(
(handle) =>
handle.kind === 'cluster-carriageway-width' &&
handle.anchor.type === 'cluster-carriageway' &&
handle.anchor.clusterId === junctionDescriptor.ref.id,
);
const nodeIds = new Set(junctionDescriptor.nodeIds.map(String));
return manifest.handles.filter(
(handle) =>
@@ -274,7 +281,7 @@ function App() {
'nodeId' in handle.anchor &&
nodeIds.has(String(handle.anchor.nodeId)),
);
}, [editMode, junctionDescriptor, manifest]);
}, [junctionDescriptor, manifest]);
const junctionFacilitySummary = useMemo(() => {
if (!junctionDescriptor || !state) return { crosswalks: 0, stopLines: 0, signals: 0 };
const nodeIds = new Set(junctionDescriptor.nodeIds.map(String));
@@ -478,11 +485,13 @@ function App() {
// compiled model before building the anchor snapshot. Without this branch
// control handles silently returned null and never scheduled a preview.
const roadId = 'roadId' in handle.anchor ? handle.anchor.roadId : null;
const sourceRoadId = handle.anchor.type === 'cluster-carriageway' ? handle.anchor.sourceRoadIds[0] : null;
const segmentId = 'segmentId' in handle.anchor ? handle.anchor.segmentId : null;
const cornerRoadId = handle.anchor.type === 'junction-corner' ? handle.anchor.incomingRoadId : null;
const road = state?.compiled.model.roads.find(
(item) =>
(roadId ? item.id === roadId : false) ||
(sourceRoadId ? item.id === sourceRoadId : false) ||
(segmentId ? item.segmentId === segmentId : false) ||
(cornerRoadId ? item.id === cornerRoadId || item.segmentId === cornerRoadId : false),
);
@@ -1105,7 +1114,7 @@ function App() {
onSignalDragEnd={finishSignalMove}
onSignalRotate={rotateSignal}
onSignalRotateEnd={finishSignalRotate}
handles={visibleEditHandles}
handles={junctionRoute ? junctionHandles : visibleEditHandles}
ranges={editRanges}
element={elementOutline}
laneSelectionBounds={laneSelectionBounds}
+1
View File
@@ -113,6 +113,7 @@ const KIND_LABELS: Record<ConstraintKind, string> = {
'road-sidewalk-width': '步行带宽度',
'road-lane-divider': '车道分隔',
'junction-approach-width': '进口宽度',
'cluster-carriageway-width': '车行道宽度',
'junction-cutback': '进口收口距离',
'junction-corner-radius': '角部圆角',
'junction-crosswalk-inset': '斑马线退让',
+21 -2
View File
@@ -12,7 +12,7 @@ import {
projectIntervalEnd,
reserveWindow,
} from './projection';
import type { ConstraintKind, EditHandle, JunctionReserve, RoadIntervalAnchor, Side } from './types';
import type { ConstraintKind, EditHandle, JunctionReserve, RoadIntervalAnchor, SemanticAnchor, Side } from './types';
const CENTER: Coordinate = [116.397, 39.908];
/** The road heads due north, so the manifest reports normal = tangent + 90 = east. */
@@ -38,7 +38,7 @@ function interval(side?: Side, boundaryIndex?: number): RoadIntervalAnchor {
};
}
function makeHandle(kind: ConstraintKind, anchor: RoadIntervalAnchor, current = 0, min = -5, max = 5): EditHandle {
function makeHandle(kind: ConstraintKind, anchor: SemanticAnchor, current = 0, min = -5, max = 5): EditHandle {
return {
handleId: `handle:${kind}`,
kind,
@@ -110,6 +110,25 @@ describe('road-sidewalk-width projection', () => {
});
});
describe('complex carriageway width projection', () => {
it('writes the shared width value shape', () => {
const handle = makeHandle(
'cluster-carriageway-width',
{
type: 'cluster-carriageway',
clusterId: 'cluster-1',
carriagewayKey: 'cluster:cluster-1:carriageway:stable',
sourceNodeIds: ['node-1'],
sourceRoadIds: ['road-1'],
},
6,
4.8,
12,
);
expect(constraintValueFor(handle, 7.5)).toEqual({ widthMeters: 7.5 });
});
});
describe('road-lane-divider projection', () => {
it('is a signed lateral offset, with no side flip', () => {
const handle = makeHandle('road-lane-divider', interval(undefined, 2), 0, -1.2, 1.2);
+1
View File
@@ -102,6 +102,7 @@ export function constraintValueFor(
case 'road-lane-divider':
return { boundaryIndex: boundaryIndexOf(handle), offsetMeters: scalar, transition };
case 'junction-approach-width':
case 'cluster-carriageway-width':
return { widthMeters: Math.max(0, scalar) };
case 'junction-cutback':
return { cutbackMeters: Math.max(0, scalar) };
+8
View File
@@ -26,6 +26,7 @@ export const ROAD_KINDS = ['road-edge-offset', 'road-sidewalk-width', 'road-lane
export const CONTROL_KINDS = ['junction-crosswalk-inset', 'junction-stop-line-offset'] as const;
export const JUNCTION_KINDS = [
'junction-approach-width',
'cluster-carriageway-width',
'junction-cutback',
'junction-corner-radius',
...CONTROL_KINDS,
@@ -59,6 +60,13 @@ export type SemanticAnchor =
boundaryIndex?: number;
}
| { type: 'junction-approach'; nodeId: string; segmentId: string; side?: Side }
| {
type: 'cluster-carriageway';
clusterId: string;
carriagewayKey: string;
sourceNodeIds: string[];
sourceRoadIds: string[];
}
| { type: 'junction-crossing'; crossingId: string; nodeId: string; segmentId: string; roadId: string }
| { type: 'junction-corner'; nodeId: string; incomingRoadId: string; outgoingRoadId: string };
@@ -32,8 +32,9 @@ export function useDirectEditSession({
const touch = () => setRevision((value) => value + 1);
useEffect(() => {
// Flag off: no manifest request at all, so the network trace matches browse mode.
if (!editMode) return;
// Complex junction capability is published by the server as scoped handles,
// so its workspace needs that manifest to expose the edit entry point.
if (!editMode && selectedJunction?.type !== 'cluster') return;
let current = true;
setManifest(null);
api
@@ -82,7 +82,14 @@ export function JunctionWorkspace({
onSignalStatus,
onUpdateSignal,
}: Props) {
const editable = useMemo(() => canEditJunction(descriptor), [descriptor]);
const editable = useMemo(
() =>
canEditJunction(
descriptor,
handles.some((handle) => handle.editable),
),
[descriptor, handles],
);
const complexEnabled = useMemo(() => {
const nodes = new Set(descriptor.nodeIds.map(String));
return Boolean(
@@ -187,7 +194,11 @@ export function JunctionWorkspace({
</div>
<p>
{complexEnabled
? '当前按复杂路口渲染'
? editable
? editMode
? '可编辑外部车行道宽度'
: '当前按复杂路口渲染,开启编辑后可调整外部车行道宽度'
: '当前按复杂路口渲染'
: descriptor.status === 'candidate'
? '当前按普通路口渲染,可切换为复杂路口'
: editable
@@ -505,9 +516,7 @@ export function JunctionWorkspace({
</div>
</>
) : editable ? (
<p className="junction-workspace__browse-hint">
开启编辑模式后,这里会显示进口宽度、进口收口距离和角部圆角控件。
</p>
<p className="junction-workspace__browse-hint">开启编辑模式后,这里会显示可调整的路口几何参数。</p>
) : complexEnabled ? (
<p className="junction-workspace__browse-hint">复杂路口几何已启用;首版仅支持查看,不支持参数拖拽编辑。</p>
) : null}
@@ -76,4 +76,23 @@ describe('junction handle labels', () => {
),
).toBe('道路2 · 东进口 · 进口收口距离');
});
it('names a complex carriageway by its source road', () => {
expect(
junctionLabelForHandle(
handle(
{
type: 'cluster-carriageway',
clusterId: 'cluster-1',
carriagewayKey: 'cluster:cluster-1:carriageway:stable',
sourceNodeIds: ['junction'],
sourceRoadIds: ['road-north'],
},
'cluster-carriageway-width',
),
roads as unknown as Road[],
[120, 30],
),
).toBe('创新大道 · 北进口 · 车行道宽度');
});
});
+5
View File
@@ -58,5 +58,10 @@ export function junctionLabelForHandle(handle: EditHandle, roads: Road[], juncti
const road = roadForKey(roads, handle.anchor.roadId) ?? roadForKey(roads, handle.anchor.segmentId);
return `${approachName(road, roads, junction)} · ${base}`;
}
const clusterAnchor = handle.anchor;
if (handle.kind === 'cluster-carriageway-width' && clusterAnchor.type === 'cluster-carriageway') {
const road = roads.find((item) => clusterAnchor.sourceRoadIds.includes(item.id));
return `${approachName(road, roads, junction)} · ${base}`;
}
return base;
}
@@ -32,8 +32,9 @@ describe('junction workspace session', () => {
expect(leaveJunctionSession(session, 'apply')?.status).toBe('applied');
});
it('only ordinary editable nodes can be changed', () => {
it('opens a cluster when the server published editable handles', () => {
expect(canEditJunction(node as never)).toBe(true);
expect(canEditJunction(cluster as never)).toBe(false);
expect(canEditJunction(cluster as never, true)).toBe(true);
});
});
+2 -2
View File
@@ -46,6 +46,6 @@ export function leaveJunctionSession(session: JunctionSession, action: LeaveActi
return applyJunctionDraft(session);
}
export function canEditJunction(descriptor: JunctionDescriptor): boolean {
return descriptor.ref.type === 'node' && descriptor.status === 'editable';
export function canEditJunction(descriptor: JunctionDescriptor, hasEditableHandles = false): boolean {
return (descriptor.ref.type === 'node' && descriptor.status === 'editable') || hasEditableHandles;
}