feat: complete carriageway direction interaction
This commit is contained in:
1 parent
a5089220b5
commit
067c0e370d
10 files changed
+251
-41
No files matched your search
@@ -97,7 +97,7 @@ export class EditGhostLayer {
|
||||
this.source.addFeature(
|
||||
new Feature({
|
||||
geometry: new Point(fromLonLat(handlePositionFor(handle, value))),
|
||||
label: `${delta >= 0 ? '+' : ''}${delta.toFixed(2)} 米`,
|
||||
label: `${delta >= 0 ? '+' : ''}${delta.toFixed(2)} ${handle.value.unit === 'degree' ? '°' : '米'}`,
|
||||
clamped,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { fromLonLat, haversineMeters, offsetCoordinate, type Coordinate } from './meters';
|
||||
import { azimuthBetween, fromLonLat, haversineMeters, offsetCoordinate, type Coordinate } from './meters';
|
||||
import {
|
||||
anchorSnapshotFor,
|
||||
constraintValueFor,
|
||||
@@ -384,3 +384,35 @@ describe('complex transition length projection', () => {
|
||||
expect(projectHandleValue(handle, ...dragBy(handle.axisAzimuth, 100))).toBe(20);
|
||||
});
|
||||
});
|
||||
|
||||
describe('complex carriageway direction projection', () => {
|
||||
it('uses angular movement around the published inner-section center', () => {
|
||||
const center: Coordinate = [121.5, 31.2];
|
||||
const handle: EditHandle = {
|
||||
...makeHandle(
|
||||
'cluster-carriageway-direction',
|
||||
{
|
||||
type: 'cluster-carriageway',
|
||||
clusterId: 'cluster-1',
|
||||
carriagewayKey: 'entry-1',
|
||||
sourceNodeIds: ['node-1'],
|
||||
sourceRoadIds: ['road-1'],
|
||||
},
|
||||
5,
|
||||
-15,
|
||||
15,
|
||||
),
|
||||
position: offsetCoordinate(center, 35, 6),
|
||||
axisAzimuth: 35,
|
||||
interaction: { kind: 'rotation', center, radiusMeters: 6 },
|
||||
value: { current: 5, min: -15, max: 15, unit: 'degree' },
|
||||
};
|
||||
const pointer = fromLonLat(offsetCoordinate(center, 45, 40));
|
||||
expect(projectHandleValue(handle, fromLonLat(handle.position), pointer)).toBeCloseTo(15, 4);
|
||||
expect(constraintValueFor(handle, 15)).toEqual({ offsetDegrees: 15 });
|
||||
|
||||
const ghost = handlePositionFor(handle, 10);
|
||||
expect(azimuthBetween(center, ghost)).toBeCloseTo(40, 3);
|
||||
expect(haversineMeters(center, ghost)).toBeCloseTo(6, 3);
|
||||
});
|
||||
});
|
||||
@@ -7,11 +7,13 @@
|
||||
// writes a coordinate into a road polygon.
|
||||
|
||||
import {
|
||||
azimuthBetween,
|
||||
clamp,
|
||||
haversineMeters,
|
||||
offsetCoordinate,
|
||||
polylineLengthMeters,
|
||||
signedMetersAlongAxis,
|
||||
toLonLat,
|
||||
type Coordinate,
|
||||
} from './meters';
|
||||
import type {
|
||||
@@ -59,6 +61,13 @@ function outwardSign(handle: EditHandle): number {
|
||||
* declared. `from` / `to` are EPSG:3857 map coordinates.
|
||||
*/
|
||||
export function projectHandleValue(handle: EditHandle, from: Coordinate, to: Coordinate): number {
|
||||
if (handle.interaction?.kind === 'rotation') {
|
||||
const center = handle.interaction.center;
|
||||
const start = azimuthBetween(center, handle.position);
|
||||
const target = azimuthBetween(center, toLonLat(to));
|
||||
const delta = ((target - start + 540) % 360) - 180;
|
||||
return clamp(handle.value.current + delta, handle.value.min, handle.value.max);
|
||||
}
|
||||
const delta = signedMetersAlongAxis(from, to, handle.axisAzimuth) * outwardSign(handle);
|
||||
return clamp(handle.value.current + delta, handle.value.min, handle.value.max);
|
||||
}
|
||||
@@ -74,6 +83,10 @@ export function projectHandleValue(handle: EditHandle, from: Coordinate, to: Coo
|
||||
* from the clamped value instead pins the handle to the limit.
|
||||
*/
|
||||
export function handlePositionFor(handle: EditHandle, value: number): Coordinate {
|
||||
if (handle.interaction?.kind === 'rotation') {
|
||||
const delta = value - handle.value.current;
|
||||
return offsetCoordinate(handle.interaction.center, handle.axisAzimuth + delta, handle.interaction.radiusMeters);
|
||||
}
|
||||
const outward = outwardSign(handle) < 0 ? handle.axisAzimuth + 180 : handle.axisAzimuth;
|
||||
return offsetCoordinate(handle.position, outward, value - handle.value.current);
|
||||
}
|
||||
|
||||
@@ -94,6 +94,8 @@ export interface EditHandle {
|
||||
position: [number, number];
|
||||
/** Draggable direction, degrees clockwise from true north. */
|
||||
axisAzimuth: number;
|
||||
/** Optional non-linear pointer gesture declared by the server manifest. */
|
||||
interaction?: { kind: 'rotation'; center: [number, number]; radiusMeters: number };
|
||||
value: { current: number; min: number; max: number; unit: 'meter' | 'degree' };
|
||||
constraintId?: string;
|
||||
/** `native_id` of every derived feature this handle changes. */
|
||||
|
||||
Reference in new issue
Block a user