diff --git a/src/ol/Map.js b/src/ol/Map.js index d0cae90c372..70c2c47be1d 100644 --- a/src/ol/Map.js +++ b/src/ol/Map.js @@ -1367,7 +1367,7 @@ class Map extends BaseObject { } const view = this.getView(); if (view) { - this.updateViewportSize_(); + this.updateViewportSize_(this.getSize()); this.viewPropertyListenerKey_ = listen( view, @@ -1738,25 +1738,18 @@ class Map extends BaseObject { const oldSize = this.getSize(); if (size && (!oldSize || !equals(size, oldSize))) { this.setSize(size); - this.updateViewportSize_(); + this.updateViewportSize_(size); } } /** * Recomputes the viewport size and save it on the view object (if any) + * @param {import("./size.js").Size|undefined} size The size. * @private */ - updateViewportSize_() { + updateViewportSize_(size) { const view = this.getView(); if (view) { - let size = undefined; - const computedStyle = getComputedStyle(this.viewport_); - if (computedStyle.width && computedStyle.height) { - size = [ - parseInt(computedStyle.width, 10), - parseInt(computedStyle.height, 10), - ]; - } view.setViewportSize(size); } } diff --git a/src/ol/View.js b/src/ol/View.js index 07cc0d28709..39ec72b70f4 100644 --- a/src/ol/View.js +++ b/src/ol/View.js @@ -74,9 +74,10 @@ import {fromExtent as polygonFromExtent} from './geom/Polygon.js'; /** * @typedef {Object} FitOptions - * @property {import("./size.js").Size} [size] The size in pixels of the box to fit - * the extent into. Default is the current size of the first map in the DOM that - * uses this view, or `[100, 100]` if no such map is found. + * @property {import("./size.js").Size} [size] The size in pixels of the box to + * fit the extent into. Defaults to the size of the map the view is associated with. + * If no map or multiple maps are connected to the view, provide the desired box size + * (e.g. `map.getSize()`). * @property {!Array} [padding=[0, 0, 0, 0]] Padding (in pixels) to be * cleared inside the view. Values in the array are top, right, bottom and left * padding. @@ -986,12 +987,12 @@ class View extends BaseObject { } /** - * Calculate the extent for the current view state and the passed size. - * The size is the pixel dimensions of the box into which the calculated extent - * should fit. In most cases you want to get the extent of the entire map, - * that is `map.getSize()`. - * @param {import("./size.js").Size} [size] Box pixel size. If not provided, the size - * of the map that uses this view will be used. + * Calculate the extent for the current view state and the passed box size. + * @param {import("./size.js").Size} [size] The pixel dimensions of the box + * into which the calculated extent should fit. Defaults to the size of the + * map the view is associated with. + * If no map or multiple maps are connected to the view, provide the desired + * box size (e.g. `map.getSize()`). * @return {import("./extent.js").Extent} Extent. * @api */