Skip to content

Commit

Permalink
Merge pull request #15269 from simonseyock/fix-update-viewport-size
Browse files Browse the repository at this point in the history
fix(Map): use same size calculation in `updateSize` and `updateViewportSize_`
  • Loading branch information
ahocevar committed Oct 26, 2023
2 parents aa5e3ab + 6c3a403 commit 226f0cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
15 changes: 4 additions & 11 deletions src/ol/Map.js
Expand Up @@ -1367,7 +1367,7 @@ class Map extends BaseObject {
}
const view = this.getView();
if (view) {
this.updateViewportSize_();
this.updateViewportSize_(this.getSize());

this.viewPropertyListenerKey_ = listen(
view,
Expand Down Expand Up @@ -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);
}
}
Expand Down
19 changes: 10 additions & 9 deletions src/ol/View.js
Expand Up @@ -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<number>} [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.
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 226f0cf

Please sign in to comment.