From 77b4f845ae90e0103cd487260c62813369a60604 Mon Sep 17 00:00:00 2001 From: Chandler Swift Date: Fri, 2 Feb 2024 01:50:01 -0600 Subject: [PATCH] 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.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.js b/main.js index 7ffa370..f1ecc9f 100644 --- a/main.js +++ b/main.js @@ -118,3 +118,5 @@ map.on('click', function (evt) { popupOverlay.setPosition(evt.coordinate); }); + +new ResizeObserver(() => map.updateSize()).observe(document.getElementById("map"));