feat: select a crosswalk group by clicking any of its stripes

A crosswalk renders as six stripe features but is edited as one thing. Clicking
one now resolves the whole group, and clicking anything else drops the selection
so a box cannot outlive what it was drawn around.

The group id needed no compiler change: crosswalk:node/<crossingId> is already
stable, because compileControlMarkings() emits exactly one group per crossing
from a single candidate road. Verified against real output — 48 stripes, 8
groups of 6, nothing ungrouped, and none of the 8 stop lines mistaken for one,
since both share controlFeature() and are told apart by provenance. Grouping
therefore reads a published identifier rather than clustering on proximity,
which prd.md forbids.

Two supporting fixes in MapCanvas: the select callbacks join the existing
callback ref, and an empty click now reports background instead of returning
early. The listener is registered once, so it had been holding the first
render's closures — harmless while they only called stable setters, and not
survivable now that one of them reads current layers.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
que01andClaude Opus 5 committed 2026-08-31 13:35:59 +08:00
1 parent 623481fd2c
commit 2694cad619
4 files changed
+267 -9

No files matched your search

+22 -5
View File
@@ -3,6 +3,7 @@ import { Download, RefreshCw, Save, Upload } from 'lucide-react';
import { api, isVersionConflict } from './lib/api';
import { MapCanvas } from './components/MapCanvas';
import { ParameterPanel, type ParameterPanelHandle } from './components/ParameterPanel';
import { elementSelectionFor, type ElementSelection } from './edit/element';
import { directEditEnabled, intervalEditingSupported } from './edit/flag';
import { PreviewRequester, type PreviewDraft } from './edit/preview-request';
import { anchorSnapshotFor, constraintValueFor, draftConstraint, operationFor } from './edit/projection';
@@ -160,6 +161,14 @@ function App() {
}, [editHandles, manifest, selected, state]);
const [preview, setPreview] = useState<Partial<Record<PreviewLayerName, GeoJson | null>> | null>(null);
const [editDiagnostics, setEditDiagnostics] = useState<EditDiagnostic[]>([]);
/**
* The crosswalk group under selection, if any.
*
* Element selection is independent of road selection: clicking a stripe also
* selects its road, because the road-level handles stay useful. Only the
* element box and its controls hang off this.
*/
const [element, setElement] = useState<ElementSelection | null>(null);
const sessionRef = useRef<EditSession | null>(null);
if (directEditEnabled && !sessionRef.current) sessionRef.current = new EditSession();
// Per-frame drag feedback reaches the panel through this rather than through
@@ -450,6 +459,11 @@ function App() {
);
const handleFeature = (properties: Record<string, unknown>) => {
setMarking(properties);
// A crosswalk is six features but one editable thing. Clicking any stripe
// selects the group; clicking anything else drops the element selection,
// because a box left around a crosswalk the user navigated away from reads
// as a stuck UI.
if (directEditEnabled) setElement(elementSelectionFor(properties, state.layers.crosswalks?.features ?? []));
const uid = properties.signal_uid;
if (typeof uid === 'string') setStatus(`已选中原生红绿灯 ${uid}`);
else if (properties.effective_style) setStatus('已选中标线,可在右侧暂存样式');
@@ -466,11 +480,13 @@ function App() {
{directEditEnabled ? (
<span className={editDiagnostics.some((item) => item.severity === 'error') ? 'dirty' : ''}>
{editDiagnostics.find((item) => item.severity === 'error')?.message ||
(editHandles.length
? `手柄 ${editHandles.length} 个`
: selected
? '当前道路无可编辑手柄'
: '选中道路以显示手柄')}
(element
? `已选中斑马线 ${element.crossingNodeId}(${element.featureIds.length} 条)`
: editHandles.length
? `手柄 ${editHandles.length} 个`
: selected
? '当前道路无可编辑手柄'
: '选中道路以显示手柄')}
{blockedReason ? `|${blockedReason}` : ''}
</span>
) : null}
@@ -551,6 +567,7 @@ function App() {
scene={scene}
onSelectRoad={setSelected}
onFeature={handleFeature}
onBackground={() => setElement(null)}
handles={editHandles}
ranges={editRanges}
preview={preview}