Material Design Icons replace the hand-drawn UI icons (only the used ones vendored, Renovate-tracked); route panel: saved-point picker, buttons on two rows with icons
This commit is contained in:
1 parent
a6d63e242b
commit
4c704045c5
10 files changed
+251
-206
No files matched your search
+48
-1
@@ -1,5 +1,5 @@
|
||||
import { Marker } from "/vendor/maplibre-gl/maplibre-gl.mjs";
|
||||
import { ROUTE_ICON } from "/js/icons.js";
|
||||
import { ROUTE_ICON, POSITION_ICON, SAVED_POINT_ICON, REVERSE_ICON, CLEAR_ICON, SAVE_ICON } from "/js/icons.js";
|
||||
import { notifySidePanelOpen, onlyOneSidePanelOpen, notifyGpxStoreChanged, onRoutePoint, onRouteEdit } from "/js/panels.js";
|
||||
import { isLoggedIn } from "/js/auth.js";
|
||||
import { wirePreview } from "/js/preview.js";
|
||||
@@ -76,6 +76,9 @@ export class RoutePanelControl {
|
||||
});
|
||||
this._panel.querySelector('[data-action="clear"]').addEventListener("click", () => this._clear());
|
||||
this._panel.querySelector('[data-action="position"]').addEventListener("click", () => this._addPosition());
|
||||
const icons = { position: POSITION_ICON, "saved-point": SAVED_POINT_ICON, reverse: REVERSE_ICON, clear: CLEAR_ICON, save: SAVE_ICON };
|
||||
for (const [action, icon] of Object.entries(icons)) this._panel.querySelector(`[data-action="${action}"]`).insertAdjacentHTML("afterbegin", icon);
|
||||
this._setupSavedPoints();
|
||||
this._editingNote = this._panel.querySelector(".route-panel__editing");
|
||||
this._saveButton.addEventListener("click", () => this._save());
|
||||
this._profileButton = this._panel.querySelector(".route-panel__profile");
|
||||
@@ -402,6 +405,50 @@ export class RoutePanelControl {
|
||||
return features.find((f) => f.geometry.type === "LineString")?.properties.id;
|
||||
}
|
||||
|
||||
// "Saved point": a search over the library's points (GET /api/search,
|
||||
// the "layers" source, nearest the map center first); a pick adds it.
|
||||
_setupSavedPoints() {
|
||||
const box = this._panel.querySelector(".route-panel__saved");
|
||||
const input = box.querySelector("input");
|
||||
const list = box.querySelector("ul");
|
||||
let timer = null;
|
||||
let request = 0;
|
||||
this._panel.querySelector('[data-action="saved-point"]').addEventListener("click", () => {
|
||||
box.hidden = !box.hidden;
|
||||
if (!box.hidden) input.focus();
|
||||
});
|
||||
input.addEventListener("input", () => {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(async () => {
|
||||
const mine = ++request;
|
||||
const center = this._map.getCenter();
|
||||
const url = new URL("/api/search", window.location.origin);
|
||||
url.search = new URLSearchParams({ q: input.value, sources: "layers", lat: center.lat, lng: center.lng });
|
||||
let results = [];
|
||||
try {
|
||||
if (input.value.trim()) results = (await (await fetch(url)).json()).results;
|
||||
} catch {}
|
||||
if (mine !== request) return;
|
||||
const points = results.filter(({ bbox }) => bbox && bbox[0] === bbox[2] && bbox[1] === bbox[3]);
|
||||
list.replaceChildren(
|
||||
...points.map(({ name, bbox, source_label: folder }) => {
|
||||
const item = document.createElement("li");
|
||||
const button = Object.assign(document.createElement("button"), { type: "button", textContent: name, title: folder });
|
||||
button.addEventListener("click", () => {
|
||||
this._addPoint(bbox.slice(0, 2), name);
|
||||
box.hidden = true;
|
||||
input.value = "";
|
||||
list.replaceChildren();
|
||||
});
|
||||
item.appendChild(button);
|
||||
return item;
|
||||
}),
|
||||
);
|
||||
if (!points.length && input.value.trim()) list.replaceChildren(Object.assign(document.createElement("li"), { textContent: "No saved points found." }));
|
||||
}, 250);
|
||||
});
|
||||
}
|
||||
|
||||
// Where the route needs a vignette or pays tolls, country by country.
|
||||
_showCountries(countries) {
|
||||
const rows = (countries || []).flatMap(({ code, motorway_km: motorway, toll_km: toll }) => {
|
||||
|
||||
Reference in new issue
Block a user