Invalid size set when map is not added to document
Parsing of an empty string with parseFloat resulted in NaN.
This commit is contained in:
@@ -1496,9 +1496,8 @@ class PluggableMap extends BaseObject {
|
|||||||
updateSize() {
|
updateSize() {
|
||||||
const targetElement = this.getTargetElement();
|
const targetElement = this.getTargetElement();
|
||||||
|
|
||||||
if (!targetElement) {
|
let size = undefined;
|
||||||
this.setSize(undefined);
|
if (targetElement) {
|
||||||
} else {
|
|
||||||
const computedStyle = getComputedStyle(targetElement);
|
const computedStyle = getComputedStyle(targetElement);
|
||||||
const width =
|
const width =
|
||||||
targetElement.offsetWidth -
|
targetElement.offsetWidth -
|
||||||
@@ -1512,15 +1511,18 @@ class PluggableMap extends BaseObject {
|
|||||||
parseFloat(computedStyle['paddingTop']) -
|
parseFloat(computedStyle['paddingTop']) -
|
||||||
parseFloat(computedStyle['paddingBottom']) -
|
parseFloat(computedStyle['paddingBottom']) -
|
||||||
parseFloat(computedStyle['borderBottomWidth']);
|
parseFloat(computedStyle['borderBottomWidth']);
|
||||||
if (height === 0 || width === 0) {
|
if (!isNaN(width) && !isNaN(height)) {
|
||||||
|
size = [width, height];
|
||||||
|
if (!hasArea(size)) {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
console.warn(
|
console.warn(
|
||||||
"No map visible because the map container's width or height are 0."
|
"No map visible because the map container's width or height are 0."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
this.setSize([width, height]);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.setSize(size);
|
||||||
this.updateViewportSize_();
|
this.updateViewportSize_();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -687,6 +687,7 @@ describe('ol.Map', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('#setTarget', function () {
|
describe('#setTarget', function () {
|
||||||
|
/** @type {Map|undefined} */
|
||||||
let map;
|
let map;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
@@ -696,6 +697,12 @@ describe('ol.Map', function () {
|
|||||||
expect(map.handleResize_).to.be.ok();
|
expect(map.handleResize_).to.be.ok();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('map with target not attached to dom', function () {
|
||||||
|
it('has undefined as size with target not in document', function () {
|
||||||
|
expect(map.getSize()).to.be(undefined);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('call setTarget with null', function () {
|
describe('call setTarget with null', function () {
|
||||||
it('unregisters the viewport resize listener', function () {
|
it('unregisters the viewport resize listener', function () {
|
||||||
map.setTarget(null);
|
map.setTarget(null);
|
||||||
|
|||||||
Reference in New Issue
Block a user