From 6455c920f69a5112a01fc8ed22bb52ed4b945f8e Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Tue, 28 Jan 2014 14:35:44 +0100 Subject: [PATCH 1/2] Make ol.Map#isDef checking stricter --- src/ol/map.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/ol/map.js b/src/ol/map.js index 1d4d518539..e53a1f3477 100644 --- a/src/ol/map.js +++ b/src/ol/map.js @@ -969,12 +969,27 @@ ol.Map.prototype.handleLayerGroupChanged_ = function() { /** + * Returns `true` if the map is defined, `false` otherwise. The map is defined + * if it is contained in `document`, visible, has non-zero height and width, and + * has a defined view. * @return {boolean} Is defined. */ ol.Map.prototype.isDef = function() { + if (!goog.dom.contains(document, this.viewport_)) { + return false; + } + if (!goog.style.isElementShown(this.viewport_)) { + return false; + } + var size = this.getSize(); + if (!goog.isDefAndNotNull(size) || size[0] <= 0 || size[1] <= 0) { + return false; + } var view = this.getView(); - return goog.isDef(view) && view.isDef() && - goog.isDefAndNotNull(this.getSize()); + if (!goog.isDef(view) || !view.isDef()) { + return false; + } + return true; }; From 4beb48fa3d41231106d5fad33251fd7b01087210 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Tue, 28 Jan 2014 14:37:38 +0100 Subject: [PATCH 2/2] Assert that pixel is non-null when positioning overlay --- src/ol/overlay.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ol/overlay.js b/src/ol/overlay.js index bd81f321c7..17081ba375 100644 --- a/src/ol/overlay.js +++ b/src/ol/overlay.js @@ -335,6 +335,7 @@ ol.Overlay.prototype.updatePixelPosition_ = function() { } var pixel = map.getPixelFromCoordinate(position); + goog.asserts.assert(!goog.isNull(pixel)); var mapSize = map.getSize(); goog.asserts.assert(goog.isDef(mapSize)); var style = this.element_.style;