fix(workbench): show junction traffic signals
This commit is contained in:
1 parent
f10a5da325
commit
1f439d98de
15 files changed
+529
-60
No files matched your search
@@ -265,7 +265,9 @@ function App() {
|
||||
nodeIds.has(String(feature.properties?.crossing_node_id)),
|
||||
).length;
|
||||
const signals = state.trafficSignals.assemblies.features.filter((feature) =>
|
||||
nodeIds.has(String(feature.properties?.node_id)),
|
||||
[feature.properties?.node_id, feature.properties?.control_id].some(
|
||||
(value) => value !== undefined && value !== null && nodeIds.has(String(value)),
|
||||
),
|
||||
).length;
|
||||
return { crosswalks: crossingIds.size, stopLines, signals };
|
||||
}, [junctionDescriptor, state]);
|
||||
@@ -610,11 +612,27 @@ function App() {
|
||||
previewSession();
|
||||
};
|
||||
const discardJunctionDraft = () => {
|
||||
if (!session) return;
|
||||
session.discard();
|
||||
session?.discard();
|
||||
if (signalDirty && signalSavedRef.current) {
|
||||
setState((current) =>
|
||||
current
|
||||
? {
|
||||
...current,
|
||||
trafficSignals: {
|
||||
...current.trafficSignals,
|
||||
assemblies: { ...current.trafficSignals.assemblies, features: signalSavedRef.current! },
|
||||
},
|
||||
}
|
||||
: current,
|
||||
);
|
||||
signalDraftRef.current = null;
|
||||
signalUndoRef.current = [];
|
||||
signalRedoRef.current = [];
|
||||
setSignalDirty(false);
|
||||
}
|
||||
gesture.current = null;
|
||||
panelRef.current?.clearLive();
|
||||
previewSession();
|
||||
if (session) previewSession();
|
||||
setJunctionSession((current) => (current ? cancelJunctionSession(current) : current));
|
||||
};
|
||||
/** A settled value from either channel: one undoable command, or nothing. */
|
||||
@@ -796,9 +814,9 @@ function App() {
|
||||
}
|
||||
return true;
|
||||
};
|
||||
const compile = async () => {
|
||||
if (!(await save())) return;
|
||||
if (!(await saveDirectEdits(false))) return;
|
||||
const compile = async (): Promise<boolean> => {
|
||||
if (!(await save())) return false;
|
||||
if (!(await saveDirectEdits(false))) return false;
|
||||
if (signalDirty && signalDraftRef.current && state) {
|
||||
try {
|
||||
const result = await api.signals({
|
||||
@@ -811,7 +829,7 @@ function App() {
|
||||
setSignalDirty(false);
|
||||
} catch (error) {
|
||||
setStatus(`红绿灯保存失败:${(error as Error).message}`);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
try {
|
||||
@@ -822,8 +840,10 @@ function App() {
|
||||
setSelected((current) => next.compiled.model.roads.find((road) => road.id === current?.id) || null);
|
||||
setPreview(null);
|
||||
setStatus('已保存并重新生成');
|
||||
return true;
|
||||
} catch (error) {
|
||||
setStatus((error as Error).message);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
if (!state)
|
||||
@@ -858,11 +878,16 @@ function App() {
|
||||
setJunctionRoute(ref);
|
||||
};
|
||||
const closeJunction = () => {
|
||||
if (junctionSession?.dirty) {
|
||||
if (junctionSession?.dirty || signalDirty) {
|
||||
const choice = window.prompt('路口有未应用草稿:输入 1 应用并返回,2 放弃并返回,3 留在工作区', '3');
|
||||
if (choice === '3' || !choice) return;
|
||||
if (choice === '1') setJunctionSession(applyJunctionDraft(junctionSession));
|
||||
else if (choice === '2') {
|
||||
if (choice === '1') {
|
||||
if (signalDirty) {
|
||||
setStatus('信号灯草稿仍未保存,请在工作区内完成保存或放弃。');
|
||||
return;
|
||||
}
|
||||
if (junctionSession) setJunctionSession(applyJunctionDraft(junctionSession));
|
||||
} else if (choice === '2') {
|
||||
discardJunctionDraft();
|
||||
} else return;
|
||||
}
|
||||
@@ -1021,7 +1046,7 @@ function App() {
|
||||
}}
|
||||
onSelectRoad={setSelected}
|
||||
onFeature={handleFeature}
|
||||
signalSelectionUid={typeof marking?.signal_uid === 'string' ? marking.signal_uid : null}
|
||||
signalSelectionUid={marking?.signal_uid == null ? null : String(marking.signal_uid)}
|
||||
onBackground={() => {
|
||||
setElement(null);
|
||||
setMarking(null);
|
||||
@@ -1132,22 +1157,18 @@ function App() {
|
||||
<JunctionWorkspace
|
||||
descriptor={junctionDescriptor}
|
||||
session={junctionSession}
|
||||
dirty={Boolean(junctionSession.dirty || signalDirty)}
|
||||
state={state}
|
||||
diagnostics={junctionDiagnostics}
|
||||
facilitySummary={junctionFacilitySummary}
|
||||
onClose={closeJunction}
|
||||
onApply={() => setJunctionSession((current) => (current ? applyJunctionDraft(current) : current))}
|
||||
onDiscard={discardJunctionDraft}
|
||||
onSave={() => {
|
||||
try {
|
||||
void saveDirectEdits().then((saved) => {
|
||||
if (!saved) return;
|
||||
setJunctionSession((current) => (current ? saveJunctionSession(current, editRevision) : current));
|
||||
setStatus('路口草稿已保存并重新生成');
|
||||
});
|
||||
} catch (error) {
|
||||
setStatus((error as Error).message);
|
||||
}
|
||||
}}
|
||||
onSave={() =>
|
||||
void compile().then((ok) => {
|
||||
if (ok) setJunctionSession((current) => (current ? saveJunctionSession(current, editRevision) : current));
|
||||
})
|
||||
}
|
||||
editMode={editMode}
|
||||
onEnableEdit={() => setEditMode(true)}
|
||||
handles={junctionHandles}
|
||||
@@ -1172,6 +1193,32 @@ function App() {
|
||||
}}
|
||||
roads={junctionRoads}
|
||||
junctionCoordinate={junctionDescriptor.coordinate}
|
||||
selectedFacility={element}
|
||||
selectedSignalUid={marking?.signal_uid == null ? null : String(marking.signal_uid)}
|
||||
signalUids={state.trafficSignals.assemblies.features
|
||||
.filter((item) =>
|
||||
[item.properties?.node_id, item.properties?.control_id].some(
|
||||
(value) => value !== undefined && value !== null && junctionDescriptor.nodeIds.includes(String(value)),
|
||||
),
|
||||
)
|
||||
.map((item) => String(item.properties?.signal_uid ?? ''))
|
||||
.filter(Boolean)}
|
||||
onSignalStatus={setStatus}
|
||||
onUpdateSignal={updateSignal}
|
||||
onSelectFacility={(facility) => {
|
||||
const source =
|
||||
facility.kind === 'crosswalk'
|
||||
? state.layers.crosswalks
|
||||
: facility.kind === 'stop-line'
|
||||
? state.layers.vehicleStopLines
|
||||
: state.trafficSignals.assemblies;
|
||||
const feature = source?.features.find((item) => {
|
||||
if (facility.kind === 'signal')
|
||||
return String(item.properties?.signal_uid) === facility.id.slice('signal:'.length);
|
||||
return String(item.properties?.crossing_node_id) === facility.id.split(':').slice(1).join(':');
|
||||
});
|
||||
if (feature) handleFeature(feature.properties ?? {});
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
@@ -131,17 +131,31 @@ export function MarkingEditor({
|
||||
export function SignalEditor({
|
||||
state,
|
||||
signal,
|
||||
signalUids,
|
||||
allowDelete = true,
|
||||
status,
|
||||
update,
|
||||
}: {
|
||||
state: WorkbenchState;
|
||||
signal?: GeoFeature;
|
||||
signalUids?: readonly string[];
|
||||
allowDelete?: boolean;
|
||||
status: (text: string) => void;
|
||||
update: (features: GeoFeature[]) => Promise<void>;
|
||||
}) {
|
||||
const allowed = signalUids ? new Set(signalUids) : null;
|
||||
const signals = state.trafficSignals.assemblies.features.filter((item) => {
|
||||
const uid = String(item.properties?.signal_uid ?? '');
|
||||
return !allowed || allowed.has(uid);
|
||||
});
|
||||
const [selected, setSelected] = useState('');
|
||||
useEffect(() => setSelected(String(signal?.properties?.signal_uid || '')), [signal]);
|
||||
const feature = state.trafficSignals.assemblies.features.find((item) => item.properties?.signal_uid === selected);
|
||||
useEffect(() => {
|
||||
if (selected && !signals.some((item) => String(item.properties?.signal_uid) === selected)) setSelected('');
|
||||
}, [selected, signals]);
|
||||
const feature = state.trafficSignals.assemblies.features.find(
|
||||
(item) => String(item.properties?.signal_uid ?? '') === selected,
|
||||
);
|
||||
const coordinates =
|
||||
feature?.geometry?.type === 'Point' && Array.isArray(feature.geometry.coordinates)
|
||||
? (feature.geometry.coordinates as [number, number])
|
||||
@@ -183,7 +197,7 @@ export function SignalEditor({
|
||||
检查信号灯
|
||||
<select value={selected} onChange={(event) => setSelected(event.target.value)}>
|
||||
<option value="">选择设施</option>
|
||||
{state.trafficSignals.assemblies.features.map((item) => (
|
||||
{signals.map((item) => (
|
||||
<option key={String(item.properties?.signal_uid)} value={String(item.properties?.signal_uid)}>
|
||||
{String(item.properties?.display_id || item.properties?.signal_uid)}
|
||||
</option>
|
||||
@@ -264,16 +278,18 @@ export function SignalEditor({
|
||||
/>{' '}
|
||||
启用
|
||||
</label>
|
||||
<Button
|
||||
onClick={() =>
|
||||
void update(state.trafficSignals.assemblies.features.filter((item) => item !== feature)).then(() => {
|
||||
setSelected('');
|
||||
status('红绿灯已删除');
|
||||
})
|
||||
}
|
||||
>
|
||||
删除信号灯
|
||||
</Button>
|
||||
{allowDelete ? (
|
||||
<Button
|
||||
onClick={() =>
|
||||
void update(state.trafficSignals.assemblies.features.filter((item) => item !== feature)).then(() => {
|
||||
setSelected('');
|
||||
status('红绿灯已删除');
|
||||
})
|
||||
}
|
||||
>
|
||||
删除信号灯
|
||||
</Button>
|
||||
) : null}
|
||||
</>
|
||||
) : null}
|
||||
</section>
|
||||
|
||||
@@ -487,7 +487,7 @@ export function MapCanvas({
|
||||
layer.setVisible(Boolean(editMode && signalSelectionUid));
|
||||
if (!editMode || !signalSelectionUid) return;
|
||||
const signal = state.trafficSignals.assemblies.features.find(
|
||||
(feature) => feature.properties?.signal_uid === signalSelectionUid,
|
||||
(feature) => String(feature.properties?.signal_uid ?? '') === String(signalSelectionUid),
|
||||
);
|
||||
const pivot =
|
||||
signal?.geometry?.type === 'Point' && Array.isArray(signal.geometry.coordinates)
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
// an intent, and a clamped typo reads as a plausible value that can go
|
||||
// unnoticed. Same invariant, two devices, two honest ways to say "no".
|
||||
|
||||
import { useImperativeHandle, useLayoutEffect, useRef, useState, type Ref } from 'react';
|
||||
import { useEffect, useImperativeHandle, useLayoutEffect, useRef, useState, type Ref } from 'react';
|
||||
import { Minus, Plus } from 'lucide-react';
|
||||
import {
|
||||
formatBoundInward,
|
||||
@@ -67,6 +67,7 @@ interface RowCallbacks {
|
||||
labelForHandle?: (handle: EditHandle) => string;
|
||||
onDraftGroup?: (handles: EditHandle[], value: number) => void;
|
||||
onSettleGroup?: (handles: EditHandle[], value: number) => void;
|
||||
highlightedHandleId?: string;
|
||||
}
|
||||
|
||||
function ParameterRow({
|
||||
@@ -77,6 +78,7 @@ function ParameterRow({
|
||||
onAbandon,
|
||||
onReset,
|
||||
labelForHandle: resolveLabel,
|
||||
highlightedHandleId,
|
||||
}: RowCallbacks & {
|
||||
handle: EditHandle;
|
||||
register: (handleId: string, node: HTMLInputElement | null) => void;
|
||||
@@ -151,7 +153,10 @@ function ParameterRow({
|
||||
};
|
||||
|
||||
return (
|
||||
<li className={reason ? 'parameter disabled' : 'parameter'}>
|
||||
<li
|
||||
data-handle-id={handle.handleId}
|
||||
className={`${reason ? 'parameter disabled' : 'parameter'}${highlightedHandleId === handle.handleId ? ' parameter--highlighted' : ''}`}
|
||||
>
|
||||
<span className="parameter-label">
|
||||
{displayLabel}
|
||||
{isModified(handle) ? (
|
||||
@@ -323,12 +328,28 @@ export function ParameterPanel({
|
||||
function GroupedParameterList({
|
||||
groups,
|
||||
register,
|
||||
highlightedHandleId,
|
||||
...callbacks
|
||||
}: RowCallbacks & {
|
||||
groups: Array<[string, EditHandle[]]>;
|
||||
register: (handleId: string, node: HTMLInputElement | null) => void;
|
||||
}) {
|
||||
const [expanded, setExpanded] = useState<Record<string, boolean>>({});
|
||||
const highlightedGroup = groups.find(([, items]) => items.some((item) => item.handleId === highlightedHandleId))?.[0];
|
||||
|
||||
useEffect(() => {
|
||||
if (!highlightedGroup) return;
|
||||
setExpanded((current) => (current[highlightedGroup] ? current : { ...current, [highlightedGroup]: true }));
|
||||
}, [highlightedGroup]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!highlightedGroup || !expanded[highlightedGroup]) return;
|
||||
const frame = window.requestAnimationFrame(() => {
|
||||
const node = document.querySelector<HTMLElement>(`[data-handle-id="${CSS.escape(highlightedHandleId ?? '')}"]`);
|
||||
node?.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||||
});
|
||||
return () => window.cancelAnimationFrame(frame);
|
||||
}, [expanded, highlightedGroup, highlightedHandleId]);
|
||||
return (
|
||||
<ul className="parameter-groups">
|
||||
{groups.map(([kind, items]) => {
|
||||
@@ -377,6 +398,7 @@ function GroupedParameterList({
|
||||
handle={globalHandle}
|
||||
register={register}
|
||||
{...callbacks}
|
||||
highlightedHandleId={highlightedHandleId}
|
||||
onDraft={(handle, value) => globalDraft(items, value)}
|
||||
onSettle={(handle, value) => globalSettle(items, value)}
|
||||
labelForHandle={() => '统一值'}
|
||||
@@ -384,7 +406,13 @@ function GroupedParameterList({
|
||||
{expandedGroup ? (
|
||||
<ul className="parameter-group__details">
|
||||
{items.map((handle) => (
|
||||
<ParameterRow handle={handle} register={register} key={handle.handleId} {...callbacks} />
|
||||
<ParameterRow
|
||||
handle={handle}
|
||||
register={register}
|
||||
key={handle.handleId}
|
||||
{...callbacks}
|
||||
highlightedHandleId={highlightedHandleId}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
) : null}
|
||||
@@ -397,7 +425,7 @@ function GroupedParameterList({
|
||||
|
||||
function groupLabel(kind: string, handle: EditHandle): string {
|
||||
if (kind === 'junction-approach-width') return '进口宽度';
|
||||
if (kind === 'junction-cutback') return '进口 cutback';
|
||||
if (kind === 'junction-cutback') return '进口收口距离';
|
||||
if (kind === 'junction-corner-radius') return '角部圆角';
|
||||
if (kind === 'junction-crosswalk-inset') return '斑马线退让';
|
||||
if (kind === 'junction-stop-line-offset') return '停止线退距';
|
||||
|
||||
@@ -52,8 +52,10 @@ export function WorkbenchInspector({
|
||||
const effective = (id: string, fallback: boolean) =>
|
||||
((staged.find((item) => item.id === id) || state.overrides.overrides.find((item) => item.id === id))?.enabled as
|
||||
boolean | undefined) ?? fallback;
|
||||
const signalUid = typeof marking?.signal_uid === 'string' ? marking.signal_uid : '';
|
||||
const signal = state.trafficSignals.assemblies.features.find((item) => item.properties?.signal_uid === signalUid);
|
||||
const signalUid = marking?.signal_uid == null ? '' : String(marking.signal_uid);
|
||||
const signal = state.trafficSignals.assemblies.features.find(
|
||||
(item) => String(item.properties?.signal_uid ?? '') === signalUid,
|
||||
);
|
||||
const [open, setOpen] = useState<'road' | 'element' | 'connections' | 'advanced' | null>('road');
|
||||
useEffect(() => {
|
||||
if (element || marking) setOpen('element');
|
||||
|
||||
@@ -113,7 +113,7 @@ const KIND_LABELS: Record<ConstraintKind, string> = {
|
||||
'road-sidewalk-width': '步行带宽度',
|
||||
'road-lane-divider': '车道分隔',
|
||||
'junction-approach-width': '进口宽度',
|
||||
'junction-cutback': '进口 cutback',
|
||||
'junction-cutback': '进口收口距离',
|
||||
'junction-corner-radius': '角部圆角',
|
||||
'junction-crosswalk-inset': '斑马线退让',
|
||||
'junction-crosswalk-size': '斑马线尺寸',
|
||||
|
||||
@@ -16,7 +16,7 @@ const limitPole = (feature: GeoFeature | undefined, coordinate: Coordinate): Coo
|
||||
const rotateFeatures = (features: GeoFeature[], uid: string, mastHeading: number): GeoFeature[] => {
|
||||
const heading = ((mastHeading % 360) + 360) % 360;
|
||||
return features.map((feature) =>
|
||||
feature.properties?.signal_uid === uid
|
||||
String(feature.properties?.signal_uid ?? '') === String(uid)
|
||||
? {
|
||||
...feature,
|
||||
properties: {
|
||||
@@ -79,7 +79,7 @@ export function useTrafficSignalDraft({
|
||||
moveActiveRef.current = true;
|
||||
}
|
||||
const source = current.trafficSignals.assemblies.features.find(
|
||||
(feature) => feature.properties?.signal_uid === uid,
|
||||
(feature) => String(feature.properties?.signal_uid ?? '') === String(uid),
|
||||
);
|
||||
const nextCoordinate = limitPole(source, coordinate);
|
||||
return {
|
||||
@@ -89,7 +89,7 @@ export function useTrafficSignalDraft({
|
||||
assemblies: {
|
||||
...current.trafficSignals.assemblies,
|
||||
features: current.trafficSignals.assemblies.features.map((feature) =>
|
||||
feature.properties?.signal_uid === uid
|
||||
String(feature.properties?.signal_uid ?? '') === String(uid)
|
||||
? { ...feature, geometry: { type: 'Point', coordinates: nextCoordinate } }
|
||||
: feature,
|
||||
),
|
||||
@@ -105,10 +105,12 @@ export function useTrafficSignalDraft({
|
||||
const finishMove = useCallback(
|
||||
(uid: string, coordinate: Coordinate) => {
|
||||
if (!state) return;
|
||||
const source = state.trafficSignals.assemblies.features.find((feature) => feature.properties?.signal_uid === uid);
|
||||
const source = state.trafficSignals.assemblies.features.find(
|
||||
(feature) => String(feature.properties?.signal_uid ?? '') === String(uid),
|
||||
);
|
||||
const nextCoordinate = limitPole(source, coordinate);
|
||||
draftRef.current = state.trafficSignals.assemblies.features.map((feature) =>
|
||||
feature.properties?.signal_uid === uid
|
||||
String(feature.properties?.signal_uid ?? '') === String(uid)
|
||||
? { ...feature, geometry: { type: 'Point', coordinates: nextCoordinate } }
|
||||
: feature,
|
||||
);
|
||||
|
||||
@@ -4,15 +4,21 @@ import { canEditJunction, type JunctionSession } from './workspace';
|
||||
import { Button } from '../ui/button';
|
||||
import { ParameterPanel } from '../components/ParameterPanel';
|
||||
import type { EditHandle } from '../edit/types';
|
||||
import type { ElementSelection } from '../edit/element';
|
||||
import type { Road } from '../types/state';
|
||||
import type { WorkbenchState } from '../types/state';
|
||||
import type { Coordinate } from '../edit/meters';
|
||||
import { junctionLabelForHandle, junctionRoadName } from './labels';
|
||||
import { junctionFacilities } from './facilities';
|
||||
import { SignalEditor } from '../components/ElementEditors';
|
||||
|
||||
interface Props {
|
||||
descriptor: JunctionDescriptor;
|
||||
session: JunctionSession;
|
||||
dirty?: boolean;
|
||||
diagnostics?: Array<{ id: string; message: string; rule: string; severity?: string }>;
|
||||
facilitySummary?: { crosswalks: number; stopLines: number; signals: number };
|
||||
state?: WorkbenchState;
|
||||
onClose: () => void;
|
||||
onApply: () => void;
|
||||
onDiscard: () => void;
|
||||
@@ -28,11 +34,18 @@ interface Props {
|
||||
onReset?: (handle: EditHandle) => void;
|
||||
roads?: Road[];
|
||||
junctionCoordinate?: Coordinate;
|
||||
selectedFacility?: ElementSelection | null;
|
||||
onSelectFacility?: (facility: { id: string; kind: 'crosswalk' | 'stop-line' | 'signal' }) => void;
|
||||
signalUids?: readonly string[];
|
||||
selectedSignalUid?: string | null;
|
||||
onSignalStatus?: (message: string) => void;
|
||||
onUpdateSignal?: (features: import('../types/state').GeoFeature[]) => Promise<void>;
|
||||
}
|
||||
|
||||
export function JunctionWorkspace({
|
||||
descriptor,
|
||||
session,
|
||||
dirty = session.dirty,
|
||||
onClose,
|
||||
onApply,
|
||||
onDiscard,
|
||||
@@ -41,6 +54,7 @@ export function JunctionWorkspace({
|
||||
onEnableEdit,
|
||||
diagnostics = [],
|
||||
facilitySummary = { crosswalks: 0, stopLines: 0, signals: 0 },
|
||||
state,
|
||||
handles = [],
|
||||
onDraft,
|
||||
onDraftGroup,
|
||||
@@ -50,8 +64,18 @@ export function JunctionWorkspace({
|
||||
onReset,
|
||||
roads = [],
|
||||
junctionCoordinate = descriptor.coordinate,
|
||||
selectedFacility,
|
||||
onSelectFacility,
|
||||
signalUids = [],
|
||||
selectedSignalUid,
|
||||
onSignalStatus,
|
||||
onUpdateSignal,
|
||||
}: Props) {
|
||||
const editable = useMemo(() => canEditJunction(descriptor), [descriptor]);
|
||||
const facilities = useMemo(
|
||||
() => (state ? junctionFacilities(state, descriptor.nodeIds, roads) : []),
|
||||
[descriptor.nodeIds, roads, state],
|
||||
);
|
||||
return (
|
||||
<section className="junction-workspace" aria-label="路口编辑工作区">
|
||||
<header className="junction-workspace__header">
|
||||
@@ -83,7 +107,7 @@ export function JunctionWorkspace({
|
||||
<dt>状态</dt>
|
||||
<dd>
|
||||
{session.status}
|
||||
{session.dirty ? '(有未应用草稿)' : ''}
|
||||
{dirty ? '(有未应用草稿)' : ''}
|
||||
</dd>
|
||||
</dl>
|
||||
<section className="junction-workspace__validation" aria-label="路口验证">
|
||||
@@ -91,6 +115,44 @@ export function JunctionWorkspace({
|
||||
<p>
|
||||
斑马线 {facilitySummary.crosswalks} · 停止线 {facilitySummary.stopLines} · 信号灯 {facilitySummary.signals}
|
||||
</p>
|
||||
{facilities.length ? (
|
||||
<ul className="junction-workspace__facilities" aria-label="已有设施">
|
||||
{facilities.map((facility) => (
|
||||
<li key={facility.id}>
|
||||
<button
|
||||
type="button"
|
||||
className={
|
||||
(facility.kind === 'signal' && selectedSignalUid === facility.id.slice('signal:'.length)) ||
|
||||
(selectedFacility &&
|
||||
selectedFacility.kind === facility.kind &&
|
||||
String(selectedFacility.crossingNodeId) === facility.id.split(':').slice(1).join(':'))
|
||||
? 'is-selected'
|
||||
: undefined
|
||||
}
|
||||
aria-current={
|
||||
(facility.kind === 'signal' && selectedSignalUid === facility.id.slice('signal:'.length)) ||
|
||||
(selectedFacility &&
|
||||
selectedFacility.kind === facility.kind &&
|
||||
String(selectedFacility.crossingNodeId) === facility.id.split(':').slice(1).join(':'))
|
||||
? 'true'
|
||||
: undefined
|
||||
}
|
||||
onClick={() => onSelectFacility?.(facility)}
|
||||
>
|
||||
{facility.label}
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : null}
|
||||
{selectedFacility && selectedFacility.kind !== 'lane-maneuver' ? (
|
||||
<p className="junction-workspace__facility-selection">
|
||||
当前选中:{selectedFacility.kind === 'crosswalk' ? '斑马线' : '停止线'}。可在下方参数中调整位置。
|
||||
</p>
|
||||
) : null}
|
||||
{selectedSignalUid ? (
|
||||
<p className="junction-workspace__facility-selection">当前选中:信号灯。可在下方参数中调整。</p>
|
||||
) : null}
|
||||
{diagnostics.length ? (
|
||||
<ul>
|
||||
{diagnostics.map((item) => (
|
||||
@@ -116,22 +178,51 @@ export function JunctionWorkspace({
|
||||
onAbandon={onAbandon ?? (() => undefined)}
|
||||
onReset={onReset ?? (() => undefined)}
|
||||
labelForHandle={(handle) => junctionLabelForHandle(handle, roads, junctionCoordinate)}
|
||||
highlightedHandleId={
|
||||
selectedFacility && selectedFacility.kind !== 'lane-maneuver'
|
||||
? handles.find(
|
||||
(handle) =>
|
||||
handle.anchor.type === 'junction-crossing' &&
|
||||
String(handle.anchor.crossingId) === String(selectedFacility.crossingNodeId) &&
|
||||
handle.kind ===
|
||||
(selectedFacility.kind === 'crosswalk'
|
||||
? 'junction-crosswalk-inset'
|
||||
: 'junction-stop-line-offset'),
|
||||
)?.handleId
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
{onUpdateSignal ? (
|
||||
<SignalEditor
|
||||
state={state!}
|
||||
signal={
|
||||
selectedSignalUid
|
||||
? state?.trafficSignals.assemblies.features.find(
|
||||
(item) => String(item.properties?.signal_uid) === selectedSignalUid,
|
||||
)
|
||||
: undefined
|
||||
}
|
||||
signalUids={signalUids}
|
||||
allowDelete={false}
|
||||
status={onSignalStatus ?? (() => undefined)}
|
||||
update={onUpdateSignal}
|
||||
/>
|
||||
) : null}
|
||||
<div className="junction-workspace__actions">
|
||||
<Button onClick={onApply} disabled={!session.dirty}>
|
||||
<Button onClick={onApply} disabled={!dirty}>
|
||||
应用到工作区
|
||||
</Button>
|
||||
<Button onClick={onSave} disabled={session.dirty}>
|
||||
<Button onClick={onSave} disabled={!dirty}>
|
||||
保存
|
||||
</Button>
|
||||
<Button onClick={onDiscard} disabled={!session.dirty}>
|
||||
<Button onClick={onDiscard} disabled={!dirty}>
|
||||
放弃草稿
|
||||
</Button>
|
||||
</div>
|
||||
</>
|
||||
) : editable ? (
|
||||
<p className="junction-workspace__browse-hint">
|
||||
开启编辑模式后,这里会显示进口宽度、cutback 和角部圆角控件。
|
||||
开启编辑模式后,这里会显示进口宽度、进口收口距离和角部圆角控件。
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { junctionFacilities } from './facilities';
|
||||
import type { WorkbenchState } from '../types/state';
|
||||
|
||||
const road = {
|
||||
id: 'road-a',
|
||||
segmentId: 'segment-a',
|
||||
centerline: [],
|
||||
sourceNodeIds: [],
|
||||
osmWayIds: [],
|
||||
tags: { name: '创新大道' },
|
||||
highway: 'primary',
|
||||
direction: 'forward',
|
||||
widthMeters: 8,
|
||||
laneCount: 2,
|
||||
sidewalkLeft: true,
|
||||
sidewalkRight: true,
|
||||
};
|
||||
const feature = (properties: Record<string, unknown>) => ({ type: 'Feature' as const, properties, geometry: null });
|
||||
|
||||
it('groups zebra stripes while keeping each facility type distinct', () => {
|
||||
const state = {
|
||||
layers: {
|
||||
crosswalks: {
|
||||
type: 'FeatureCollection',
|
||||
features: [
|
||||
feature({ crossing_node_id: 'node-1', road_id: 'road-a' }),
|
||||
feature({ crossing_node_id: 'node-1', road_id: 'road-a' }),
|
||||
],
|
||||
},
|
||||
vehicleStopLines: {
|
||||
type: 'FeatureCollection',
|
||||
features: [feature({ crossing_node_id: 'node-1', road_id: 'road-a' })],
|
||||
},
|
||||
},
|
||||
trafficSignals: {
|
||||
assemblies: {
|
||||
type: 'FeatureCollection',
|
||||
features: [feature({ control_id: 'node-1', signal_uid: 'signal-1', road_id: 'road-a' })],
|
||||
},
|
||||
},
|
||||
} as unknown as WorkbenchState;
|
||||
expect(junctionFacilities(state, ['node-1'], [road])).toEqual([
|
||||
{ id: 'crosswalk:node-1', kind: 'crosswalk', label: '斑马线 · 创新大道' },
|
||||
{ id: 'stop-line:node-1', kind: 'stop-line', label: '停止线 · 创新大道' },
|
||||
{ id: 'signal:signal-1', kind: 'signal', label: '信号灯 · 创新大道' },
|
||||
]);
|
||||
});
|
||||
|
||||
it('filters every facility to the active junction nodes', () => {
|
||||
const state = {
|
||||
layers: {
|
||||
crosswalks: {
|
||||
type: 'FeatureCollection',
|
||||
features: [
|
||||
feature({ crossing_node_id: 'node-1', road_id: 'road-a' }),
|
||||
feature({ crossing_node_id: 'node-2', road_id: 'road-a' }),
|
||||
],
|
||||
},
|
||||
vehicleStopLines: {
|
||||
type: 'FeatureCollection',
|
||||
features: [feature({ crossing_node_id: 'node-2', road_id: 'road-a' })],
|
||||
},
|
||||
},
|
||||
trafficSignals: {
|
||||
assemblies: {
|
||||
type: 'FeatureCollection',
|
||||
features: [
|
||||
feature({ node_id: 'node-1', signal_uid: 7, road_id: 'road-a' }),
|
||||
feature({ node_id: 'node-2', signal_uid: '8', road_id: 'road-a' }),
|
||||
],
|
||||
},
|
||||
},
|
||||
} as unknown as WorkbenchState;
|
||||
expect(junctionFacilities(state, ['node-1'], [road])).toEqual([
|
||||
{ id: 'crosswalk:node-1', kind: 'crosswalk', label: '斑马线 · 创新大道' },
|
||||
{ id: 'signal:7', kind: 'signal', label: '信号灯 · 创新大道' },
|
||||
]);
|
||||
});
|
||||
@@ -0,0 +1,62 @@
|
||||
import type { GeoFeature, Road, WorkbenchState } from '../types/state';
|
||||
import { junctionRoadName } from './labels';
|
||||
|
||||
export interface JunctionFacility {
|
||||
id: string;
|
||||
kind: 'crosswalk' | 'stop-line' | 'signal';
|
||||
label: string;
|
||||
}
|
||||
|
||||
function text(value: unknown): string | null {
|
||||
return typeof value === 'string' || typeof value === 'number' ? String(value) : null;
|
||||
}
|
||||
|
||||
function roadLabel(feature: GeoFeature, roads: Road[]): string {
|
||||
const id = text(feature.properties?.road_id);
|
||||
const sourceWay = text(feature.properties?.source_way_id);
|
||||
const approach = text(feature.properties?.approach_id)?.split(':')[0];
|
||||
const road = roads.find(
|
||||
(item) =>
|
||||
item.id === id ||
|
||||
(sourceWay !== null && item.osmWayIds.map(String).includes(sourceWay)) ||
|
||||
(approach !== undefined && item.osmWayIds.map(String).includes(approach)),
|
||||
);
|
||||
return junctionRoadName(road, roads);
|
||||
}
|
||||
|
||||
/** One user-facing item per existing facility, never one item per zebra stripe. */
|
||||
export function junctionFacilities(
|
||||
state: WorkbenchState,
|
||||
nodeIds: readonly string[],
|
||||
roads: Road[],
|
||||
): JunctionFacility[] {
|
||||
const nodes = new Set(nodeIds.map(String));
|
||||
const result = new Map<string, JunctionFacility>();
|
||||
for (const feature of state.layers.crosswalks?.features ?? []) {
|
||||
const crossing = text(feature.properties?.crossing_node_id);
|
||||
if (!crossing || !nodes.has(crossing)) continue;
|
||||
result.set(`crosswalk:${crossing}`, {
|
||||
id: `crosswalk:${crossing}`,
|
||||
kind: 'crosswalk',
|
||||
label: `斑马线 · ${roadLabel(feature, roads)}`,
|
||||
});
|
||||
}
|
||||
for (const feature of state.layers.vehicleStopLines?.features ?? []) {
|
||||
const crossing = text(feature.properties?.crossing_node_id);
|
||||
if (!crossing || !nodes.has(crossing)) continue;
|
||||
result.set(`stop-line:${crossing}`, {
|
||||
id: `stop-line:${crossing}`,
|
||||
kind: 'stop-line',
|
||||
label: `停止线 · ${roadLabel(feature, roads)}`,
|
||||
});
|
||||
}
|
||||
for (const feature of state.trafficSignals.assemblies.features) {
|
||||
const nodeIdsForSignal = [text(feature.properties?.node_id), text(feature.properties?.control_id)].filter(
|
||||
(value): value is string => value !== null,
|
||||
);
|
||||
if (!nodeIdsForSignal.some((node) => nodes.has(node))) continue;
|
||||
const id = text(feature.properties?.signal_uid) ?? `signal:${nodeIdsForSignal[0]}`;
|
||||
result.set(`signal:${id}`, { id: `signal:${id}`, kind: 'signal', label: `信号灯 · ${roadLabel(feature, roads)}` });
|
||||
}
|
||||
return [...result.values()];
|
||||
}
|
||||
@@ -74,6 +74,6 @@ describe('junction handle labels', () => {
|
||||
roads as unknown as Road[],
|
||||
[120, 30],
|
||||
),
|
||||
).toBe('道路2 · 东进口 · 进口 cutback');
|
||||
).toBe('道路2 · 东进口 · 进口收口距离');
|
||||
});
|
||||
});
|
||||
@@ -4,13 +4,33 @@ import type { PreviewLayerName } from '../edit/types';
|
||||
|
||||
const empty: GeoJson = { type: 'FeatureCollection', features: [] };
|
||||
|
||||
function approachRoadIdsForDescriptor(state: WorkbenchState, descriptor: JunctionDescriptor): Set<string> {
|
||||
const ids = new Set(descriptor.approachRoadIds);
|
||||
if (!ids.size) {
|
||||
const nodes = new Set(descriptor.nodeIds.map(String));
|
||||
for (const endpoint of state.compiled.model.endpoints || []) {
|
||||
if (nodes.has(String(endpoint.nodeId))) ids.add(endpoint.roadId);
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
function approachRoadIdsFromRoads(roads: Road[], descriptor: JunctionDescriptor): Set<string> {
|
||||
const ids = new Set(descriptor.approachRoadIds);
|
||||
if (!ids.size) {
|
||||
const nodes = new Set(descriptor.nodeIds.map(String));
|
||||
for (const road of roads) if (road.sourceNodeIds.some((node) => nodes.has(String(node)))) ids.add(road.id);
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
function text(value: unknown): string | null {
|
||||
return typeof value === 'string' || typeof value === 'number' ? String(value) : null;
|
||||
}
|
||||
|
||||
function related(feature: GeoFeature, nodeIds: Set<string>, roadIds: Set<string>, segmentIds: Set<string>): boolean {
|
||||
const props = feature.properties || {};
|
||||
const nodeKeys = ['node_id', 'osm_node_id', 'crossing_node_id', 'junction_node_id'];
|
||||
const nodeKeys = ['node_id', 'osm_node_id', 'control_id', 'crossing_node_id', 'junction_node_id'];
|
||||
if (
|
||||
nodeKeys.some((key) => {
|
||||
const value = text(props[key]);
|
||||
@@ -45,7 +65,8 @@ export function localJunctionPreview(
|
||||
): Partial<Record<PreviewLayerName, GeoJson | null>> | null {
|
||||
if (!preview) return preview ?? null;
|
||||
const nodeIds = new Set(descriptor.nodeIds.map(String));
|
||||
const selectedRoads = roads.filter((road) => descriptor.approachRoadIds.includes(road.id));
|
||||
const approachRoadIds = approachRoadIdsFromRoads(roads, descriptor);
|
||||
const selectedRoads = roads.filter((road) => approachRoadIds.has(road.id) || approachRoadIds.has(road.segmentId));
|
||||
const roadIds = new Set(selectedRoads.map((road) => road.id));
|
||||
const segmentIds = new Set(selectedRoads.map((road) => road.segmentId));
|
||||
const scoped = { ...preview };
|
||||
@@ -63,7 +84,10 @@ export function localJunctionPreview(
|
||||
/** Build the intentionally small state consumed by the independent junction canvas. */
|
||||
export function localJunctionState(state: WorkbenchState, descriptor: JunctionDescriptor): WorkbenchState {
|
||||
const nodeIds = new Set(descriptor.nodeIds.map(String));
|
||||
const roads = state.compiled.model.roads.filter((road) => descriptor.approachRoadIds.includes(road.id));
|
||||
const approachRoadIds = approachRoadIdsForDescriptor(state, descriptor);
|
||||
const roads = state.compiled.model.roads.filter(
|
||||
(road) => approachRoadIds.has(road.id) || approachRoadIds.has(road.segmentId),
|
||||
);
|
||||
const roadIds = new Set(roads.map((road) => road.id));
|
||||
const segmentIds = new Set(roads.map((road) => road.segmentId));
|
||||
const keep = (value: GeoJson | null | undefined): GeoJson => ({
|
||||
|
||||
@@ -409,6 +409,28 @@ pre {
|
||||
.parameter.disabled {
|
||||
background: #f2f4f3;
|
||||
}
|
||||
.parameter--highlighted {
|
||||
border-color: #d7a23c;
|
||||
background: #fff8e8;
|
||||
box-shadow: 0 0 0 2px rgb(215 162 60 / 22%);
|
||||
animation: parameter-highlight-pulse 1.8s ease-out 1;
|
||||
}
|
||||
.parameter--highlighted .parameter-label {
|
||||
color: #6f5318;
|
||||
font-weight: 600;
|
||||
}
|
||||
.parameter--highlighted .parameter-input {
|
||||
border-color: #c58b1b;
|
||||
background: #fffdf7;
|
||||
}
|
||||
@keyframes parameter-highlight-pulse {
|
||||
0% {
|
||||
box-shadow: 0 0 0 4px rgb(215 162 60 / 35%);
|
||||
}
|
||||
100% {
|
||||
box-shadow: 0 0 0 2px rgb(215 162 60 / 22%);
|
||||
}
|
||||
}
|
||||
.parameter.disabled .parameter-value {
|
||||
color: #9aa8a1;
|
||||
}
|
||||
@@ -711,6 +733,37 @@ pre {
|
||||
gap: 0.5rem;
|
||||
margin-top: 1.5rem;
|
||||
}
|
||||
.junction-workspace__facilities {
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
margin: 8px 0 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
}
|
||||
.junction-workspace__facilities li {
|
||||
padding: 5px 7px;
|
||||
border-left: 2px solid #d7a23c;
|
||||
background: #fffaf0;
|
||||
color: #5d4a21;
|
||||
font-size: 12px;
|
||||
}
|
||||
.junction-workspace__facilities button {
|
||||
width: 100%;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: none;
|
||||
color: inherit;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
}
|
||||
.junction-workspace__facility-selection {
|
||||
margin: 8px 0 0;
|
||||
padding: 6px 8px;
|
||||
border: 1px solid #d7a23c;
|
||||
background: #fff7e6;
|
||||
color: #70551a;
|
||||
font-size: 12px;
|
||||
}
|
||||
.junction-workspace__browse-hint {
|
||||
margin: 1.5rem 0 0;
|
||||
padding: 0.75rem 1rem;
|
||||
|
||||
Reference in new issue
Block a user