ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 11m19s
ci / test (pull_request) Successful in 13m11s
ci / build (pull_request) Successful in 18m31s
ci / image (pull_request) Successful in 5m52s
Regions a few kilometres apart drew their labels on top of each other. As on the landing page, a label now runs to the right of its point, or to the left where the right side would cover another pin or leave the map; a pin with room on neither side shows only its dot and reveals its name on hover. Placement reruns while zooming and panning. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
120 lines
7.3 KiB
HTML
120 lines
7.3 KiB
HTML
<!doctype html><html><body data-msg-network="net">
|
|
<form id="monitor">
|
|
<div id="select-map" data-region-map="select" data-region-items="#monitor-regions" data-map-server="stub" data-touch-hint="t" data-scroll-hint="{key} s" data-ctrl-key="Ctrl" hidden style="width:300px;height:200px"></div>
|
|
<div id="monitor-regions">
|
|
<label><input type="checkbox" name="regions" value="r1" data-multi checked data-lat="50.11" data-lon="8.68" data-name="Frankfurt" data-live="2"></label>
|
|
<label><input type="checkbox" name="regions" value="r2" data-multi data-lat="40.71" data-lon="-74.0" data-name="New York" data-live="0"></label>
|
|
<label><input type="checkbox" name="regions" value="r3" data-multi data-name="Office" data-live="1"></label>
|
|
</div>
|
|
</form>
|
|
<div id="edit-map" data-region-map="edit" data-region-items="#region-list" data-map-server="stub" data-touch-hint="t" data-scroll-hint="{key} s" data-ctrl-key="Ctrl" hidden style="width:300px;height:200px"></div>
|
|
<table><tbody id="region-list">
|
|
<tr data-lat="50.11" data-lon="8.68" data-name="Frankfurt" data-live="2"><td><button type="button" id="toggle" data-location-toggle="location-r1">set</button></td></tr>
|
|
<tr id="location-r1" hidden><td><form data-api="/org/regions/r1" data-method="patch" data-next="#saved" data-location-form id="row-form">
|
|
<input name="latitude" data-number data-nullable data-location-field="latitude" value="50.11">
|
|
<input name="longitude" data-number data-nullable data-location-field="longitude" value="8.68">
|
|
<button type="submit">save</button><button type="button" id="clear" data-location-clear>clear</button>
|
|
</form></td></tr>
|
|
</tbody></table>
|
|
<form data-api="/org/regions" id="create"><div data-location-form data-location-default>
|
|
<input name="latitude" data-number data-nullable data-location-field="latitude">
|
|
<input name="longitude" data-number data-nullable data-location-field="longitude">
|
|
</div></form>
|
|
<div id="near-map" data-region-map="edit" data-region-items="#near" data-map-server="stub" data-touch-hint="t" data-scroll-hint="{key} s" data-ctrl-key="Ctrl" hidden style="width:300px;height:200px;position:relative"></div>
|
|
<table><tbody id="near">
|
|
<tr data-lat="50" data-lon="8" data-name="Nuremberg" data-live="1"><td></td></tr>
|
|
<tr data-lat="50.05" data-lon="8.5" data-name="Bamberg" data-live="1"><td></td></tr>
|
|
<tr data-lat="55" data-lon="19" data-name="Gdansk" data-live="1"><td></td></tr>
|
|
</tbody></table>
|
|
<pre id="out"></pre>
|
|
<script>
|
|
const sent = [];
|
|
window.axios = { create: () => ({ interceptors: { request: { use() {} } }, request: async (cfg) => { sent.push(cfg); return { data: {} }; } }) };
|
|
const maps = [];
|
|
window.maplibregl = {
|
|
Map: class {
|
|
constructor(opts) { this.container = opts.container; this.handlers = {}; this.style = opts.style; maps.push(this); }
|
|
on(ev, fn) { (this.handlers[ev] ??= []).push(fn); }
|
|
fire(ev, arg) { for (const fn of this.handlers[ev] ?? []) fn(arg); }
|
|
addControl() {}
|
|
resize() {}
|
|
fitBounds(b) { this.bounds = b.points; }
|
|
jumpTo(o) { this.center = o.center; }
|
|
setStyle(s) { this.style = s; }
|
|
// 10 px per degree, 8°E 50°N at the middle of the box.
|
|
project({ lng, lat }) { return { x: 100 + (lng - 0) * 10, y: 100 - (lat - 50) * 10 }; }
|
|
},
|
|
Marker: class {
|
|
constructor(o) { this.el = o.element; }
|
|
setLngLat(p) { this.at = p; this.el.dataset.at = p.join(","); return this; }
|
|
getLngLat() { return { lng: this.at[0], lat: this.at[1] }; }
|
|
addTo(map) { map.container.append(this.el); return this; }
|
|
},
|
|
NavigationControl: class {},
|
|
LngLatBounds: class {
|
|
constructor(a) { this.points = [a]; }
|
|
extend(p) { this.points.push(p); return this; }
|
|
},
|
|
};
|
|
</script>
|
|
<script src="../assets/app.js"></script>
|
|
<script>
|
|
(async () => {
|
|
const out = [];
|
|
const check = (name, got, want) => {
|
|
const g = JSON.stringify(got), w = JSON.stringify(want);
|
|
out.push((g === w ? "PASS " : "FAIL ") + name + (g === w ? "" : " got=" + g + " want=" + w));
|
|
};
|
|
await new Promise((r) => setTimeout(r, 50));
|
|
const sel = document.getElementById("select-map");
|
|
const markers = () => [...sel.querySelectorAll(".region-pin")];
|
|
const box = (v) => document.querySelector(`[value="${v}"]`);
|
|
check("select map shown", sel.hidden, false);
|
|
check("light style", maps[0].style, "stub/style-light.json");
|
|
check("markers for located regions", markers().map((m) => m.title), ["Frankfurt", "New York"]);
|
|
check("fits all markers", maps[0].bounds, [[8.68, 50.11], [-74, 40.71]]);
|
|
check("checked marker filled", markers().map((m) => m.classList.contains("is-checked")), [true, false]);
|
|
check("idle region marked", markers()[1].dataset.live, "0");
|
|
markers()[1].click();
|
|
check("marker click ticks checkbox", box("r2").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 PointerEvent("pointerenter", { pointerType: "touch" }));
|
|
check("a tap leaves no highlight", box("r1").closest("label").classList.contains("is-hover"), false);
|
|
markers()[0].dispatchEvent(new PointerEvent("pointerenter", { pointerType: "mouse" }));
|
|
check("hovering a marker lights its row", box("r1").closest("label").classList.contains("is-hover"), true);
|
|
box("r2").closest("label").dispatchEvent(new PointerEvent("pointerenter", { pointerType: "mouse" }));
|
|
check("hovering a row lights its marker", markers()[1].parentElement.classList.contains("is-hover"), true);
|
|
box("r1").click();
|
|
check("checkbox untick clears marker", markers()[0].classList.contains("is-checked"), false);
|
|
|
|
const edit = maps[1];
|
|
const click = (lat, lng) => edit.fire("click", { lngLat: { lat, lng, wrap() { return { lat, lng: lng > 180 ? lng - 360 : lng }; } } });
|
|
click(48.137154, 11.576124);
|
|
const create = document.getElementById("create");
|
|
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 .region-pick")?.dataset.at, "11.576124,48.137154");
|
|
document.querySelector("#edit-map .region-pin").click();
|
|
check("marker click opens its row", document.getElementById("location-r1").hidden, false);
|
|
click(52.52, 373.4);
|
|
const row = document.getElementById("row-form");
|
|
check("map click fills open row", [row.elements.latitude.value, row.elements.longitude.value], ["52.52", "13.4"]);
|
|
check("create form untouched", create.elements.latitude.value, "48.1372");
|
|
document.getElementById("clear").click();
|
|
await new Promise((r) => setTimeout(r, 50));
|
|
check("clear sends nulls", sent.at(-1) && [sent.at(-1).method, sent.at(-1).url, sent.at(-1).data], ["patch", "/org/regions/r1", { latitude: null, longitude: null }]);
|
|
document.getElementById("toggle").click();
|
|
check("toggle closes row", document.getElementById("location-r1").hidden, true);
|
|
click(1, 2);
|
|
check("closed row falls back to create form", create.elements.latitude.value, "1");
|
|
|
|
const near = maps[2];
|
|
near.fire("load");
|
|
const placement = () => [...near.container.querySelectorAll(".region-pin")].map((p) => [p.title, p.parentElement.classList.contains("is-flipped") ? "left" : p.parentElement.classList.contains("is-compact") ? "dot" : "right"]);
|
|
check("close labels make room", placement(), [["Nuremberg", "dot"], ["Bamberg", "right"], ["Gdansk", "left"]]);
|
|
|
|
document.getElementById("out").textContent = out.join("\n");
|
|
})();
|
|
</script>
|
|
</body></html>
|