Skip to content

Map picker: fit the provider list on screen and scroll it - #2460

Merged
efiten merged 2 commits into
Kpa-clawbot:masterfrom
anieto:map-picker-fit
Nov 25, 2026
Merged

efiten merged 2 commits into
Kpa-clawbot:masterfrom
anieto:map-picker-fit

Conversation

@anieto

@anieto anieto commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #2434. With several of the new provider groups enabled, the map picker's list is taller than many screens. On the Live page it gets no scrollbar, and the last entries end up off screen or behind the replay bar and the legend.

Cause

Leaflet's layer control sizes the expanded list from the whole map's height (map.getSize().y minus the control's offset). On the Live page the map fills the window and runs under the nav, the replay bar and the legend, so Leaflet decides the list fits when the visible part of the map is much shorter. The Map page is not affected in practice, because its map ends where the visible area ends.

Fix

  • map-tile-providers.js: _fitLayerList caps the expanded list to the visible space and turns on Leaflet's own leaflet-control-layers-scrollbar class when the list doesn't fit. The limit is the lowest of:

    • the viewport;
    • the map's bottom edge;
    • an optional bottomInset(listRect) from the caller.

    It runs on expand, when the list is re-rendered, and on map resize. The resize handler is removed with the control.

  • MC_attachAutoTiles(map, { controlPosition, bottomInset }): the new option is passed through to the picker. Callers that don't pass it behave as before, apart from the viewport and map-edge cap.

  • live.js: passes a bottomInset that covers #vcrBar and .live-legend when either sits below the list in its columns.

Testing

  • New unit test in tests/unit/test-map-layer-builder.js. It checks that:
    • the list is untouched while collapsed;
    • it is capped above the inset and scrolls when expanded;
    • it is released on a taller window;
    • it follows the map's bottom edge;
    • the resize handler is removed on destroy.
  • test-all.sh and npx eslint public/*.js pass.
  • Checked in a browser on a deployment with all keyless groups enabled, with the list made taller than the window. On Live, the list stops above the replay bar, and above the legend when the legend is open below it. It scrolls to the last entry (the EOX labels overlay). On the Map page the behaviour is unchanged.

With several provider groups enabled, the picker's list is taller than
many screens. Leaflet sizes the expanded list from the whole map's
height, but the Live map runs under the nav, the replay bar and the
legend, so it decided the list fit: no scrollbar, and the last entries
were off screen or hidden behind the replay bar and legend.

On expand, list updates and map resize, cap the list to the visible
space (viewport, map bottom, and an optional bottomInset(listRect) from
the caller) and turn on Leaflet's scrollbar class. Live passes the
replay bar and the legend when they sit below the list.

@zfouts zfouts left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks — this fixes the Live overflow, and the listener lifecycle is clean (removed on rebuild and in _detach; the collapsed early-return keeps _update storms free). It merges cleanly with #2446 and #2436, and the unit suites pass on both merged trees. A few points, most important first:

  1. Map/Planner: the last rows now go under the attribution bar (map-tile-providers.js:1195). Leaflet's expand() caps the list at map.getSize().y - (offsetTop + 50). _fitLayerList drops that and re-caps at the map's bottom minus 12 px. On a phone-width Map or Planner page (picker top-left, attribution wrapping to two lines), .leaflet-bottom paints over the last row and takes its taps. That is the same symptom this PR fixes on Live, and it contradicts "Map page unchanged". Suggestion: also cap at the top of any child of map._controlCorners.bottomleft/bottomright whose rect overlaps the list's columns. That handles the attribution and any bottom control, and would also cover the ducting panel from #2436. Simpler alternative: keep Leaflet's margin when no bottomInset is given.
  2. Live: other bottom-right widgets aren't in the inset (live.js:1568). #liveMap is a stacking context at z-index 1, so .legend-toggle-btn (shown when the legend is hidden), .feed-show-btn, and a feed or node detail moved to the bottom-right all paint over the capped list. Suggest including them in the selector.
  3. A hidden legend is skipped only by geometry (live.js:1570). .live-legend.hidden is visibility:hidden plus translateX(100%), not display:none, so its rect has a height. It drops out today only because its shifted left edge sits right of the list. A getComputedStyle(el).visibility === 'hidden' check would make that explicit.
  4. Scroll position resets on a re-fit while open (map-tile-providers.js:1187-1188). Clearing the height before measuring sends scrollTop to 0 on a map resize, or on a cross-tab pin/overlay change (#2446 adds those) while the list is open and scrolled. Saving and restoring section.scrollTop around the fit fixes it.
  5. Very short viewports (map-tile-providers.js:1196). With room <= 0 the list is left uncapped, and Leaflet's cap has already been cleared, so a landscape phone with the VCR bar gets the original bug back. A floor such as Math.max(room, 60) would avoid that.
  6. Tests. These lines can be removed without a test failing: the _fitLayerList call in the _update wrapper (map-tile-providers.js:1317), the _offFitHandler() before re-registering on rebuild (map-tile-providers.js:1329), and the viewport cap. The Live bottomInset geometry has no test. Suggest asserting after c._update() while expanded, checking for a single resize handler after a fromConfig rebuild, and pulling the Live inset into a function of (listRect, rects, innerHeight) with its own test.

Nothing here was checked in a browser; the layout points come from the Leaflet 1.9.4 source and our CSS.

Review follow-ups:
- The list also stops above the map's own bottom-corner controls in its
  columns (attribution, scale, any plugin), so on a phone-width Map or
  Planner page the last rows no longer go under the attribution.
- Live's bottomInset now uses MC_layerListInset and also covers the
  legend toggle, the feed and its show button and a node detail. Hidden,
  invisible and faded-out panels are skipped explicitly.
- A re-fit keeps the list's scroll position.
- A very short viewport keeps a 60 px scrolling list instead of none.
- Tests for the pure inset helper, the hidden-element filter, the corner
  controls, the viewport cap, the re-fit on _update, the scroll position,
  the minimum height and a single resize handler across rebuilds.
@anieto

anieto commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, Zach. All six are in b15b3240.

  1. Bottom-corner controls. _fitLayerList now also stops above any shown child of map._controlCorners.bottomleft and .bottomright that sits below the list and overlaps its columns. That covers the attribution, a scale control, and anything added there later, such as the ducting panel from feat(map): tropospheric ducting overlay (Open-Meteo, worldwide, off by default) #2436. Checked in a browser on the Map page at 390 px wide, with the map shortened and the attribution wrapped under the top-left list: the list now ends 12 px above the attribution and scrolls.

  2. Other Live widgets. Live's bottomInset now covers #vcrBar, .live-legend, .legend-toggle-btn, #feedShowBtn, .live-feed and .live-node-detail.

  3. Hidden elements. The geometry is now MC_layerListInset(listRect, els, vh). It skips elements whose computed style is display:none, visibility:hidden or opacity 0, so .live-legend.hidden is skipped by its style, not by where it happens to sit. The pure part is exposed as MC_coveredBelow(listRect, rects, vh).

  4. Scroll position. scrollTop is saved before the height is cleared and restored after the cap is applied.

  5. Short viewports. The list keeps at least 60 px and scrolls, rather than being left uncapped.

  6. Tests. New tests in test-map-layer-builder.js cover:

    • the pure inset rule and the hidden-element filter;
    • the corner controls and the viewport cap;
    • a re-fit on _update() while expanded, and the scroll position across _update and a resize;
    • the 60 px floor;
    • a single resize handler after two fromConfig rebuilds, which then fits the new control.

    With the _update fit, the _offFitHandler() before re-registering, the scroll restore or the floor removed, a test fails. The viewport cap is also implied by the bottomInset term, so that test checks the behaviour rather than one line.

test-all.sh passes, and npx eslint public/*.js reports no errors.

@efiten
efiten merged commit 5f03253 into Kpa-clawbot:master Nov 25, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants