Keep selected stop visible on mobile

This commit is contained in:
Edward Betts 2026-08-15 13:06:29 +01:00
parent 827435bd92
commit 98b5951cbb
2 changed files with 49 additions and 2 deletions

View file

@ -410,6 +410,18 @@ function clearHoveredStop() {
hoveredMarkerHalo = null;
}
/** Centre a selected stop in the portion of the map not covered by the mobile sheet. */
function centreSelectedStop(stop) {
const zoom = Math.max(map.getZoom(), 17);
let verticalOffset = 0;
if (isMobile() && byId('sidebar').classList.contains('panel-open')) {
verticalOffset = Math.min(map.getSize().y, byId('sidebar').getBoundingClientRect().height) / 2;
}
const stopPoint = map.project(L.latLng(stop.lat, stop.lon), zoom);
const adjustedCenter = map.unproject(stopPoint.add(L.point(0, verticalOffset)), zoom);
map.setView(adjustedCenter, zoom);
}
function osmUrl(stop, edit = false) {
return `https://www.openstreetmap.org/${edit ? 'edit?' : ''}${edit ? `${stop.type}=${stop.id}` : `${stop.type}/${stop.id}`}`;
}
@ -462,15 +474,15 @@ async function selectStop(stop, updateUrl = true) {
show('atco-missing', !stop.atco_code);
byId('copy-status').textContent = '';
renderTags(stop.tags);
if (isMobile()) setPanel(true);
moveMap(
() => map.setView([stop.lat, stop.lon], Math.max(map.getZoom(), 17)),
() => centreSelectedStop(stop),
() => {
if (selectedStop && selectedStop.type === stop.type && selectedStop.id === stop.id) {
loadVisibleMapStops();
}
}
);
if (isMobile()) setPanel(true);
byId('route-list').replaceChildren();
show('route-loading');