[OpenLayers-Users] Removing popups with clicks on map

Robert Buzink post at robertbuzink.nl
Sun Feb 4 06:23:38 EST 2007


hi Alex,

You can find a way to pick up a clickevent in the map at
http://openlayers.org/dev/examples/click.htm :

map.events.register("click", map, function(e) {
                var lonlat = map.getLonLatFromViewPortPx(e.xy);
                alert("You clicked near " + lonlat.lat + " N, " +
                                          + lonlat.lon + " E");
            });


You can change the alert part to a destroy popup code. You should know
though that the code you've written destroys a specific popup, named
'popup'. The add function in this example could also have been:

daspop = new OpenLayers.Popup("chicken",
                                         new OpenLayers.LonLat(5,40),
                                         new OpenLayers.Size(200,200),
                                         "example popup",
                                         true);

            map.addPopup(daspop);


In which case the destroy code would have been:

markers.map.removePopup(daspop);
                daspop.destroy();
                daspop = null;


In other words, in your code you will have to find out the name of the popup
that is being shown, before you can destroy it. I have no idea how you
should do that. Maybe someone else could answer that (or correct me when I'm
wrong)?

On 2/2/07, Alexandre Leroux <alexandre.leroux at ec.gc.ca> wrote:
>
>
> Hi list,
>
> I'm using OpenLayers.Layer.Text to plot some markers. I'd like popups to
> disappear when a click on the map is done. Right now, the popup
> disappear only if (1) another markers is selected and a new popup first
> this second marker is shown, or if (2) the marker is clicked again. This
> is not convenient to me.
>
> I looked at the popups.html example provided. I simply added the destroy
> popup code.
>
> In my map div I added:
> <div id="map" onclick="destroy()"></div>
>
> and in my script section:
> function destroy() {
>             popup.destroy();
>         }
>
> But it does not work. Any idea why? It there another way to remove
> popups on clicks? Should I open a ticket?
>
> Thanks & have a great Friday!
>
> Alex :-)
>
> --
> Alexandre Leroux, M.Sc., Ing.
> Environnement Canada / Environment Canada
> Centre météorologique canadien / Canadian Meteorological Centre
> Division de la réponse aux urgences environnementales /
> Environmental Emergency Response Division
> alexandre.leroux at ec.gc.ca
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>



-- 
Robert Buzink, website ontwerp en ontwikkeling
Sint-Pietersaalststraat 123
9000 Gent
+32 (0)9 33 00 267
+32 (0)487 548 414
post at robertbuzink.nl
robertbuzink.nl/webdesign
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20070204/b6a88ba7/attachment.html


More information about the Users mailing list