feat: complete carriageway direction interaction

This commit is contained in:
que01 committed 2026-09-11 09:51:02 +08:00
1 parent a5089220b5
commit 067c0e370d
10 files changed
+251 -41

No files matched your search

+13
View File
@@ -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);
}