Splits: descent column and a header row; Tracks & Points: clicking a name shows the item and zooms to it
This commit is contained in:
1 parent
07e22a87af
commit
e3f08f2267
3 files changed
+33
-6
No files matched your search
+19
-1
@@ -1,4 +1,4 @@
|
||||
import { Popup } from "/vendor/maplibre-gl/maplibre-gl.mjs";
|
||||
import { Popup, LngLatBounds } from "/vendor/maplibre-gl/maplibre-gl.mjs";
|
||||
import {
|
||||
GPX_ICON,
|
||||
NEW_FOLDER_ICON,
|
||||
@@ -328,6 +328,16 @@ export class GpxPanelControl {
|
||||
label.appendChild(checkbox);
|
||||
(file.kinds || []).forEach((kind) => label.appendChild(this._kindIcon(kind)));
|
||||
label.appendChild(name);
|
||||
// The name zooms to it (showing it first if needed); the checkbox
|
||||
// alone shows/hides.
|
||||
name.addEventListener("click", async (event) => {
|
||||
event.preventDefault();
|
||||
if (!checkbox.checked) {
|
||||
checkbox.checked = true;
|
||||
await this._toggleFile(file.path, true, checkbox);
|
||||
}
|
||||
if (checkbox.checked) this._zoomTo(file.path);
|
||||
});
|
||||
row.appendChild(label);
|
||||
// Delete/download require login (app.rb); shown only once logged in
|
||||
// rather than shown-but-failing-on-click.
|
||||
@@ -544,6 +554,14 @@ export class GpxPanelControl {
|
||||
}
|
||||
}
|
||||
|
||||
async _zoomTo(path) {
|
||||
const sources = [linesSourceId(path), pointsSourceId(path)].map((id) => this._map.getSource(id)).filter(Boolean);
|
||||
const bounds = new LngLatBounds();
|
||||
const extend = (c) => (typeof c[0] === "number" ? bounds.extend([c[0], c[1]]) : c.forEach(extend));
|
||||
for (const source of sources) (await source.getData()).features.forEach((f) => f.geometry && extend(f.geometry.coordinates));
|
||||
if (!bounds.isEmpty()) this._map.fitBounds(bounds, { padding: 60, maxZoom: 15 });
|
||||
}
|
||||
|
||||
// Fetches the file's GeoJSON itself (rather than handing maplibre a URL
|
||||
// to fetch internally) so a parse failure — a real GPX a device/app
|
||||
// wrote in some way REXML doesn't like, say — surfaces as an alert
|
||||
|
||||
Reference in new issue
Block a user