[OpenLayers-Users] Re: Destroying old popup before crating new one
Greg Allensworth
gregor at greeninfo.org
Fri Feb 17 11:48:32 EST 2012
On 2/17/2012 4:47 AM, Francesc Cañas wrote:
> Hi, where I have to put the code? I've tried but unsuccess...
I would structure it like this:
var POPUP; // global scope
function deletePopup() {
if (! POPUP) return;
map.removePopup(POPUP);
POPUP.destroy();
POPUP = null;
}
// GetfeatureInfo...
eventListeners: {
getfeatureinfo: function(event) {
deletePopup();
POPUP = new OpenLayers.Popup.FramedCloud(...);
map.addPopup(POPUP);
}
}
There's probably no substantial benefit of a global POPUP variable
versus iterating over map.popups, but I find it more easily readable.
The separation of deletePopup() into its own function, allows us to
close the popup from other program code without repeating code.
--
Greg Allensworth, Web GIS Developer
BS A+ Network+ Security+ Linux+ Server+
GreenInfo Network - Information and Mapping in the Public Interest
564 Market Street, Suite 510 San Francisco CA 94104
PH: 415-979-0343 x302 FX: 415-979-0371 email: gregor at greeninfo.org
Web: www.GreenInfo.org www.MapsPortal.org
Subscribe to MapLines, our e-newsletter, at www.GreenInfo.org
More information about the Users
mailing list