feat(workbench): drag control markings as elements
This commit is contained in:
1 parent
834470cfa1
commit
31552a5b6f
9 files changed
+244
-75
No files matched your search
@@ -170,6 +170,20 @@ function App() {
|
||||
* element box and its controls hang off this.
|
||||
*/
|
||||
const [element, setElement] = useState<ElementSelection | null>(null);
|
||||
const visibleEditHandles = useMemo(() => {
|
||||
if (!element || element.kind === 'lane-maneuver') return editHandles;
|
||||
const constraintKind = specOfKind(element.kind).constraintKind;
|
||||
// Control markings use the selected outline itself as their drag target,
|
||||
// exactly like lane-maneuver. Keep the selected control in the index so the
|
||||
// outline can resolve its semantics, while the layer hides its duplicate dot.
|
||||
return editHandles.filter(
|
||||
(handle) =>
|
||||
!handle.kind.startsWith('junction-cross') ||
|
||||
(handle.kind === constraintKind &&
|
||||
handle.anchor.type === 'junction-crossing' &&
|
||||
String(handle.anchor.crossingId) === String(element.crossingNodeId)),
|
||||
);
|
||||
}, [editHandles, element]);
|
||||
/**
|
||||
* The selected element as something to draw and grab.
|
||||
*
|
||||
@@ -189,7 +203,7 @@ function App() {
|
||||
const layer = specOfKind(element.kind).layer;
|
||||
const drawn = preview?.[layer] ?? state.layers[layer];
|
||||
const bounds = orientedBoundsOf(groupMembers(drawn?.features ?? [], element.elementId));
|
||||
return bounds ? { handleId: handle.handleId, bounds } : null;
|
||||
return bounds ? { handleId: handle.handleId, bounds, hideOtherHandles: true } : null;
|
||||
}, [editMode, element, editHandles, state, preview]);
|
||||
const laneSelectionBounds = useMemo<Coordinate[] | null>(() => {
|
||||
if (!element || element.kind !== 'lane-maneuver' || !state || !element.featureIds.length) return null;
|
||||
@@ -785,7 +799,7 @@ function App() {
|
||||
onSignalDragEnd={finishSignalMove}
|
||||
onSignalRotate={rotateSignal}
|
||||
onSignalRotateEnd={finishSignalRotate}
|
||||
handles={editHandles}
|
||||
handles={visibleEditHandles}
|
||||
ranges={editRanges}
|
||||
element={elementOutline}
|
||||
laneSelectionBounds={laneSelectionBounds}
|
||||
|
||||
@@ -263,12 +263,20 @@ export function handleForElement<T extends { kind: string; anchor: Record<string
|
||||
const nodeId = road?.sourceNodeIds.at(-1);
|
||||
if (!road || nodeId === undefined) return null;
|
||||
return (
|
||||
handles.find(
|
||||
(handle) =>
|
||||
handle.kind === spec.constraintKind &&
|
||||
handle.anchor.type === 'junction-crossing' &&
|
||||
String(handle.anchor.crossingId) === String(element.crossingNodeId),
|
||||
) ??
|
||||
// Accept legacy manifests while a saved server document is being upgraded.
|
||||
handles.find(
|
||||
(handle) =>
|
||||
handle.kind === spec.constraintKind &&
|
||||
handle.anchor.segmentId === road.segmentId &&
|
||||
String(handle.anchor.nodeId) === String(nodeId),
|
||||
) ?? null
|
||||
) ??
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -82,6 +82,14 @@ export class EditGhostLayer {
|
||||
* whether you have hit the limit.
|
||||
*/
|
||||
show(handle: EditHandle, value: number): void {
|
||||
// Control markings are dragged from their selected outline, like lane
|
||||
// maneuvers. The generic scalar knob/readout would reintroduce a confusing
|
||||
// blue point and "+N 米" label, so let the preview outline be the only feedback.
|
||||
if (handle.kind === 'junction-crosswalk-inset' || handle.kind === 'junction-stop-line-offset') {
|
||||
this.pending = false;
|
||||
this.source.clear();
|
||||
return;
|
||||
}
|
||||
const clamped = value >= handle.value.max - 1e-6 || value <= handle.value.min + 1e-6;
|
||||
const delta = value - handle.value.current;
|
||||
this.pending = false;
|
||||
|
||||
@@ -34,6 +34,8 @@ export interface ElementOutline {
|
||||
handleId: string;
|
||||
/** Four corners, EPSG:4326, oriented along the element. */
|
||||
bounds: Coordinate[];
|
||||
/** Hide every point handle while a control element owns the gesture. */
|
||||
hideOtherHandles?: boolean;
|
||||
}
|
||||
|
||||
const EDITABLE_STYLE: Record<string, Style> = {
|
||||
@@ -96,6 +98,7 @@ export class EditHandleLayer {
|
||||
private index = new Map<string, EditHandle>();
|
||||
private ranges = new Map<string, IntervalRangeHandle>();
|
||||
private elementIds = new Set<string>();
|
||||
private hideOtherHandles = false;
|
||||
|
||||
constructor() {
|
||||
this.layer = new VectorLayer({
|
||||
@@ -104,10 +107,17 @@ export class EditHandleLayer {
|
||||
zIndex: 100,
|
||||
style: (feature) => {
|
||||
const id = String(feature.get(HANDLE_ID));
|
||||
if (this.elementIds.has(id)) return ELEMENT_STYLE;
|
||||
if (this.elementIds.has(id)) {
|
||||
// The selected element outline owns the drag gesture. Its companion
|
||||
// point is kept in the semantic index but must not be painted as a
|
||||
// confusing second red/green control dot.
|
||||
return feature.getGeometry()?.getType() === 'Polygon' ? ELEMENT_STYLE : undefined;
|
||||
}
|
||||
if (this.hideOtherHandles && feature.getGeometry()?.getType() === 'Point') return undefined;
|
||||
if (this.ranges.has(id)) return RANGE_STYLE;
|
||||
const handle = this.index.get(id);
|
||||
if (!handle) return undefined;
|
||||
if (handle.kind === 'junction-crosswalk-inset' || handle.kind === 'junction-stop-line-offset') return undefined;
|
||||
return handle.editable ? EDITABLE_STYLE[handle.kind] : DISABLED_STYLE;
|
||||
},
|
||||
});
|
||||
@@ -126,6 +136,7 @@ export class EditHandleLayer {
|
||||
this.index = new Map(handles.map((handle) => [handle.handleId, handle]));
|
||||
this.ranges = new Map(ranges.map((range) => [range.handleId, range]));
|
||||
this.elementIds = new Set(element ? [element.handleId] : []);
|
||||
this.hideOtherHandles = element?.hideOtherHandles === true;
|
||||
this.source.clear();
|
||||
if (element)
|
||||
this.source.addFeatures([
|
||||
@@ -134,8 +145,11 @@ export class EditHandleLayer {
|
||||
[HANDLE_ID]: element.handleId,
|
||||
}),
|
||||
]);
|
||||
const renderedHandles = element?.hideOtherHandles
|
||||
? handles.filter((handle) => handle.handleId === element.handleId)
|
||||
: handles;
|
||||
this.source.addFeatures(
|
||||
[...handles, ...ranges].map(
|
||||
[...renderedHandles, ...(element?.hideOtherHandles ? [] : ranges)].map(
|
||||
(handle) =>
|
||||
new Feature({
|
||||
geometry: new Point(fromLonLat(handle.position)),
|
||||
@@ -149,6 +163,7 @@ export class EditHandleLayer {
|
||||
this.index = new Map();
|
||||
this.ranges = new Map();
|
||||
this.elementIds = new Set();
|
||||
this.hideOtherHandles = false;
|
||||
this.source.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ export type SemanticAnchor =
|
||||
boundaryIndex?: number;
|
||||
}
|
||||
| { type: 'junction-approach'; nodeId: string; segmentId: string; side?: Side }
|
||||
| { type: 'junction-crossing'; crossingId: string; nodeId: string; segmentId: string; roadId: string }
|
||||
| { type: 'junction-corner'; nodeId: string; incomingRoadId: string; outgoingRoadId: string };
|
||||
|
||||
export type RoadIntervalAnchor = Extract<SemanticAnchor, { type: 'road-interval' }>;
|
||||
|
||||
Reference in new issue
Block a user