Trails by kind: the extract keeps hiking, foot, bicycle, mtb and ski routes, each with a kind (educational told apart by educational=yes, the green diagonal marking or the name); versioned so the next offline build redoes old files; the overlay picks kinds (hiking and educational by default), the elevation profile shows the ones for the activity
This commit is contained in:
1 parent
4bcd85f269
commit
b32f7d3bd3
7 files changed
+92
-15
No files matched your search
@@ -2202,6 +2202,12 @@ body.side-pinned:has(.basemap-panel:not([hidden]), .gpx-panel:not([hidden])) .pr
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.hiking-trail-kinds {
|
||||
margin-bottom: 8px;
|
||||
padding-bottom: 8px;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
|
||||
.hiking-trail-countries__item label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -86,25 +86,32 @@ function normalizedTrailColor(raw) {
|
||||
return /^#[0-9a-fA-F]{3,8}$/.test(trimmed) ? trimmed : DEFAULT_TRAIL_COLOR;
|
||||
}
|
||||
|
||||
// The offline trails currently drawn (every ticked country), for
|
||||
// Route kinds (Maptool::HikingTrails#kind; a file extracted before kinds
|
||||
// existed has none: hiking), the ones the map shows picked by the viewer.
|
||||
const KIND_LABELS = { hiking: "Hiking", educational: "Educational", bicycle: "Cycling", ski: "Ski" };
|
||||
const DEFAULT_KINDS = ["hiking", "educational"];
|
||||
const kindOf = (properties) => properties.kind || "hiking";
|
||||
|
||||
// The offline trails of every ticked country (all kinds), for
|
||||
// trailColorsAlong.
|
||||
let shownTrails = [];
|
||||
const TRAIL_MATCH_M = 20; // GPS/OSM offset a point may be off its trail
|
||||
const GRID_DEG = 0.001; // ~100 m cells
|
||||
|
||||
// For each {lon, lat} point, the colors of the drawn trails within
|
||||
// For each {lon, lat} point, the colors of the trails of `kinds` within
|
||||
// TRAIL_MATCH_M of it ([] off-trail), for the elevation profile's trail
|
||||
// band; null when no point is on a drawn trail. Only what the hiking
|
||||
// trails overlay shows, so ticking a country there is what turns it on.
|
||||
export function trailColorsAlong(points) {
|
||||
if (!shownTrails.length || !points.length) return null;
|
||||
// band; null when no point is on one. Only the countries the hiking
|
||||
// trails overlay has loaded, so ticking a country there turns it on.
|
||||
export function trailColorsAlong(points, kinds) {
|
||||
const trails = shownTrails.filter(({ properties }) => kinds.includes(kindOf(properties)));
|
||||
if (!trails.length || !points.length) return null;
|
||||
const lons = points.map((p) => p.lon);
|
||||
const lats = points.map((p) => p.lat);
|
||||
const [w, e] = [Math.min(...lons) - GRID_DEG, Math.max(...lons) + GRID_DEG];
|
||||
const [s, n] = [Math.min(...lats) - GRID_DEG, Math.max(...lats) + GRID_DEG];
|
||||
// Only segments near the points, bucketed by cell.
|
||||
const grid = new Map();
|
||||
for (const { geometry, properties } of shownTrails) {
|
||||
for (const { geometry, properties } of trails) {
|
||||
const lines = geometry.type === "LineString" ? [geometry.coordinates] : geometry.coordinates;
|
||||
for (const line of lines) {
|
||||
for (let i = 1; i < line.length; i++) {
|
||||
@@ -172,6 +179,10 @@ export class HikingTrailsControl {
|
||||
this._lanes = null; // the current LaneLayer, null when no country is shown
|
||||
this._bboxes = {}; // code -> [w, s, e, n]
|
||||
this._inView = false; // main checkbox, offline: the countries in view
|
||||
this._kinds = DEFAULT_KINDS;
|
||||
try {
|
||||
this._kinds = JSON.parse(localStorage.getItem("hikingTrailKinds")) || DEFAULT_KINDS;
|
||||
} catch {}
|
||||
|
||||
// Each country entered while the main checkbox is on joins in.
|
||||
// ponytail: a country left behind stays loaded until unticked.
|
||||
@@ -206,13 +217,15 @@ export class HikingTrailsControl {
|
||||
<button type="button" class="overlays-panel__name">Hiking trails</button>
|
||||
</div>
|
||||
<div class="overlays-panel__details" hidden>
|
||||
<ul class="hiking-trail-countries hiking-trail-kinds"></ul>
|
||||
<ul class="hiking-trail-countries"></ul>
|
||||
</div>
|
||||
`;
|
||||
this._checkbox = li.querySelector(".overlays-panel__toggle");
|
||||
this._nameButton = li.querySelector(".overlays-panel__name");
|
||||
this._details = li.querySelector(".overlays-panel__details");
|
||||
this._countryList = li.querySelector(".hiking-trail-countries");
|
||||
this._kindList = li.querySelector(".hiking-trail-kinds");
|
||||
this._countryList = li.querySelector(".hiking-trail-countries:not(.hiking-trail-kinds)");
|
||||
|
||||
this._checkbox.addEventListener("change", (event) => {
|
||||
if (this._offlineCountries.length) this._toggleInView(event.target.checked);
|
||||
@@ -244,6 +257,18 @@ export class HikingTrailsControl {
|
||||
this._checkbox.checked = false;
|
||||
this._checkbox.title = `Countries in view, from zoom ${LANES_MIN_ZOOM} — click the name to pick some`;
|
||||
|
||||
this._kindList.innerHTML = Object.entries(KIND_LABELS)
|
||||
.map(([kind, label]) => `<li class="hiking-trail-countries__item"><label><input type="checkbox" value="${kind}"${this._kinds.includes(kind) ? " checked" : ""}> ${label}</label></li>`)
|
||||
.join("");
|
||||
this._kindList.addEventListener("change", () => {
|
||||
this._kinds = [...this._kindList.querySelectorAll("input:checked")].map((input) => input.value);
|
||||
try {
|
||||
localStorage.setItem("hikingTrailKinds", JSON.stringify(this._kinds));
|
||||
} catch {}
|
||||
this._builtArea = null;
|
||||
if (this._selectedCountries.size > 0) this._rebuildLanes();
|
||||
});
|
||||
|
||||
this._countryList.innerHTML = countries
|
||||
.map(
|
||||
(code) => `
|
||||
@@ -354,7 +379,7 @@ export class HikingTrailsControl {
|
||||
const [dx, dy] = [view.getEast() - view.getWest(), view.getNorth() - view.getSouth()];
|
||||
const area = [view.getWest() - dx / 2, view.getSouth() - dy / 2, view.getEast() + dx / 2, view.getNorth() + dy / 2];
|
||||
this._builtArea = area;
|
||||
features = all.flatMap((feature) => clipToArea(feature, area));
|
||||
features = all.filter(({ properties }) => this._kinds.includes(kindOf(properties))).flatMap((feature) => clipToArea(feature, area));
|
||||
}
|
||||
let graph = null;
|
||||
if (features.length > 0) {
|
||||
|
||||
@@ -260,7 +260,11 @@ export class TrackProfilePanel {
|
||||
// track follows (several stacked where trails share the path), blank off
|
||||
// trail. Point i's colors span from it to the next point.
|
||||
_renderTrailBand() {
|
||||
const colors = trailColorsAlong(this._profile);
|
||||
// The trails the activity uses: a ride the cycling routes, skiing the
|
||||
// ski routes, on foot (or unknown) the hiking and educational trails.
|
||||
if (/driv|motor|car/i.test(this._activityType)) return null;
|
||||
const kinds = this._ride ? ["bicycle"] : /ski/i.test(this._activityType) ? ["ski"] : ["hiking", "educational"];
|
||||
const colors = trailColorsAlong(this._profile, kinds);
|
||||
if (!colors) return null;
|
||||
const HEIGHT = 10;
|
||||
const toX = (p) => this._fx(p) * VIEWBOX_WIDTH;
|
||||
|
||||
Reference in new issue
Block a user