0

I am doing a map which refresh dinamically all markers when they get modified. I want to add popups to show some info.

I create popups this way:

        var feature = new OpenLayers.Feature(markers, location); //location = lonlat
        feature.closeBox = true;
        feature.popupClass = OpenLayers.Class(OpenLayers.Popup.FramedCloud, {
        'autoSize': true
    });;
        feature.data.popupContentHTML = "info"; 
        feature.data.overflow = (false) ? "auto" : "hidden";        
            var markerClick = function (evt) {
            if (this.popup == null) {
                this.popup = this.createPopup(this.closeBox);
                map.addPopup(this.popup);
                this.popup.show();
            } else {
                this.popup.toggle();
            }
            currentPopup = this.popup;
            OpenLayers.Event.stop(evt);
        };
        mark.events.register("mousedown", feature, markerClick);

Now, I have the problem about what to do if one of my markers update its info. How can I destroy the popup? (I will create other one) or how can I modifiy it? Can I access them using lonlat?

Sometimes, I want to delete all of them, is there a way to do that? like deleting a layer or something?

2 Answers 2

6

for getting one popup info, you should do this:

map.popups[0]; // the firstly added popup

for removing one popup:

map.removePopup(map.popups[0]); // it will destroy firstly added popup
map.popups[0].destroy() // the same thing

for removing all popup from maps:

var pops = map.popups;
for(var a = 0; a < pops.length; a++){
   map.removePopup(map.popups[a]);
};

for hiding and showing popups:

map.popups[0].hide()
map.popups[0].show()

for finding popups from lonlat, you can get info for looping it in for loop and if clause:

map.popups[0].lonlat.lon
map.popups[0].lonlat.lat

and you can get the last popup with following code:

map.popups[0].getLast()

this all information is some part of Openlayers popup element...there are lots of thing you can do with popups...

i hope it helps you

-2

Did you take a look at the OpenLayers.Map documentation? All popups are accessible from the "map" variable.

http://dev.openlayers.org/docs/files/OpenLayers/Map-js.html#OpenLayers.Map.popups

1
  • 1
    it would be better if you could explain the answer rather than just providing a link
    – Sam007
    Commented Jun 5, 2012 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.