简体   繁体   中英

how to get a Popup by id in OpenLayers map

When initial the map, I created many popup for features

var popup= new OpenLayers.Popup.FramedCloud(
    id, //id
    new OpenLayers.LonLat(msg.reviseLng, msg.reviseLat),
    new OpenLayers.Size(160,100),
    '<html></html>',
    null,
    true);
    popup.autoSize=false;
    map.addPopup(popup);

but I can not get a exist popup when I location a point ,I want get it by it's id and show it, please help me

The idea should be: when the user click on a certain point recognized by you, the popup should be displayed, isn't it?

You can do it in this way:

map.events.register("click", map , function(e){
   // Look for point... (your code)

   // Point detected!

   // now we need to take the popup identified by 'popupid' identifier and show it
   for(var i=0; i<map.popups.length; i++){
      if(map.popups[i].id == myid){
         map.popups[i].show();
         break;
      }
   }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM