Map the start and end of trails with no track, with the notice beside it
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
a37f375101
commit
3709a9af5f
8 files changed
+309
-78
No files matched your search
+92
-10
@@ -800,15 +800,9 @@
|
||||
{ id: 'olt-sketch-points', type: 'circle', strokeByKind: true, strokeWidth: 2, radius: [3, 3, 9, 6], filter: IS_SKETCH, hit: true }
|
||||
];
|
||||
}
|
||||
if (kind === 'sketch') {
|
||||
var col = routeMain ? '--route' : '--trail';
|
||||
/* A pale band under the dots lifts them off relief and contours. */
|
||||
return [
|
||||
{ id: 'olt-sketch-halo', color: '--casing', width: [5, 6, 12, 9], opacity: 0.6, filter: IS_SKETCH },
|
||||
{ id: 'olt-sketch', color: col, width: [5, 3, 12, 5], dash: [0, 2], cap: 'round', filter: IS_SKETCH },
|
||||
{ id: 'olt-sketch-points', type: 'circle', stroke: col, strokeWidth: 2.5, radius: [5, 5, 12, 8], filter: IS_SKETCH }
|
||||
];
|
||||
}
|
||||
/* A trail page with no track: the map draws no layer at all. The start and the end are
|
||||
labelled markers (placeTermini in initMap), and nothing joins them. */
|
||||
if (kind === 'sketch') return [];
|
||||
return [
|
||||
{ id: 'olt-casing', color: '--casing', width: [5, 4, 12, 8] },
|
||||
{ id: 'olt-alt', color: '--trail', width: [5, 1.5, 12, 3], dash: [2, 1.6], filter: ['==', ['get', 'role'], 'alternate'] },
|
||||
@@ -942,7 +936,89 @@
|
||||
if (!frame || !hasSketch()) return;
|
||||
var r = host.getBoundingClientRect();
|
||||
if (r.width && r.height) corners(extentOf(frame, r.width, r.height, 0));
|
||||
placeTermini();
|
||||
}
|
||||
|
||||
/* The start and the end of a trail with no track: a dot and a label each, from the
|
||||
page's own list of them (.terminus-item: the record's places and positions). They sit
|
||||
over the drawing and over the live map alike, and are text for screen readers in that
|
||||
list, so the layer is hidden from them. A northern end's label goes above its dot, a
|
||||
southern one's below, and each is kept inside the frame. */
|
||||
var termini = [];
|
||||
var terminiLayer = host.querySelector('.map__termini');
|
||||
if (terminiLayer) {
|
||||
Array.prototype.forEach.call(fig.querySelectorAll('.terminus-item'), function (li) {
|
||||
var el = document.createElement('div');
|
||||
el.className = 'terminus terminus--' + li.dataset.role;
|
||||
var dot = document.createElement('span');
|
||||
dot.className = 'terminus__dot';
|
||||
var label = document.createElement('span');
|
||||
label.className = 'terminus__label';
|
||||
label.textContent = li.dataset.label;
|
||||
el.appendChild(dot);
|
||||
el.appendChild(label);
|
||||
terminiLayer.appendChild(el);
|
||||
termini.push({ el: el, label: label, lon: Number(li.dataset.lon), lat: Number(li.dataset.lat) });
|
||||
});
|
||||
}
|
||||
function placeTermini() {
|
||||
if (!termini.length) return;
|
||||
var r = host.getBoundingClientRect();
|
||||
if (!r.width || !r.height) return;
|
||||
var W = r.width, H = r.height;
|
||||
var ext = entry.ready && entry.map ? null : (frame ? extentOf(frame, W, H, 0) : null);
|
||||
var xy = termini.map(function (t) {
|
||||
if (ext) return { x: W / 2 + (t.lon - ext.cx) * ext.rad * ext.k, y: H / 2 - (mercY(t.lat) - ext.cy) * ext.k };
|
||||
var p = entry.map.project([t.lon, t.lat]);
|
||||
return { x: p.x, y: p.y };
|
||||
});
|
||||
/* Each label goes above or below its dot, as far as possible outward (the northern end's
|
||||
above, the southern end's below), kept inside the frame, and never over the other label
|
||||
or the other dot: the four ways of placing two labels are scored and the best one used. */
|
||||
var HALF = 13;
|
||||
var boxes = termini.map(function (t, i) {
|
||||
var w = t.label.offsetWidth, h = t.label.offsetHeight, p = xy[i];
|
||||
var x0 = p.x - w / 2;
|
||||
var dx = x0 < 8 ? 8 - x0 : (x0 + w > W - 8 ? (W - 8) - (x0 + w) : 0);
|
||||
return { w: w, h: h, dx: dx, left: x0 + dx };
|
||||
});
|
||||
function rect(i, above) {
|
||||
var b = boxes[i], p = xy[i];
|
||||
var top = above ? p.y - HALF - b.h : p.y + HALF;
|
||||
return { l: b.left, r: b.left + b.w, t: top, b: top + b.h };
|
||||
}
|
||||
function overlap(a, c) {
|
||||
var w = Math.min(a.r, c.r) - Math.max(a.l, c.l), h = Math.min(a.b, c.b) - Math.max(a.t, c.t);
|
||||
return w > 0 && h > 0 ? w * h : 0;
|
||||
}
|
||||
function dotBox(i) { return { l: xy[i].x - 10, r: xy[i].x + 10, t: xy[i].y - 10, b: xy[i].y + 10 }; }
|
||||
function cost(sides) {
|
||||
var c = 0;
|
||||
var rs = sides.map(function (above, i) { return rect(i, above); });
|
||||
rs.forEach(function (r, i) {
|
||||
c += Math.max(0, 4 - r.t) * 40 + Math.max(0, r.b - (H - 4)) * 40;
|
||||
xy.forEach(function (_, j) { if (j !== i) c += overlap(r, dotBox(j)) * 20; });
|
||||
if (i > 0) c += overlap(r, rs[0]) * 20;
|
||||
});
|
||||
return c;
|
||||
}
|
||||
var outward = xy.length > 1 && xy[1].y < xy[0].y ? [false, true] : [true, false];
|
||||
var choices = xy.length === 1 ? [[true], [false]]
|
||||
: [outward, [!outward[0], !outward[1]], [true, true], [false, false]];
|
||||
var best = choices[0], bestCost = Infinity;
|
||||
choices.forEach(function (c) {
|
||||
var k = cost(c);
|
||||
if (k < bestCost) { best = c; bestCost = k; }
|
||||
});
|
||||
termini.forEach(function (t, i) {
|
||||
var p = xy[i];
|
||||
t.el.style.transform = 'translate(' + p.x.toFixed(1) + 'px,' + p.y.toFixed(1) + 'px)';
|
||||
t.el.classList.toggle('terminus--above', best[i]);
|
||||
t.el.classList.toggle('terminus--below', !best[i]);
|
||||
t.label.style.setProperty('--dx', boxes[i].dx.toFixed(1) + 'px');
|
||||
});
|
||||
}
|
||||
entry.placeTermini = placeTermini;
|
||||
function redrawFallback() {
|
||||
if (hasSketch()) { sketchCorners(); return; }
|
||||
if (!entry.ready && entry.fc) {
|
||||
@@ -1100,6 +1176,7 @@
|
||||
}
|
||||
entry.ready = true;
|
||||
settled = true;
|
||||
placeTermini();
|
||||
/* The live map shows (and the drawing gives way, in the CSS) once it has drawn its first
|
||||
frame with the tracks: the base map fills in behind a track that holds still. */
|
||||
var shown = false;
|
||||
@@ -1161,6 +1238,11 @@
|
||||
corners({ w: b.getWest(), e: b.getEast(), n: b.getNorth(), s: b.getSouth() });
|
||||
}
|
||||
map.on('moveend', function () { if (entry.ready) mapCorners(); });
|
||||
if (termini.length) {
|
||||
map.on('move', placeTermini);
|
||||
map.on('resize', placeTermini);
|
||||
map.on('load', placeTermini);
|
||||
}
|
||||
document.addEventListener('olt:theme', function () {
|
||||
if (!entry.ready || !settled) return; /* a style still loading is dressed in the new theme */
|
||||
if (current === 'outdoor') restyle();
|
||||
@@ -1253,7 +1335,7 @@
|
||||
var pointOnly = (g.type === 'MultiPoint' && g.coordinates.length === 1) || g.type === 'Point';
|
||||
var note = document.createElement('p');
|
||||
note.textContent = pointOnly
|
||||
? 'No GPX here. The ring only marks one end of it; it is not the trail\u2019s path.'
|
||||
? 'No GPX here. The ring only marks where it starts and ends; it is not the trail\u2019s path.'
|
||||
: 'No GPX here. The dotted line only joins the start and the end; it is not the trail\u2019s path.';
|
||||
box.appendChild(note);
|
||||
}
|
||||
|
||||
+57
-3
@@ -825,9 +825,63 @@ html.js .map__status:not([data-say]) { display: none; }
|
||||
.legend li { display: inline-flex; align-items: center; gap: var(--space-2); }
|
||||
/* Under a map of many trails the legend keeps a row to itself, however short it is. */
|
||||
.mapfig[data-map="overview"] .legend { flex-basis: 100%; }
|
||||
.mapfig__caption--sketch { align-items: start; }
|
||||
.sketch-note { display: grid; gap: var(--space-2); max-inline-size: 42rem; }
|
||||
.sketch-note .cluster { margin-block-start: var(--space-1); }
|
||||
/* A trail with no track and a known start and end (olt/trail.py sketch_figure): the map with a
|
||||
labelled marker at each end, and the notice about where to get a track beside or under it,
|
||||
never over it. No line joins the two. */
|
||||
.mapfig--termini { display: grid; gap: var(--space-4); align-content: start; }
|
||||
.mapfig--termini .mapfig__frame { grid-area: frame; }
|
||||
.mapfig--termini .termini-notice { grid-area: notice; min-inline-size: 0; }
|
||||
.mapfig--termini .mapfig__caption { grid-area: caption; margin-block-start: 0; }
|
||||
.mapfig--termini { grid-template-areas: "frame" "caption" "notice"; gap: var(--space-3); }
|
||||
.mapfig--termini .map__message { max-inline-size: none; padding: var(--space-4); box-shadow: 4px 4px 0 var(--rule); }
|
||||
.mapfig--termini .map__message > * + * { margin-block-start: var(--space-2); }
|
||||
.mapfig--termini .map__message h2 { font-size: var(--step-1); }
|
||||
.mapfig--termini .map { aspect-ratio: 16 / 10; }
|
||||
/* Wide: the notice stands beside the map, so both ends and the notice are in the first screen. */
|
||||
@media (min-width: 64rem) {
|
||||
.mapfig--termini {
|
||||
grid-template-columns: minmax(0, 1fr) 17.5rem;
|
||||
grid-template-areas: "frame notice" "caption caption";
|
||||
gap: var(--space-3) var(--space-4);
|
||||
}
|
||||
.mapfig--termini .map { aspect-ratio: auto; block-size: clamp(17rem, calc(100svh - 28rem), 26rem); }
|
||||
}
|
||||
.termini-list { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-5); padding: 0; margin: 0 0 var(--space-1); list-style: none; }
|
||||
/* With the script the labels on the map say the same; the list stays for screen readers. */
|
||||
html.js .termini-list { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); }
|
||||
.mapfig--termini .map__reason { font-size: var(--step-0); line-height: 1.5; }
|
||||
.termini-list strong { margin-inline-end: var(--space-1); }
|
||||
.map__termini { position: absolute; inset: 0; z-index: 2; overflow: hidden; pointer-events: none; }
|
||||
.terminus { position: absolute; inset-block-start: 0; inset-inline-start: 0; }
|
||||
.terminus__dot {
|
||||
position: absolute;
|
||||
inset-block-start: -8px;
|
||||
inset-inline-start: -8px;
|
||||
inline-size: 16px;
|
||||
block-size: 16px;
|
||||
box-sizing: border-box;
|
||||
border-radius: 50%;
|
||||
background: var(--casing);
|
||||
border: 3.5px solid var(--trail);
|
||||
box-shadow: 0 0 0 2px var(--casing);
|
||||
}
|
||||
.mapfig[data-route="yes"] .terminus__dot { border-color: var(--route); }
|
||||
.terminus__label {
|
||||
position: absolute;
|
||||
inset-inline-start: 0;
|
||||
inline-size: max-content;
|
||||
max-inline-size: 15rem;
|
||||
padding: 2px var(--space-2);
|
||||
transform: translateX(calc(-50% + var(--dx, 0px)));
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--ink);
|
||||
color: var(--ink);
|
||||
font: 600 var(--step--1)/1.3 var(--font-sans);
|
||||
text-align: center;
|
||||
}
|
||||
.terminus--above .terminus__label { inset-block-end: 13px; }
|
||||
.terminus--below .terminus__label { inset-block-start: 13px; }
|
||||
@media (max-width: 40rem) { .terminus__label { max-inline-size: 10rem; font-size: var(--step--2); } }
|
||||
|
||||
/* Empty frame: the record has no line, so nothing is drawn */
|
||||
.map--empty {
|
||||
|
||||
Reference in new issue
Block a user