From d11f40e313d45f7e0ffd860f37a42101997eabf9 Mon Sep 17 00:00:00 2001 From: Renaud Michaelis Date: Wed, 28 Aug 2024 10:05:48 +0200 Subject: [PATCH] If a map is initializated with an height of 0 then force the map refresh as soon as the height change --- geoportal/jsapi/src/map.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/geoportal/jsapi/src/map.js b/geoportal/jsapi/src/map.js index f38a64297..d9e1d9dc6 100644 --- a/geoportal/jsapi/src/map.js +++ b/geoportal/jsapi/src/map.js @@ -464,6 +464,11 @@ class Map extends OpenLayersMap { 'public.lu', 'etat.lu', 'inondations.lu', 'visit-fouhren.lu', 'visit-hoscheid.lu', 'visitjunglinster.lu', 'visitreisdorf.lu', 'visitrosportmompach.lu', 'mae.lu', 'gouvernement.lu', 'meteolux.lu', 'luxemburg.infomax.online']; + /** + * @private + */ + this.resizeObserver_ = undefined; + /** * @private * @type {boolean} @@ -713,6 +718,31 @@ class Map extends OpenLayersMap { options.callback.call(this); }.bind(this)); } + /** + * @private + * @type {function()} + */ + this.cbResize_ = function(entries) { + for (let entry of entries) { + if (entry.contentRect.width > 0 && + entry.contentRect.height > 0) { + this.updateSize(); + if (this.resizeObserver_ !== undefined) { + this.resizeObserver_.unobserve(this.getTargetElement()); + this.resizeObserver_ = undefined; + } + } + } + } + try { + if (this.getTargetElement().clientHeight == 0 || + this.getTargetElement().clientWidth == 0) { + this.resizeObserver_ = new ResizeObserver(this.cbResize_.bind(this)); + this.resizeObserver_.observe(this.getTargetElement()) + } + } catch(e) { + console.log(e); + } } /**