Click a hiking trail to see its name, color, network and distance
The Waymarked Trails raster overlay has no queryable features (just pixels), so this answers "what trail is this" with a one-off Overpass query on click instead: way(around:40m) finds candidate ways, then rel(bw) walks backward to their parent route=hiking relations. Overpass has permissive CORS, so this runs straight from the browser, no server proxy needed — verified against a real KST route in the Tatras. Route length isn't tagged directly, so it's summed from each member way's own geometry (measure.js's existing haversine lineLength, now exported and reused rather than duplicated). The colour tag is only ever used as a CSS background after matching a strict hex/word regex — untrusted free text otherwise.
This commit is contained in:
1 parent
9c45e7275c
commit
6f1577f957
3 files changed
+107
-4
No files matched your search
@@ -317,7 +317,9 @@ function haversine([lng1, lat1], [lng2, lat2]) {
|
||||
return 2 * EARTH_RADIUS_M * Math.asin(Math.sqrt(a));
|
||||
}
|
||||
|
||||
function lineLength(points) {
|
||||
// Exported — also used by hiking_trails.js to total up an OSM route
|
||||
// relation's member ways into one distance, same haversine-sum approach.
|
||||
export function lineLength(points) {
|
||||
let total = 0;
|
||||
for (let i = 1; i < points.length; i++) total += haversine(points[i - 1], points[i]);
|
||||
return total;
|
||||
@@ -347,7 +349,8 @@ function polygonArea(points) {
|
||||
return Math.abs((area * EARTH_RADIUS_M * EARTH_RADIUS_M) / 2);
|
||||
}
|
||||
|
||||
function formatDistance(meters) {
|
||||
// Exported — also used by hiking_trails.js's route-details popup.
|
||||
export function formatDistance(meters) {
|
||||
if (meters === 0) return "";
|
||||
return meters >= 1000 ? `${(meters / 1000).toFixed(2)} km` : `${Math.round(meters)} m`;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user