From ad40db89af53b5cd70f7e884d8ff7de887bbdb1a Mon Sep 17 00:00:00 2001 From: euzuro Date: Thu, 15 Nov 2007 14:54:18 +0000 Subject: [PATCH] Fix for addPopup()'s 'exclusive' option -- reworking of the for loop to make sure all popups are removed without error. Great find on this by li ethan and excellent work turning it into a patch by fredj. Once again, open source prevails. Thanks everyone. All tests pass FF/IE6. (Closes #1149) git-svn-id: http://svn.openlayers.org/trunk/openlayers@5187 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Map.js | 2 +- tests/test_Map.html | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index ba1c0c9779..34f124d51e 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -836,7 +836,7 @@ OpenLayers.Map = OpenLayers.Class({ if (exclusive) { //remove all other popups from screen - for(var i=0; i < this.popups.length; i++) { + for (var i = this.popups.length - 1; i >= 0; --i) { this.removePopup(this.popups[i]); } } diff --git a/tests/test_Map.html b/tests/test_Map.html index ff0f333c07..d14375da72 100644 --- a/tests/test_Map.html +++ b/tests/test_Map.html @@ -162,7 +162,34 @@ } } t.ok(!found, "popup.div successfully removed from the map's viewPort"); - }; + } + + function test_Map_add_popup_exclusive(t) { + t.plan(2); + + map = new OpenLayers.Map('map'); + var baseLayer = new OpenLayers.Layer.WMS("Test Layer", + "http://octo.metacarta.com/cgi-bin/mapserv?", + {map: "/mapdata/vmap_wms.map", layers: "basic"}); + map.addLayer(baseLayer); + + map.setCenter(new OpenLayers.LonLat(0, 0), 0); + + for (var i = 0; i < 10; i++) { + var popup = new OpenLayers.Popup("chicken", + new OpenLayers.LonLat(0,0), + new OpenLayers.Size(200,200)); + map.addPopup(popup); + } + t.eq(map.popups.length, 10, "addPopup non exclusive mode works"); + + var popup = new OpenLayers.Popup("chicken", + new OpenLayers.LonLat(0,0), + new OpenLayers.Size(200,200)); + map.addPopup(popup, true); + t.eq(map.popups.length, 1, "addPopup exclusive mode works"); + } + /*** THIS IS A GOOD TEST, BUT IT SHOULD BE MOVED TO WMS. * Also, it won't work until we figure out the viewSize bug