Merge pull request #12028 from MoonE/overview-map-no-initial-target
Overview map no initial target
This commit is contained in:
+11
-9
@@ -1480,9 +1480,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 -
|
||||||
@@ -1496,15 +1495,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)) {
|
||||||
// eslint-disable-next-line
|
size = [width, height];
|
||||||
console.warn(
|
if (!hasArea(size)) {
|
||||||
"No map visible because the map container's width or height are 0."
|
// eslint-disable-next-line
|
||||||
);
|
console.warn(
|
||||||
|
"No map visible because the map container's width or height are 0."
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.setSize([width, height]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.setSize(size);
|
||||||
this.updateViewportSize_();
|
this.updateViewportSize_();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -306,6 +306,10 @@ class OverviewMap extends Control {
|
|||||||
this.resetExtent_();
|
this.resetExtent_();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.ovmap_.isRendered()) {
|
||||||
|
this.updateBoxAfterOvmapIsRendered_();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,6 +326,11 @@ class OverviewMap extends Control {
|
|||||||
}
|
}
|
||||||
const newView = this.getMap().getView();
|
const newView = this.getMap().getView();
|
||||||
this.bindView_(newView);
|
this.bindView_(newView);
|
||||||
|
} else if (
|
||||||
|
!this.ovmap_.isRendered() &&
|
||||||
|
(event.key === MapProperty.TARGET || event.key === MapProperty.SIZE)
|
||||||
|
) {
|
||||||
|
this.ovmap_.updateSize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -514,6 +523,24 @@ class OverviewMap extends Control {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
updateBoxAfterOvmapIsRendered_() {
|
||||||
|
if (this.ovmapPostrenderKey_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.ovmapPostrenderKey_ = listenOnce(
|
||||||
|
this.ovmap_,
|
||||||
|
MapEventType.POSTRENDER,
|
||||||
|
function (event) {
|
||||||
|
delete this.ovmapPostrenderKey_;
|
||||||
|
this.updateBox_();
|
||||||
|
},
|
||||||
|
this
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {MouseEvent} event The event to handle
|
* @param {MouseEvent} event The event to handle
|
||||||
* @private
|
* @private
|
||||||
@@ -546,14 +573,7 @@ class OverviewMap extends Control {
|
|||||||
}
|
}
|
||||||
ovmap.updateSize();
|
ovmap.updateSize();
|
||||||
this.resetExtent_();
|
this.resetExtent_();
|
||||||
listenOnce(
|
this.updateBoxAfterOvmapIsRendered_();
|
||||||
ovmap,
|
|
||||||
MapEventType.POSTRENDER,
|
|
||||||
function (event) {
|
|
||||||
this.updateBox_();
|
|
||||||
},
|
|
||||||
this
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -245,7 +245,7 @@
|
|||||||
}
|
}
|
||||||
.ol-overviewmap .ol-overviewmap-map,
|
.ol-overviewmap .ol-overviewmap-map,
|
||||||
.ol-overviewmap button {
|
.ol-overviewmap button {
|
||||||
display: inline-block;
|
display: block;
|
||||||
}
|
}
|
||||||
.ol-overviewmap .ol-overviewmap-map {
|
.ol-overviewmap .ol-overviewmap-map {
|
||||||
border: 1px solid #7b98bc;
|
border: 1px solid #7b98bc;
|
||||||
@@ -253,8 +253,8 @@
|
|||||||
margin: 2px;
|
margin: 2px;
|
||||||
width: 150px;
|
width: 150px;
|
||||||
}
|
}
|
||||||
.ol-overviewmap:not(.ol-collapsed) button{
|
.ol-overviewmap:not(.ol-collapsed) button {
|
||||||
bottom: 1px;
|
bottom: 2px;
|
||||||
left: 2px;
|
left: 2px;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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