diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index a739a642ae..9953738693 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -161,15 +161,15 @@ OpenLayers.Map.prototype = { /** * @param {OpenLayers.Popup} popup - * @param {OpenLayers.Pixel} px */ - addPopup: function(popup, px) { + addPopup: function(popup) { this.popups.push(popup); + var px = this.getPixelFromLonLat(popup.lonlat) var popupDiv = popup.draw(px); if (popupDiv) { popupDiv.style.zIndex = this.Z_INDEX_BASE['Popup'] + this.popups.length; - this.viewPortDiv.appendChild(popupDiv); + this.layerContainerDiv.appendChild(popupDiv); } }, @@ -179,7 +179,7 @@ OpenLayers.Map.prototype = { removePopup: function(popup) { this.popups.remove(popup); if (popup.div) { - this.viewPortDiv.removeChild(popup.div); + this.layerContainerDiv.removeChild(popup.div); } }, @@ -325,6 +325,14 @@ OpenLayers.Map.prototype = { if (zoomChanged != null) { // reset the layerContainerDiv's location this.layerContainerDiv.style.left = "0px"; this.layerContainerDiv.style.top = "0px"; + + //redraw popups + for (var i = 0; i < this.popups.length; i++) { + var popup = this.popups[i]; + var px = this.getPixelFromLonLat(popup.lonlat); + popup.moveTo(px); + } + } var bounds = this.getExtent(); for (var i = 0; i < this.layers.length; i++) { diff --git a/popups.html b/popups.html index 1ce33a8f2a..5bdb4ec9e6 100644 --- a/popups.html +++ b/popups.html @@ -36,10 +36,11 @@ function add() { popup = new OpenLayers.Popup("chicken", + new OpenLayers.LonLat(5,40), new OpenLayers.Size(200,200), "example popup"); - map.addPopup(popup, new OpenLayers.Pixel(50,50)); + map.addPopup(popup); } function destroy() { diff --git a/tests/test_Map.html b/tests/test_Map.html index 872e2f9fc6..d22df6e34b 100644 --- a/tests/test_Map.html +++ b/tests/test_Map.html @@ -80,12 +80,14 @@ map = new OpenLayers.Map('map'); var popup = new OpenLayers.Popup("chicken", + new OpenLayers.LonLat(0,0), new OpenLayers.Size(200,200)); + map.setCenter(new OpenLayers.LonLat(0, 0), 0); - map.addPopup(popup, new OpenLayers.Pixel(20,20)); + map.addPopup(popup); t.eq(map.popups.indexOf(popup), 0, "popup successfully added to Map's internal popups array"); - - var nodes = map.viewPortDiv.childNodes; + + var nodes = map.layerContainerDiv.childNodes; var found = false; for (var i=0; i < nodes.length; i++) { @@ -108,8 +110,6 @@ } } t.ok(!found, "popup.div successfully removed from the map's viewPort"); - - } function test_08_Map_px_lonlat_translation (t) {