From aa7058703359862c78a3a698b81d95afe5ecec8a Mon Sep 17 00:00:00 2001 From: crschmidt Date: Wed, 12 Sep 2007 20:48:28 +0000 Subject: [PATCH] Prevent popups from failing when getLayerPxFromLonLat returns null (which is possible in the case of a not-yet-setup layer, for example). git-svn-id: http://svn.openlayers.org/trunk/openlayers@4251 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Popup.js | 4 +++- tests/test_Popup.html | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/OpenLayers/Popup.js b/lib/OpenLayers/Popup.js index ffd074e691..156d423546 100644 --- a/lib/OpenLayers/Popup.js +++ b/lib/OpenLayers/Popup.js @@ -226,7 +226,9 @@ OpenLayers.Popup = OpenLayers.Class({ updatePosition: function() { if ((this.lonlat) && (this.map)) { var px = this.map.getLayerPxFromLonLat(this.lonlat); - this.moveTo(px); + if (px) { + this.moveTo(px); + } } }, diff --git a/tests/test_Popup.html b/tests/test_Popup.html index d16249bafa..e2484c860e 100644 --- a/tests/test_Popup.html +++ b/tests/test_Popup.html @@ -51,6 +51,19 @@ t.eq(popup.contentHTML, content, "contentHTML porpoerty of set correctly"); } + function test_Popup_updatePosition(t) { + t.plan(1) + var map = new OpenLayers.Map('map'); + map.addLayer(new OpenLayers.Layer('name', {'isBaseLayer':true})); + map.zoomToMaxExtent(); + var popup = new OpenLayers.Popup('id'); + map.addPopup(popup); + map.getLayerPxFromLonLat = function () { return null; } + popup.moveTo=function() { t.fail("Shouldnt' call moveTo if layerpx is null"); } + popup.lonlat = true; + popup.updatePosition(); + t.ok(true, "update position doesn't fail when getLayerPxFromLonLat fails."); + } function test_03_Popup_draw(t) { t.plan( 17 ); @@ -109,5 +122,6 @@ +