Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Map): use same size calculation in updateSize and updateViewportSize_ #15269

Merged
merged 4 commits into from Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
8 changes: 5 additions & 3 deletions src/ol/View.js
Expand Up @@ -74,9 +74,11 @@ 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. If the view is associated with one map, it defaults to
* the size of the map. If it is associated with multiple maps, the size can be
* of any one of the maps, so the desired size should be specified. If no map
* is associated it uses `[100, 100]` as the size.
simonseyock marked this conversation as resolved.
Show resolved Hide resolved
* @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