Compass and a north-up rotation lock (on by default, remembered): a two-finger gesture on a tablet rotated the map far too easily
This commit is contained in:
1 parent
4265421457
commit
6faabca93d
4 files changed
+57
-6
No files matched your search
@@ -1756,6 +1756,11 @@ body.side-pinned:has(.basemap-panel:not([hidden]), .gpx-panel:not([hidden])) .pr
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.rotation-lock-ctrl button svg {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
}
|
||||
|
||||
.pitch-toggle-ctrl__button.active {
|
||||
background: #dbe9ff;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ import {
|
||||
mdiFolderPlusOutline,
|
||||
mdiLayersOutline,
|
||||
mdiLayersPlus,
|
||||
mdiLock,
|
||||
mdiLockOpenVariantOutline,
|
||||
mdiMagnify,
|
||||
mdiMapMarkerOutline,
|
||||
mdiMapMarkerPath,
|
||||
@@ -63,6 +65,8 @@ export const SAVED_POINT_ICON = mdi(mdiMapMarkerStarOutline);
|
||||
export const REVERSE_ICON = mdi(mdiSwapVertical);
|
||||
export const CLEAR_ICON = mdi(mdiDeleteSweepOutline);
|
||||
export const SAVE_ICON = mdi(mdiContentSaveOutline);
|
||||
export const LOCK_ICON = mdi(mdiLock);
|
||||
export const UNLOCK_ICON = mdi(mdiLockOpenVariantOutline);
|
||||
export const TRACK_ICON = GPX_ICON;
|
||||
|
||||
// A rounded-square badge — used as the map marker for individual waypoints,
|
||||
|
||||
+46
-6
@@ -17,7 +17,7 @@ import { LocateControl } from "/js/locate.js";
|
||||
import { SearchControl } from "/js/search.js";
|
||||
import { OfflineDataControl } from "/js/offline_data.js";
|
||||
import { RoutePanelControl } from "/js/route.js";
|
||||
import { LAYERS_ICON, WAYPOINT_ICON, SUNRISE_ICON, SUNSET_ICON, PENDING_ICON } from "/js/icons.js";
|
||||
import { LAYERS_ICON, WAYPOINT_ICON, SUNRISE_ICON, SUNSET_ICON, PENDING_ICON, LOCK_ICON, UNLOCK_ICON } from "/js/icons.js";
|
||||
import { formatCoords, formatSunInfo, sunChartHtml } from "/js/sun.js";
|
||||
import { notifySidePanelOpen, onlyOneSidePanelOpen, setupSidePanelModes } from "/js/panels.js";
|
||||
import { isLoggedIn } from "/js/auth.js";
|
||||
@@ -359,8 +359,7 @@ class ZoomLevelControl {
|
||||
}
|
||||
|
||||
// Tilts the camera between a flat top-down view and a fixed 3D-perspective
|
||||
// pitch — bearing stays untouched (this map never rotates, see the
|
||||
// NavigationControl comment below), so this is purely "look at it from an
|
||||
// pitch — bearing stays untouched, so this is purely "look at it from an
|
||||
// angle", not a rotate/compass control. Independent of the "Terrain
|
||||
// shading" overlay toggle (overlays.js) — that adds a raster-dem hillshade/
|
||||
// color-relief layer, this just moves the camera; combining both gives a
|
||||
@@ -417,6 +416,47 @@ class PitchToggleControl {
|
||||
}
|
||||
}
|
||||
|
||||
// Locks the map north-up (on by default): a two-finger gesture on a
|
||||
// tablet rotates it far too easily. Unlocked, it rotates like any map and
|
||||
// NavigationControl's compass turns it back north.
|
||||
class RotationLockControl {
|
||||
onAdd(map) {
|
||||
this._map = map;
|
||||
this._container = document.createElement("div");
|
||||
this._container.className = "maplibregl-ctrl maplibregl-ctrl-group rotation-lock-ctrl";
|
||||
this._button = document.createElement("button");
|
||||
this._button.type = "button";
|
||||
this._button.addEventListener("click", () => this._set(!this._locked));
|
||||
this._container.appendChild(this._button);
|
||||
let stored = null;
|
||||
try {
|
||||
stored = localStorage.getItem("rotationLocked");
|
||||
} catch {}
|
||||
this._set(stored !== "false");
|
||||
return this._container;
|
||||
}
|
||||
|
||||
onRemove() {
|
||||
this._container.remove();
|
||||
}
|
||||
|
||||
_set(locked) {
|
||||
this._locked = locked;
|
||||
const action = locked ? "disableRotation" : "enableRotation";
|
||||
this._map.touchZoomRotate[action]();
|
||||
this._map.keyboard[action]();
|
||||
this._map.dragRotate[locked ? "disable" : "enable"]();
|
||||
if (locked && this._map.getBearing() !== 0) this._map.easeTo({ bearing: 0, duration: 300 });
|
||||
this._button.innerHTML = locked ? LOCK_ICON : UNLOCK_ICON;
|
||||
this._button.title = locked ? "Rotation locked (north up), click to allow rotating" : "Rotation allowed, click to lock north up";
|
||||
this._button.setAttribute("aria-label", this._button.title);
|
||||
this._button.classList.toggle("active", locked);
|
||||
try {
|
||||
localStorage.setItem("rotationLocked", String(locked));
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
|
||||
const map = new MaplibreMap({
|
||||
container: "map",
|
||||
style: ONLINE_STYLE,
|
||||
@@ -450,9 +490,9 @@ const SLOVAKIA_BOUNDS = [
|
||||
const searchControl = new SearchControl();
|
||||
map.addControl(searchControl, "top-left");
|
||||
map.addControl(new HomeButton({ bounds: SLOVAKIA_BOUNDS }), "top-left");
|
||||
// showCompass: false — this map never rotates, so a bearing-reset button
|
||||
// (NavigationControl's default third button) would just be dead weight.
|
||||
map.addControl(new NavigationControl({ showCompass: false }), "top-left");
|
||||
// The compass shows the bearing; a click turns the map back north.
|
||||
map.addControl(new NavigationControl({ visualizePitch: false }), "top-left");
|
||||
map.addControl(new RotationLockControl(), "top-left");
|
||||
map.addControl(new ZoomLevelControl(), "top-left");
|
||||
const pitchToggle = new PitchToggleControl();
|
||||
map.addControl(pitchToggle, "top-left");
|
||||
|
||||
Vendored
+2
@@ -9,6 +9,8 @@ export const mdiDeleteSweepOutline = "M15,16H19V18H15V16M15,8H22V10H15V8M15,12H2
|
||||
export const mdiFolderPlusOutline = "M13 19C13 19.34 13.04 19.67 13.09 20H4C2.9 20 2 19.11 2 18V6C2 4.89 2.89 4 4 4H10L12 6H20C21.1 6 22 6.89 22 8V13.81C21.39 13.46 20.72 13.22 20 13.09V8H4V18H13.09C13.04 18.33 13 18.66 13 19M20 18V15H18V18H15V20H18V23H20V20H23V18H20Z";
|
||||
export const mdiLayersOutline = "M12,18.54L19.37,12.8L21,14.07L12,21.07L3,14.07L4.62,12.81L12,18.54M12,16L3,9L12,2L21,9L12,16M12,4.53L6.26,9L12,13.47L17.74,9L12,4.53Z";
|
||||
export const mdiLayersPlus = "M17,14H19V17H22V19H19V22H17V19H14V17H17V14M11,16L2,9L11,2L20,9L11,16M11,18.54L12,17.75V18C12,18.71 12.12,19.39 12.35,20L11,21.07L2,14.07L3.62,12.81L11,18.54Z";
|
||||
export const mdiLock = "M12,17A2,2 0 0,0 14,15C14,13.89 13.1,13 12,13A2,2 0 0,0 10,15A2,2 0 0,0 12,17M18,8A2,2 0 0,1 20,10V20A2,2 0 0,1 18,22H6A2,2 0 0,1 4,20V10C4,8.89 4.9,8 6,8H7V6A5,5 0 0,1 12,1A5,5 0 0,1 17,6V8H18M12,3A3,3 0 0,0 9,6V8H15V6A3,3 0 0,0 12,3Z";
|
||||
export const mdiLockOpenVariantOutline = "M10 13C11.1 13 12 13.89 12 15C12 16.11 11.11 17 10 17S8 16.11 8 15 8.9 13 10 13M18 1C15.24 1 13 3.24 13 6V8H4C2.9 8 2 8.9 2 10V20C2 21.1 2.9 22 4 22H16C17.1 22 18 21.1 18 20V10C18 8.9 17.1 8 16 8H15V6C15 4.34 16.34 3 18 3S21 4.34 21 6V8H23V6C23 3.24 20.76 1 18 1M16 10V20H4V10H16Z";
|
||||
export const mdiMagnify = "M9.5,3A6.5,6.5 0 0,1 16,9.5C16,11.11 15.41,12.59 14.44,13.73L14.71,14H15.5L20.5,19L19,20.5L14,15.5V14.71L13.73,14.44C12.59,15.41 11.11,16 9.5,16A6.5,6.5 0 0,1 3,9.5A6.5,6.5 0 0,1 9.5,3M9.5,5C7,5 5,7 5,9.5C5,12 7,14 9.5,14C12,14 14,12 14,9.5C14,7 12,5 9.5,5Z";
|
||||
export const mdiMapMarkerOutline = "M12,6.5A2.5,2.5 0 0,1 14.5,9A2.5,2.5 0 0,1 12,11.5A2.5,2.5 0 0,1 9.5,9A2.5,2.5 0 0,1 12,6.5M12,2A7,7 0 0,1 19,9C19,14.25 12,22 12,22C12,22 5,14.25 5,9A7,7 0 0,1 12,2M12,4A5,5 0 0,0 7,9C7,10 7,12 12,18.71C17,12 17,10 17,9A5,5 0 0,0 12,4Z";
|
||||
export const mdiMapMarkerPath = "M18,15A3,3 0 0,1 21,18A3,3 0 0,1 18,21C16.69,21 15.58,20.17 15.17,19H14V17H15.17C15.58,15.83 16.69,15 18,15M18,17A1,1 0 0,0 17,18A1,1 0 0,0 18,19A1,1 0 0,0 19,18A1,1 0 0,0 18,17M18,8A1.43,1.43 0 0,0 19.43,6.57C19.43,5.78 18.79,5.14 18,5.14C17.21,5.14 16.57,5.78 16.57,6.57A1.43,1.43 0 0,0 18,8M18,2.57A4,4 0 0,1 22,6.57C22,9.56 18,14 18,14C18,14 14,9.56 14,6.57A4,4 0 0,1 18,2.57M8.83,17H10V19H8.83C8.42,20.17 7.31,21 6,21A3,3 0 0,1 3,18C3,16.69 3.83,15.58 5,15.17V14H7V15.17C7.85,15.47 8.53,16.15 8.83,17M6,17A1,1 0 0,0 5,18A1,1 0 0,0 6,19A1,1 0 0,0 7,18A1,1 0 0,0 6,17M6,3A3,3 0 0,1 9,6C9,7.31 8.17,8.42 7,8.83V10H5V8.83C3.83,8.42 3,7.31 3,6A3,3 0 0,1 6,3M6,5A1,1 0 0,0 5,6A1,1 0 0,0 6,7A1,1 0 0,0 7,6A1,1 0 0,0 6,5M11,19V17H13V19H11M7,13H5V11H7V13Z";
|
||||
|
||||
Reference in new issue
Block a user