Resize map on div size change

By default, OpenLayers listens for and resizes on page resize, but not
on map div size change. (Pre-2021ish, this was maybe impossible to do?
But ResizeObserver makes this easy.) This means from the first time the
sidebar is collapsed until the first time a resize event was triggered
(e.g. on mobile rotating the device) the map wouldn't render render its
full size.
main
Chandler Swift 2024-02-02 01:50:01 -06:00
parent ff77bc31e7
commit 77b4f845ae
Signed by: chandlerswift
GPG Key ID: A851D929D52FB93F
1 changed files with 2 additions and 0 deletions

View File

@ -118,3 +118,5 @@ map.on('click', function (evt) {
popupOverlay.setPosition(evt.coordinate); popupOverlay.setPosition(evt.coordinate);
}); });
new ResizeObserver(() => map.updateSize()).observe(document.getElementById("map"));