[OpenLayers-Users] Help dealing with popup clicks verse clickhandlers

小粟 weimin_su at 126.com
Tue May 27 01:42:23 EDT 2008


   Hope this is useful!

 var feature, popup;
    var contentHTML;
    var marker, markers;

function addMarker(lon, lat, cHtml) 
  {
      if(markers == null)
      {
          markers = new OpenLayers.Layer.Markers("热点层");
          map.addLayer(markers);
      }

      if(feature != null)
      {
          feature.destroy();
          if(popup != null)
          {
              popup.destroy();
              popup = null;             
          }
      }
      feature = new OpenLayers.Feature(layer, new OpenLayers.LonLat(lon, lat));
      //feature.closeBox = false;
      feature.popupClass = OpenLayers.Popup.FramedBubbleM2Ex;
      //feature.popupClass = OpenLayers.Popup.FramedCloud;
      var markerIcon = new OpenLayers.Icon("mainimg/marker.gif", new OpenLayers.Size(37.5,37.5));
      if(marker == null)
      {
        marker = feature.createMarker();
        //marker.icon = markerIcon;
      }
      else
      {
        markers.removeMarker(marker);
        marker = feature.createMarker();
        //marker.icon = markerIcon;
      }
      
      markers.addMarker(marker);
      contentHTML = cHtml;
      marker.events.register("mousedown", marker, mousedown);
  }
        
  function mousedown(evt) {
      if (popup == null) {
      popup = feature.createPopup(true);
      popup.setContentHTML(contentHTML);
      markers.map.addPopup(popup);
      } else {
          popup.toggle();
      }

      OpenLayers.Event.stop(evt);
  } 

----- Original Message ----- 
From: "Stephen Woodbridge" <woodbri at swoodbridge.com>
To: "openlayers user list" <users at openlayers.org>
Sent: Tuesday, May 27, 2008 8:11 AM
Subject: [OpenLayers-Users] Help dealing with popup clicks verse clickhandlers


> Hi all,
> 
> I have a marker layer that which is working great. I just added a click 
> handler that reverse geocodes on a click and adds a marker at the click 
> point and populates the popup with the XML  response. This is all 
> working great EXCEPT that when I click on the icons to open or close a 
> popup, that click is propagating to the click handler causing another 
> marker to be added.
> 
> How to I control or stop this?
> 
> Thanks,
>   -Steve W
> 
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users


More information about the Users mailing list