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
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:
1 parent
3562f8224e
commit
6c246b145f
6 files changed
+92
-31
No files matched your search
+44
-13
@@ -119,23 +119,54 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Region maps: a dot per region, filled when it is selected and grey
|
/* Region maps: a labelled pin per region, filled when it is selected;
|
||||||
when no checker of the region is live. */
|
its dot is green while a checker of the region is live. */
|
||||||
.region-marker {
|
.region-pin {
|
||||||
width: 14px;
|
display: inline-flex;
|
||||||
height: 14px;
|
align-items: center;
|
||||||
padding: 0;
|
gap: 6px;
|
||||||
border: 2px solid var(--color-ink);
|
padding: 3px 9px 3px 5px;
|
||||||
|
border: 1px solid var(--color-rule);
|
||||||
border-radius: 9999px;
|
border-radius: 9999px;
|
||||||
background: var(--color-paper);
|
background: var(--color-paper);
|
||||||
|
color: var(--color-ink);
|
||||||
|
font: 500 11px/1.3 var(--font-sans);
|
||||||
|
white-space: nowrap;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
box-shadow: 0 1px 4px rgb(0 0 0 / 0.25);
|
||||||
|
transition: background-color 0.15s, color 0.15s, transform 0.15s, box-shadow 0.15s;
|
||||||
}
|
}
|
||||||
.region-marker.is-checked { background: var(--color-ink); }
|
.region-pin-dot {
|
||||||
.region-marker[data-live="0"] { border-color: var(--color-unknown); }
|
flex: none;
|
||||||
.region-marker.is-checked[data-live="0"] { background: var(--color-unknown); }
|
width: 8px;
|
||||||
.region-marker.is-pick {
|
height: 8px;
|
||||||
border-color: var(--color-down);
|
border-radius: 9999px;
|
||||||
|
background: var(--color-unknown);
|
||||||
|
box-shadow: 0 0 0 2px var(--color-paper);
|
||||||
|
}
|
||||||
|
.region-pin:not([data-live="0"]) .region-pin-dot { background: var(--color-up); }
|
||||||
|
.region-pin.is-checked {
|
||||||
|
border-color: var(--color-ink);
|
||||||
|
background: var(--color-ink);
|
||||||
|
color: var(--color-paper);
|
||||||
|
}
|
||||||
|
.region-pin.is-checked .region-pin-dot { box-shadow: 0 0 0 2px var(--color-ink); }
|
||||||
|
.maplibregl-marker.is-hover,
|
||||||
|
.maplibregl-marker:hover { z-index: 3; }
|
||||||
|
.is-hover > .region-pin,
|
||||||
|
.region-pin:hover {
|
||||||
|
transform: scale(1.1);
|
||||||
|
box-shadow: 0 2px 8px rgb(0 0 0 / 0.35);
|
||||||
|
}
|
||||||
|
.region-pin:focus-visible { outline: 2px solid var(--color-maintenance); outline-offset: 2px; }
|
||||||
|
.region-pick {
|
||||||
|
width: 14px;
|
||||||
|
height: 14px;
|
||||||
|
border: 2px solid var(--color-paper);
|
||||||
|
border-radius: 9999px;
|
||||||
background: var(--color-down);
|
background: var(--color-down);
|
||||||
cursor: default;
|
box-shadow: 0 1px 4px rgb(0 0 0 / 0.4);
|
||||||
}
|
}
|
||||||
|
.region-row { transition: background-color 0.15s; }
|
||||||
|
.region-row.is-hover { background: color-mix(in srgb, var(--color-ink) 7%, transparent); }
|
||||||
.region-map .maplibregl-ctrl-attrib { font-size: 10px; }
|
.region-map .maplibregl-ctrl-attrib { font-size: 10px; }
|
||||||
+36
-12
@@ -647,7 +647,9 @@ for (const el of document.querySelectorAll("input[data-tz-default]")) {
|
|||||||
box.hidden = false;
|
box.hidden = false;
|
||||||
let map;
|
let map;
|
||||||
try {
|
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 {
|
} catch {
|
||||||
box.hidden = true;
|
box.hidden = true;
|
||||||
return;
|
return;
|
||||||
@@ -670,7 +672,8 @@ for (const el of document.querySelectorAll("input[data-tz-default]")) {
|
|||||||
const points = items.map(lngLat);
|
const points = items.map(lngLat);
|
||||||
if (points.length > 1) {
|
if (points.length > 1) {
|
||||||
const bounds = points.slice(1).reduce((b, p) => b.extend(p), new gl.LngLatBounds(points[0], points[0]));
|
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) {
|
} else if (points.length === 1) {
|
||||||
map.jumpTo({ center: points[0], zoom: 5 });
|
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";
|
const selecting = box.dataset.regionMap === "select";
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
const el = Object.assign(document.createElement("button"), { type: "button", className: "region-marker", title: item.dataset.name });
|
// The list row (a label or table row) and the marker light up together.
|
||||||
el.setAttribute("aria-label", item.dataset.name);
|
const row = item.closest("label, tr") ?? item;
|
||||||
el.dataset.live = item.dataset.live;
|
row.classList.add("region-row");
|
||||||
new gl.Marker({ element: el }).setLngLat(lngLat(item)).addTo(map);
|
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) {
|
if (selecting) {
|
||||||
// The checkbox stays the source of truth; its change event keeps
|
// The checkbox stays the source of truth; its change event keeps
|
||||||
// the form's own behaviour.
|
// 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();
|
paint();
|
||||||
item.addEventListener("change", paint);
|
item.addEventListener("change", () => {
|
||||||
el.addEventListener("click", (ev) => {
|
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();
|
ev.stopPropagation();
|
||||||
if (!item.matches(":disabled")) item.click();
|
if (!item.matches(":disabled")) item.click();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
el.classList.add("is-checked");
|
pin.addEventListener("click", (ev) => {
|
||||||
el.addEventListener("click", (ev) => {
|
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
item.querySelector("[data-location-toggle]")?.click();
|
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="latitude"]').value = round(at.lat);
|
||||||
locationTarget.querySelector('[data-location-field="longitude"]').value = round(at.lng);
|
locationTarget.querySelector('[data-location-field="longitude"]').value = round(at.lng);
|
||||||
const point = [at.lng, at.lat];
|
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)
|
.setLngLat(point)
|
||||||
.addTo(map);
|
.addTo(map);
|
||||||
pick.setLngLat(point);
|
pick.setLngLat(point);
|
||||||
|
|||||||
@@ -1137,7 +1137,7 @@ templ MonitorEditor(p Page, me Me, f MonitorForm) {
|
|||||||
}
|
}
|
||||||
<div id="monitor-regions">
|
<div id="monitor-regions">
|
||||||
for _, r := range f.Regions {
|
for _, r := range f.Regions {
|
||||||
<label class="mb-1.5 flex items-center gap-2 text-sm">
|
<label class="-mx-2 mb-0.5 flex items-center gap-2 px-2 py-1 text-sm">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
name="regions"
|
name="regions"
|
||||||
|
|||||||
@@ -5554,7 +5554,7 @@ func MonitorEditor(p Page, me Me, f MonitorForm) templ.Component {
|
|||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
for _, r := range f.Regions {
|
for _, r := range f.Regions {
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 451, "<label class=\"mb-1.5 flex items-center gap-2 text-sm\"><input type=\"checkbox\" name=\"regions\" value=\"")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 451, "<label class=\"-mx-2 mb-0.5 flex items-center gap-2 px-2 py-1 text-sm\"><input type=\"checkbox\" name=\"regions\" value=\"")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+9
-3
@@ -39,6 +39,7 @@ window.maplibregl = {
|
|||||||
Marker: class {
|
Marker: class {
|
||||||
constructor(o) { this.el = o.element; }
|
constructor(o) { this.el = o.element; }
|
||||||
setLngLat(p) { this.at = p; this.el.dataset.at = p.join(","); return this; }
|
setLngLat(p) { this.at = p; this.el.dataset.at = p.join(","); return this; }
|
||||||
|
getLngLat() { return this.at; }
|
||||||
addTo(map) { map.container.append(this.el); return this; }
|
addTo(map) { map.container.append(this.el); return this; }
|
||||||
},
|
},
|
||||||
NavigationControl: class {},
|
NavigationControl: class {},
|
||||||
@@ -58,7 +59,7 @@ window.maplibregl = {
|
|||||||
};
|
};
|
||||||
await new Promise((r) => setTimeout(r, 50));
|
await new Promise((r) => setTimeout(r, 50));
|
||||||
const sel = document.getElementById("select-map");
|
const sel = document.getElementById("select-map");
|
||||||
const markers = () => [...sel.querySelectorAll(".region-marker")];
|
const markers = () => [...sel.querySelectorAll(".region-pin")];
|
||||||
const box = (v) => document.querySelector(`[value="${v}"]`);
|
const box = (v) => document.querySelector(`[value="${v}"]`);
|
||||||
check("select map shown", sel.hidden, false);
|
check("select map shown", sel.hidden, false);
|
||||||
check("light style", maps[0].style, "stub/style-light.json");
|
check("light style", maps[0].style, "stub/style-light.json");
|
||||||
@@ -69,6 +70,11 @@ window.maplibregl = {
|
|||||||
markers()[1].click();
|
markers()[1].click();
|
||||||
check("marker click ticks checkbox", box("r2").checked, true);
|
check("marker click ticks checkbox", box("r2").checked, true);
|
||||||
check("marker follows", markers()[1].classList.contains("is-checked"), true);
|
check("marker follows", markers()[1].classList.contains("is-checked"), true);
|
||||||
|
check("row follows", box("r2").closest("label").classList.contains("is-checked"), true);
|
||||||
|
markers()[0].dispatchEvent(new Event("mouseenter"));
|
||||||
|
check("hovering a marker lights its row", box("r1").closest("label").classList.contains("is-hover"), true);
|
||||||
|
box("r2").closest("label").dispatchEvent(new Event("mouseenter"));
|
||||||
|
check("hovering a row lights its marker", markers()[1].parentElement.classList.contains("is-hover"), true);
|
||||||
box("r1").click();
|
box("r1").click();
|
||||||
check("checkbox untick clears marker", markers()[0].classList.contains("is-checked"), false);
|
check("checkbox untick clears marker", markers()[0].classList.contains("is-checked"), false);
|
||||||
|
|
||||||
@@ -77,8 +83,8 @@ window.maplibregl = {
|
|||||||
click(48.137154, 11.576124);
|
click(48.137154, 11.576124);
|
||||||
const create = document.getElementById("create");
|
const create = document.getElementById("create");
|
||||||
check("map click fills create form", [create.elements.latitude.value, create.elements.longitude.value], ["48.1372", "11.5761"]);
|
check("map click fills create form", [create.elements.latitude.value, create.elements.longitude.value], ["48.1372", "11.5761"]);
|
||||||
check("pick marker shown", document.querySelector("#edit-map .is-pick")?.dataset.at, "11.576124,48.137154");
|
check("pick marker shown", document.querySelector("#edit-map .region-pick")?.dataset.at, "11.576124,48.137154");
|
||||||
document.querySelector("#edit-map .region-marker:not(.is-pick)").click();
|
document.querySelector("#edit-map .region-pin").click();
|
||||||
check("marker click opens its row", document.getElementById("location-r1").hidden, false);
|
check("marker click opens its row", document.getElementById("location-r1").hidden, false);
|
||||||
click(52.52, 373.4);
|
click(52.52, 373.4);
|
||||||
const row = document.getElementById("row-form");
|
const row = document.getElementById("row-form");
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@ window.axios = { create: () => ({ interceptors: { request: { use() {} } } }) };
|
|||||||
<script src="../assets/app.js"></script>
|
<script src="../assets/app.js"></script>
|
||||||
<script>
|
<script>
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const ok = document.getElementById("map").hidden && !document.querySelector(".region-marker");
|
const ok = document.getElementById("map").hidden && !document.querySelector(".region-pin");
|
||||||
document.getElementById("out").textContent = (ok ? "PASS" : "FAIL") + " map stays hidden when MapLibre cannot load";
|
document.getElementById("out").textContent = (ok ? "PASS" : "FAIL") + " map stays hidden when MapLibre cannot load";
|
||||||
}, 500);
|
}, 500);
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in new issue
Block a user