user1396008
user1396008

Reputation:

displaying openlayer marker

here am using the Google markers and getting up the latitude and longitude values and displaying the Google place markers using open-layer markers here is the piece of code

function googleMarker(name, lat, lng, address, types, iconImage)
{       
    var nameLength = name.length;       
    nameLength = nameLength+120;
    var lonLat = new OpenLayers.LonLat( lng ,lat ).transform(new OpenLayers.Projection("EPSG:4326"),map.getProjectionObject());                         
    trackMarkers = new OpenLayers.Layer.Markers("Markers");
    var size = new OpenLayers.Size(20, 20);
    var offset = new OpenLayers.Pixel(-(size.w / 2), -(size.h / 2));                        
    var icon = new OpenLayers.Icon(iconImage, size, offset);                                        
    map.addLayer(trackMarkers);
    trackMarker = new OpenLayers.Marker(lonLat, icon);
    trackMarkers.addMarker(trackMarker);        

    trackMarker.events.register('click', trackMarker, function(evt) 
    {   
        popup = new OpenLayers.Popup.FramedCloud("featurePopup",lonLat, null,'<div style="color:#FF0000;">'+name+","+address + '</div>', null, null);                                       
        map.addPopup(popup);                                    
    });         
}

here is the parsed and projected onto the open layer, the issue which i am facing is how to remove the previously enabled popup before selecting the next marker and clicking on the map this popup should get dismissed.

enter image description here

Upvotes: 0

Views: 655

Answers (1)

AnthonyLeGovic
AnthonyLeGovic

Reputation: 2335

According to OpenLayers documentation here you can specify it in your addPopup() call :

addPopup: function(popup, exclusive)
Parameters:    popup        {OpenLayers.Popup}
               exclusive    {Boolean} If true, closes all other popups first

So in your case, change your addPopup call in last lines by :

map.addPopup(popup, true);

Edit : If you want to remove all your popups when you click on map, you can do it this way :

map.events.register("click", map , function(e){ 
   while(map.popups.length){
      map.removePopup(map.popups[0]);
   } 
}); 

after your map was initialized

Upvotes: 0

Related Questions