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
@@ -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