feat(regions): label the map pins and link them to the region list
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 11m17s
ci / test (pull_request) Successful in 12m34s
ci / build (pull_request) Canceled after 4m21s
ci / image (pull_request) Canceled after 0s

Pins carry the region's name, turn dark when the region is selected and
show a green dot while a checker of the region is live. Hovering a pin
highlights its row in the list and the other way round, and a region
ticked in the list pans into view. Scrolling the page no longer zooms
the map, and the attribution stays compact.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-28 20:31:11 +01:00
1 parent 3562f8224e
commit 6c246b145f
6 files changed
+92 -31

No files matched your search

+36 -12
View File
@@ -647,7 +647,9 @@ for (const el of document.querySelectorAll("input[data-tz-default]")) {
box.hidden = false;
let map;
try {
map = new gl.Map({ container: box, style: mapStyle(server), center: [10.45, 51.17], zoom: 3 });
// Scrolling the page must not zoom the map; the buttons, a double
// click and pinching do.
map = new gl.Map({ container: box, style: mapStyle(server), center: [10.45, 51.17], zoom: 3, scrollZoom: false, attributionControl: { compact: true } });
} catch {
box.hidden = true;
return;
@@ -670,7 +672,8 @@ for (const el of document.querySelectorAll("input[data-tz-default]")) {
const points = items.map(lngLat);
if (points.length > 1) {
const bounds = points.slice(1).reduce((b, p) => b.extend(p), new gl.LngLatBounds(points[0], points[0]));
map.fitBounds(bounds, { padding: 40, maxZoom: 6, duration: 0 });
// Labels run to the right of their point.
map.fitBounds(bounds, { padding: { top: 40, bottom: 40, left: 40, right: 130 }, maxZoom: 6, duration: 0 });
} else if (points.length === 1) {
map.jumpTo({ center: points[0], zoom: 5 });
}
@@ -680,23 +683,44 @@ for (const el of document.querySelectorAll("input[data-tz-default]")) {
const selecting = box.dataset.regionMap === "select";
for (const item of items) {
const el = Object.assign(document.createElement("button"), { type: "button", className: "region-marker", title: item.dataset.name });
el.setAttribute("aria-label", item.dataset.name);
el.dataset.live = item.dataset.live;
new gl.Marker({ element: el }).setLngLat(lngLat(item)).addTo(map);
// The list row (a label or table row) and the marker light up together.
const row = item.closest("label, tr") ?? item;
row.classList.add("region-row");
const pin = Object.assign(document.createElement("button"), { type: "button", className: "region-pin", title: item.dataset.name });
pin.dataset.live = item.dataset.live;
pin.append(Object.assign(document.createElement("span"), { className: "region-pin-dot" }), Object.assign(document.createElement("span"), { textContent: item.dataset.name }));
const holder = document.createElement("div");
holder.append(pin);
const marker = new gl.Marker({ element: holder, anchor: "left", offset: [-8, 0] }).setLngLat(lngLat(item)).addTo(map);
const hover = (on) => {
holder.classList.toggle("is-hover", on);
row.classList.toggle("is-hover", on);
};
for (const el of [pin, row]) {
el.addEventListener("mouseenter", () => hover(true));
el.addEventListener("mouseleave", () => hover(false));
}
if (selecting) {
// The checkbox stays the source of truth; its change event keeps
// the form's own behaviour.
const paint = () => el.classList.toggle("is-checked", item.checked);
const paint = () => {
pin.classList.toggle("is-checked", item.checked);
row.classList.toggle("is-checked", item.checked);
pin.setAttribute("aria-pressed", String(item.checked));
};
paint();
item.addEventListener("change", paint);
el.addEventListener("click", (ev) => {
item.addEventListener("change", () => {
paint();
// A region ticked in the list comes into view on the map.
const bounds = map.getBounds?.();
if (item.checked && bounds && !bounds.contains(marker.getLngLat())) map.easeTo({ center: marker.getLngLat() });
});
pin.addEventListener("click", (ev) => {
ev.stopPropagation();
if (!item.matches(":disabled")) item.click();
});
} else {
el.classList.add("is-checked");
el.addEventListener("click", (ev) => {
pin.addEventListener("click", (ev) => {
ev.stopPropagation();
item.querySelector("[data-location-toggle]")?.click();
});
@@ -711,7 +735,7 @@ for (const el of document.querySelectorAll("input[data-tz-default]")) {
locationTarget.querySelector('[data-location-field="latitude"]').value = round(at.lat);
locationTarget.querySelector('[data-location-field="longitude"]').value = round(at.lng);
const point = [at.lng, at.lat];
pick ??= new gl.Marker({ element: Object.assign(document.createElement("div"), { className: "region-marker is-pick" }) })
pick ??= new gl.Marker({ element: Object.assign(document.createElement("div"), { className: "region-pick" }) })
.setLngLat(point)
.addTo(map);
pick.setLngLat(point);