[OpenLayers-Dev] Remove ALL popups

Martijn van Oosterhout kleptog at gmail.com
Fri Feb 22 10:56:33 EST 2008


2008/2/21 Leandro R <learonco at gmail.com>:
> The problem comes here: there is another function that removes all the
> markers and popups. The markers are correctly removed but the popups not.
> There is always one that is not removed. I have to run the function twice.

Your problem is that you have a counter i looping over an array while
you are removing stuff from it. The way I read it it will remove half
the popups each time.

You want a while loop, something like:

> function limpiarMapa() {
>     markerlyr.clearMarkers();
>     alert(map.popups.length);
>     while( map.popups.length ) {
>         map.removePopup(map.popups[0]);
>     }
>     alert(map.popups.length);
>  }

Have a nice day,
-- 
Martijn van Oosterhout <kleptog at gmail.com> http://svana.org/kleptog/



More information about the Dev mailing list