Be more tolerant of map and position value

The `map` property type is `ol.Map|undefined` but `null` is set when
removing the overlay from the map:
https://github.com/openlayers/openlayers/blob/v3.20.1/src/ol/map.js#L453

This raise an exception with:
```js
map.removeOverlay(overlay);
overlay.setPosition(undefined);
```

Because `map === undefined` is used in `ol.Overlay.setPosition`
This commit is contained in:
Frederic Junod
2017-01-23 16:48:36 +01:00
parent 7f39b22161
commit 6605669cb6

View File

@@ -271,7 +271,7 @@ ol.Overlay.prototype.handleOffsetChanged = function() {
*/
ol.Overlay.prototype.handlePositionChanged = function() {
this.updatePixelPosition();
if (this.get(ol.Overlay.Property_.POSITION) !== undefined && this.autoPan) {
if (this.get(ol.Overlay.Property_.POSITION) && this.autoPan) {
this.panIntoView_();
}
};
@@ -339,7 +339,7 @@ ol.Overlay.prototype.setPosition = function(position) {
ol.Overlay.prototype.panIntoView_ = function() {
var map = this.getMap();
if (map === undefined || !map.getTargetElement()) {
if (!map || !map.getTargetElement()) {
return;
}
@@ -442,7 +442,7 @@ ol.Overlay.prototype.setVisible = function(visible) {
ol.Overlay.prototype.updatePixelPosition = function() {
var map = this.getMap();
var position = this.getPosition();
if (map === undefined || !map.isRendered() || position === undefined) {
if (!map || !map.isRendered() || !position) {
this.setVisible(false);
return;
}