Keep a place page's map on its place after the list is applied
fitToVisible compared the whole list of a place page (every trail there, drawn or not) with the drawn trails the page opened on, found them different, and fitted the map to the extent of the visible tracks: the American Discovery Trail's. Only trails with geometry now count on a place page (data-place). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
cfa8026300
commit
a0540d21d2
3 files changed
+31
-1
No files matched your search
@@ -916,6 +916,8 @@
|
||||
var frame = (fig.dataset.frame || '').split(',').map(Number);
|
||||
if (frame.length !== 4 || frame.some(isNaN)) frame = null;
|
||||
entry.frame = frame;
|
||||
/* A place page (data-place) is about its place: what its map settles on is the place's box. */
|
||||
entry.place = fig.hasAttribute('data-place');
|
||||
entry.initialIds = onlyIds.length ? onlyIds : null;
|
||||
|
||||
/* The page's own drawing of the tracks (class map__sketch) stays until the live map has
|
||||
@@ -1368,6 +1370,13 @@
|
||||
/* The trails the page opened on are the ground its drawing shows: that view needs no move. */
|
||||
var first = entry.initialIds || Object.keys(entry.boundsById);
|
||||
var same = ids.length === first.length && ids.every(function (id) { return first.indexOf(id) !== -1; });
|
||||
/* The list of a place page holds trails the map cannot draw (no track, no known start or end), and
|
||||
the trails the map drew are the page's own data-ids. The same trails drawn is the same view. */
|
||||
if (!same && entry.place && entry.initialIds) {
|
||||
var drawn = function (list) { return list.filter(function (id) { return entry.boundsById[id]; }); };
|
||||
var now = drawn(ids), then = drawn(first);
|
||||
same = now.length === then.length && now.every(function (id) { return then.indexOf(id) !== -1; });
|
||||
}
|
||||
if (entry.frame && same) { target = entry.frame; padding = 0; }
|
||||
map.fitBounds([[target[0], target[1]], [target[2], target[3]]],
|
||||
{ padding: padding, maxZoom: 11, animate: !reduceMotion });
|
||||
|
||||
+2
-1
@@ -694,7 +694,8 @@ def overview_map(recs, label, *, wide=False, scope="", saved=False, place=None):
|
||||
# The frame takes the shape of the ground it shows, within calm bounds, so the tracks fill it
|
||||
# (style.css .browse__map); the drawing and the live map fit the same ground either way.
|
||||
frame_attr += f' style="--frame-n: {frame_ratio(fr):.3f}"'
|
||||
return Markup(f"""<figure class="mapfig{" mapfig--wide" if wide else ""}" data-map="overview" data-src="/data/overview.geojson"{ids_attr}{overview_bbox(recs, place)}{frame_attr}>
|
||||
place_attr = " data-place" if place and not saved else ""
|
||||
return Markup(f"""<figure class="mapfig{" mapfig--wide" if wide else ""}" data-map="overview" data-src="/data/overview.geojson"{ids_attr}{overview_bbox(recs, place)}{frame_attr}{place_attr}>
|
||||
<div class="mapfig__frame">
|
||||
<span class="mapfig__corner mapfig__corner--nw" aria-hidden="true"></span>
|
||||
<div class="map" role="region" aria-label="{esc(label)}">
|
||||
|
||||
@@ -103,6 +103,26 @@ class PlaceViewTest(unittest.TestCase):
|
||||
whole = figure(home.overview_map(self.records, "Map", scope="all"))
|
||||
self.assertEqual(attr(whole, "bbox"), rounded(home.overview_box(self.records)))
|
||||
|
||||
def test_a_place_page_declares_its_place_and_no_other_page_does(self):
|
||||
self.assertIn(" data-place", self.region_figure("us-ut"))
|
||||
self.assertIn(" data-place", figure(regions.group_page("mountain-west", self.records, self.site)[2]))
|
||||
self.assertNotIn("data-place", figure(home.overview_map(self.records[:12], "Map")))
|
||||
self.assertNotIn("data-place", figure(home.overview_map(self.records, "Map", scope="all")))
|
||||
with mock.patch.object(bounds, "_boxes", {}):
|
||||
self.assertNotIn("data-place", self.region_figure("us-ut"))
|
||||
|
||||
def test_the_script_keeps_a_place_page_on_its_place_when_the_list_holds_trails_it_cannot_draw(self):
|
||||
# The list of a place page holds every trail there, drawn or not; the filters hand fitToVisible
|
||||
# that list. Comparing it with the drawn trails (data-ids) alone sent Utah and Mountain West to
|
||||
# the extent of the American Discovery Trail. Only trails with geometry count.
|
||||
with open(os.path.join(WEB, "assets", "app.js"), encoding="utf-8") as f:
|
||||
js = f.read()
|
||||
fit = re.search(r"function fitToVisible\(.*?\n \}\n", js, re.S).group(0)
|
||||
self.assertIn("entry.place", fit)
|
||||
self.assertIn("entry.boundsById[id]", fit)
|
||||
self.assertIn("if (entry.frame && same) { target = entry.frame; padding = 0; }", fit)
|
||||
self.assertIn("entry.place = fig.hasAttribute('data-place');", js)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user