feat: add native road direction arrows
This commit is contained in:
@@ -358,6 +358,18 @@ function addMeters(center, axis, axisDistance, right, rightDistance, meters) {
|
||||
];
|
||||
}
|
||||
|
||||
function arrowRingsAt(maneuver, center, axis, manifest = loadManifest()) {
|
||||
const normalized = normalizeManeuver(maneuver);
|
||||
if (!supportedAssets(manifest).has(normalized) || !Array.isArray(center) || !Array.isArray(axis)) return [];
|
||||
const meters = metersForLat(center[1]);
|
||||
const length = Math.hypot(axis[0], axis[1]);
|
||||
if (!Number.isFinite(length) || length < 0.001) return [];
|
||||
const forward = [axis[0] / length, axis[1] / length];
|
||||
const right = [forward[1], -forward[0]];
|
||||
return templateFor(normalized, manifest).map((template) => template.map(([rightMeters, forwardMeters]) =>
|
||||
addMeters(center, forward, forwardMeters, right, rightMeters, meters)));
|
||||
}
|
||||
|
||||
function templateFor(assetId, manifest = loadManifest()) {
|
||||
const asset = supportedAssets(manifest).get(assetId);
|
||||
if (!asset) throw new Error(`Unsupported or untested turn-lane asset: ${assetId}`);
|
||||
@@ -487,4 +499,4 @@ function strokePolygon(points, width) {
|
||||
return [...left, ...right, left[0]];
|
||||
}
|
||||
|
||||
module.exports = { buildCustomTurnLaneArrows, loadManifest, normalizeManeuver, supportedAssets, templateFor };
|
||||
module.exports = { arrowRingsAt, buildCustomTurnLaneArrows, loadManifest, normalizeManeuver, supportedAssets, templateFor };
|
||||
|
||||
Reference in New Issue
Block a user