Night mode (auto after sunset / on / off, one invert+dim filter for now), tracker drawn as a top-down vehicle rotated by its GNSS course with a heading-up tilted Navigate mode, side panels float over the map on phone width instead of squeezing it
This commit is contained in:
1 parent
0e5f79f8e4
commit
9148c9a411
5 files changed
+189
-17
No files matched your search
@@ -552,6 +552,30 @@ body.side-pinned:has(.basemap-panel:not([hidden]), .gpx-panel:not([hidden])) .pr
|
||||
left: calc(52px + min(300px, 90vw));
|
||||
}
|
||||
|
||||
/* Phone portrait: a pinned 300px panel left the map a sliver, so there it
|
||||
always floats over the map instead (closed by its × button). */
|
||||
@media (max-width: 640px) {
|
||||
body.side-pinned:has(.basemap-panel:not([hidden]), .gpx-panel:not([hidden])) #map {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
body.side-pinned:has(.basemap-panel:not([hidden]), .gpx-panel:not([hidden])) .profile-panel {
|
||||
left: 52px;
|
||||
}
|
||||
|
||||
/* body: outranks .gpx-panel's own rule further down */
|
||||
body .basemap-panel,
|
||||
body .gpx-panel {
|
||||
width: auto;
|
||||
right: 0;
|
||||
max-width: none;
|
||||
}
|
||||
|
||||
.side-panel-pin {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.side-panel-pin {
|
||||
margin-left: auto;
|
||||
margin-right: 4px;
|
||||
@@ -3092,3 +3116,47 @@ body.side-pinned:has(.basemap-panel:not([hidden]), .gpx-panel:not([hidden])) .pr
|
||||
font-weight: normal;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
/* Big enough to hit while driving. */
|
||||
.live-tracker-card__nav {
|
||||
display: block;
|
||||
width: 100%;
|
||||
min-height: 44px;
|
||||
margin-top: 6px;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
background: var(--accent);
|
||||
color: #fff;
|
||||
font: inherit;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.live-tracker-card__nav.active {
|
||||
background: #c0392b;
|
||||
}
|
||||
|
||||
/* Night mode (map.js): the whole page inverted and dimmed, map included,
|
||||
the already-black topbar and photos inverted back.
|
||||
ponytail: one filter instead of a dark map style + dark copy of this
|
||||
stylesheet; colors come out approximate (hue kept, lightness flipped) —
|
||||
a real dark Park Tiles palette in map_themes.js if that's not enough. */
|
||||
html.night {
|
||||
filter: invert(1) hue-rotate(180deg) brightness(0.75);
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
html.night .topbar,
|
||||
html.night img {
|
||||
filter: invert(1) hue-rotate(180deg);
|
||||
}
|
||||
|
||||
.topbar__night {
|
||||
border: none;
|
||||
background: none;
|
||||
color: #bbb;
|
||||
font-size: 16px;
|
||||
padding: 4px 6px;
|
||||
cursor: pointer;
|
||||
}
|
||||
+88
-16
@@ -104,7 +104,25 @@ const poller = {
|
||||
|
||||
const TRACKER_SOURCE = "live-tracker";
|
||||
const TRAIL_SOURCE = "live-tracker-trail";
|
||||
const TRACKER_LAYERS = ["live-tracker-trail", "live-tracker-badge", "live-tracker-icon", "live-tracker-label"];
|
||||
const TRACKER_LAYERS = ["live-tracker-trail", "live-tracker-badge", "live-tracker-icon", "live-tracker-vehicle", "live-tracker-label"];
|
||||
// Below this speed the GNSS course is noise: the vehicle keeps its last one.
|
||||
const MOVING_KMH = 3;
|
||||
const NAV_PITCH = 60;
|
||||
const NAV_ZOOM = 16;
|
||||
|
||||
// Top-down shapes pointing north, rotated on the map by the course (like
|
||||
// OpenTrafficMap's vehicles): picked from the tracker's icon.
|
||||
const VEHICLE_SHAPES = {
|
||||
car: `<svg viewBox="0 0 24 24"><rect x="6" y="2" width="12" height="20" rx="4" fill="currentColor" stroke="#fff" stroke-width="1.5"/><path d="M8 8.5h8l-1-2.5H9zM8.5 17h7l.5 2h-8z" fill="#fff" opacity=".85"/></svg>`,
|
||||
moto: `<svg viewBox="0 0 24 24"><rect x="10" y="1.5" width="4" height="5" rx="2" fill="currentColor" stroke="#fff"/><rect x="10" y="17.5" width="4" height="5" rx="2" fill="currentColor" stroke="#fff"/><path d="M6 8h12M9 8l1.5 9h3L15 8" fill="currentColor" stroke="#fff" stroke-width="1.5" stroke-linecap="round"/></svg>`,
|
||||
bike: `<svg viewBox="0 0 24 24"><path d="M12 2v20M7 7h10" stroke="currentColor" stroke-width="3" stroke-linecap="round"/><path d="M12 2v20M7 7h10" stroke="#fff" stroke-width=".8" stroke-linecap="round"/></svg>`,
|
||||
};
|
||||
|
||||
function vehicleShape(icon) {
|
||||
if (/moto/.test(icon)) return "moto";
|
||||
if (/bicycle|cycl|vtt|bike/.test(icon)) return "bike";
|
||||
return "car";
|
||||
}
|
||||
|
||||
export class TrackerControl {
|
||||
constructor(map) {
|
||||
@@ -150,6 +168,7 @@ export class TrackerControl {
|
||||
|
||||
this._status.addEventListener("click", (event) => {
|
||||
if (event.target.closest(".live-panel__show")) this._showTracker();
|
||||
if (event.target.closest(".live-panel__follow")) this._setFollow(true);
|
||||
});
|
||||
if (!isLoggedIn()) {
|
||||
this._toggle.disabled = true;
|
||||
@@ -202,6 +221,7 @@ export class TrackerControl {
|
||||
}
|
||||
|
||||
_disable() {
|
||||
this._setFollow(false);
|
||||
this._enabled = false;
|
||||
poller.unsubscribe(this._onData);
|
||||
this._status.hidden = true;
|
||||
@@ -210,6 +230,28 @@ export class TrackerControl {
|
||||
removeLayers(this._map, TRACKER_LAYERS, [TRACKER_SOURCE, TRAIL_SOURCE]);
|
||||
}
|
||||
|
||||
// Navigation mode: the map follows the tracker heading-up, tilted, with
|
||||
// the vehicle in the lower third so more road ahead shows.
|
||||
_setFollow(on) {
|
||||
if (!this._follow === !on) return;
|
||||
this._follow = on;
|
||||
this._renderCard();
|
||||
const t = this._data?.tracker;
|
||||
if (on && t) this._navigate(t);
|
||||
if (!on) this._map.easeTo({ padding: { top: 0, bottom: 0, left: 0, right: 0 }, duration: 300 });
|
||||
}
|
||||
|
||||
_navigate(t) {
|
||||
this._map.easeTo({
|
||||
center: [t.longitude, t.latitude],
|
||||
bearing: this._course ?? this._map.getBearing(),
|
||||
pitch: NAV_PITCH,
|
||||
zoom: Math.max(this._map.getZoom(), NAV_ZOOM),
|
||||
padding: { top: this._map.getContainer().clientHeight * 0.4, bottom: 0, left: 0, right: 0 },
|
||||
duration: Math.min(POLL_INTERVAL_MS, 1000),
|
||||
});
|
||||
}
|
||||
|
||||
_showTracker() {
|
||||
const t = this._data?.tracker;
|
||||
if (t) this._map.flyTo({ center: [t.longitude, t.latitude], zoom: Math.max(this._map.getZoom(), 14) });
|
||||
@@ -227,18 +269,36 @@ export class TrackerControl {
|
||||
layout: { "line-cap": "round", "line-join": "round" },
|
||||
paint: { "line-color": ["get", "color"], "line-width": 3, "line-opacity": 0.75 },
|
||||
});
|
||||
// Badge + glyph until a course is known, then the rotated vehicle.
|
||||
const still = ["!", ["has", "course"]];
|
||||
this._map.addLayer({
|
||||
id: "live-tracker-badge",
|
||||
type: "symbol",
|
||||
source: TRACKER_SOURCE,
|
||||
filter: still,
|
||||
layout: { "icon-image": ["get", "badge"], "icon-size": 0.7, "icon-allow-overlap": true },
|
||||
});
|
||||
this._map.addLayer({
|
||||
id: "live-tracker-icon",
|
||||
type: "symbol",
|
||||
source: TRACKER_SOURCE,
|
||||
filter: still,
|
||||
layout: { "icon-image": ["get", "glyph"], "icon-size": 0.4, "icon-allow-overlap": true },
|
||||
});
|
||||
this._map.addLayer({
|
||||
id: "live-tracker-vehicle",
|
||||
type: "symbol",
|
||||
source: TRACKER_SOURCE,
|
||||
filter: ["has", "course"],
|
||||
layout: {
|
||||
"icon-image": ["get", "vehicle"],
|
||||
"icon-size": 0.9,
|
||||
"icon-rotate": ["get", "course"],
|
||||
"icon-rotation-alignment": "map",
|
||||
"icon-pitch-alignment": "map",
|
||||
"icon-allow-overlap": true,
|
||||
},
|
||||
});
|
||||
this._map.addLayer({
|
||||
id: "live-tracker-label",
|
||||
type: "symbol",
|
||||
@@ -248,9 +308,13 @@ export class TrackerControl {
|
||||
});
|
||||
if (!this._interactive) {
|
||||
this._interactive = true;
|
||||
this._map.on("click", "live-tracker-badge", (event) => this._popup(event.lngLat));
|
||||
this._map.on("mouseenter", "live-tracker-badge", () => (this._map.getCanvas().style.cursor = "pointer"));
|
||||
this._map.on("mouseleave", "live-tracker-badge", () => (this._map.getCanvas().style.cursor = ""));
|
||||
for (const layer of ["live-tracker-badge", "live-tracker-vehicle"]) {
|
||||
this._map.on("click", layer, (event) => this._popup(event.lngLat));
|
||||
this._map.on("mouseenter", layer, () => (this._map.getCanvas().style.cursor = "pointer"));
|
||||
this._map.on("mouseleave", layer, () => (this._map.getCanvas().style.cursor = ""));
|
||||
}
|
||||
// Panning by hand ends navigation mode (zoom/pinch keeps it).
|
||||
this._map.on("dragstart", () => this._setFollow(false));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,7 +332,13 @@ export class TrackerControl {
|
||||
const image = await svgToImageData(svg.replace(/currentColor/g, "#fff"), ICON_IMAGE_SIZE);
|
||||
if (!this._map.hasImage(glyph)) this._map.addImage(glyph, image);
|
||||
}
|
||||
return { badge, glyph };
|
||||
const shape = vehicleShape(icon);
|
||||
const vehicle = `live-vehicle-${shape}-${color}`;
|
||||
if (!this._map.hasImage(vehicle)) {
|
||||
const image = await svgToImageData(VEHICLE_SHAPES[shape].replace(/currentColor/g, color), ICON_IMAGE_SIZE);
|
||||
if (!this._map.hasImage(vehicle)) this._map.addImage(vehicle, image);
|
||||
}
|
||||
return { badge, glyph, vehicle };
|
||||
}
|
||||
|
||||
async _render(data) {
|
||||
@@ -286,22 +356,20 @@ export class TrackerControl {
|
||||
}
|
||||
const t = data.tracker;
|
||||
this._status.innerHTML = t
|
||||
? `${escapeHtml(settings.name)} ${ago(t.age)} · <button type="button" class="live-panel__show">show</button>`
|
||||
? `${escapeHtml(settings.name)} ${ago(t.age)} · <button type="button" class="live-panel__show">show</button> · <button type="button" class="live-panel__follow">navigate</button>`
|
||||
: `No ${escapeHtml(settings.name)} position yet`;
|
||||
if (t?.course != null && (t.speed ?? MOVING_KMH) >= MOVING_KMH) this._course = t.course;
|
||||
this._renderCard();
|
||||
if (!t) return;
|
||||
|
||||
const { badge, glyph } = await this._ensureImages(settings.color, settings.icon);
|
||||
const { badge, glyph, vehicle } = await this._ensureImages(settings.color, settings.icon);
|
||||
const properties = { badge, glyph, vehicle, label: `${settings.name} · ${ago(t.age)}` };
|
||||
if (this._course != null) properties.course = this._course;
|
||||
this._map.getSource(TRACKER_SOURCE)?.setData({
|
||||
type: "FeatureCollection",
|
||||
features: [
|
||||
{
|
||||
type: "Feature",
|
||||
geometry: { type: "Point", coordinates: [t.longitude, t.latitude] },
|
||||
properties: { badge, glyph, label: `${settings.name} · ${ago(t.age)}` },
|
||||
},
|
||||
],
|
||||
features: [{ type: "Feature", geometry: { type: "Point", coordinates: [t.longitude, t.latitude] }, properties }],
|
||||
});
|
||||
if (this._follow) this._navigate(t);
|
||||
const trail = [...(t.trail || []), [t.longitude, t.latitude]];
|
||||
this._map.getSource(TRAIL_SOURCE)?.setData({
|
||||
type: "FeatureCollection",
|
||||
@@ -337,7 +405,10 @@ export class TrackerControl {
|
||||
if (!this._card) {
|
||||
this._card = document.createElement("div");
|
||||
this._card.className = "live-tracker-card";
|
||||
this._card.addEventListener("click", () => this._showTracker());
|
||||
this._card.addEventListener("click", (event) => {
|
||||
if (event.target.closest(".live-tracker-card__nav")) this._setFollow(!this._follow);
|
||||
else this._showTracker();
|
||||
});
|
||||
this._map.getContainer().appendChild(this._card);
|
||||
}
|
||||
this._card.style.opacity = this._cardOpacity.value;
|
||||
@@ -352,7 +423,8 @@ export class TrackerControl {
|
||||
["Updated", ago(t.age)],
|
||||
].filter(Boolean);
|
||||
this._card.innerHTML = `<div class="live-tracker-card__title"><span class="live-tracker-card__icon" style="background:${escapeHtml(s.color)}">${POI_ICONS[s.icon] || NPS_SYMBOLS.automobiles}</span>${escapeHtml(s.name)}</div>
|
||||
<table>${rows.map(([k, v]) => `<tr><th>${k}</th><td>${escapeHtml(v)}</td></tr>`).join("")}</table>`;
|
||||
<table>${rows.map(([k, v]) => `<tr><th>${k}</th><td>${escapeHtml(v)}</td></tr>`).join("")}</table>
|
||||
<button type="button" class="live-tracker-card__nav${this._follow ? " active" : ""}">${this._follow ? "Stop navigating" : "Navigate"}</button>`;
|
||||
}
|
||||
|
||||
_popup(lngLat) {
|
||||
|
||||
@@ -19,6 +19,7 @@ import { OfflineDataControl } from "/js/offline_data.js";
|
||||
import { RoutePanelControl } from "/js/route.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 { getPosition } from "/vendor/suncalc/suncalc.js";
|
||||
import { notifySidePanelOpen, onlyOneSidePanelOpen, setupSidePanelModes } from "/js/panels.js";
|
||||
import { isLoggedIn } from "/js/auth.js";
|
||||
import { DebugControl } from "/js/debug.js";
|
||||
@@ -465,6 +466,33 @@ updateSun();
|
||||
map.on("moveend", updateSun);
|
||||
setInterval(updateSun, 60000);
|
||||
|
||||
// Night mode (html.night, style.css) so the screen doesn't glare in the
|
||||
// car: "auto" follows the sun at the map center, or forced on/off — the
|
||||
// topbar button cycles the three, remembered per device.
|
||||
const NIGHT_MODES = { auto: ["◐", "Night mode: automatic (after sunset)"], on: ["☾", "Night mode: on"], off: ["☀", "Night mode: off"] };
|
||||
const nightButton = document.querySelector(".topbar__night");
|
||||
let nightMode = "auto";
|
||||
try {
|
||||
nightMode = localStorage.getItem("nightMode") || "auto";
|
||||
} catch {}
|
||||
const updateNight = () => {
|
||||
const { lng, lat } = map.getCenter();
|
||||
const dark = nightMode === "on" || (nightMode === "auto" && getPosition(new Date(), lat, lng).altitude < 0);
|
||||
document.documentElement.classList.toggle("night", dark);
|
||||
[nightButton.textContent, nightButton.title] = NIGHT_MODES[nightMode] || NIGHT_MODES.auto;
|
||||
};
|
||||
nightButton.addEventListener("click", () => {
|
||||
const modes = Object.keys(NIGHT_MODES);
|
||||
nightMode = modes[(modes.indexOf(nightMode) + 1) % modes.length];
|
||||
try {
|
||||
localStorage.setItem("nightMode", nightMode);
|
||||
} catch {}
|
||||
updateNight();
|
||||
});
|
||||
updateNight();
|
||||
map.on("moveend", updateNight);
|
||||
setInterval(updateNight, 60000);
|
||||
|
||||
const sidebar = document.getElementById("sidebar");
|
||||
|
||||
// Grouped into the TODO's planned 4-module menu (Explorer / Offline hub /
|
||||
|
||||
Reference in new issue
Block a user