[OpenLayers-Users] Click Event

Brian Krebs bkrebs at korterra.com
Wed Apr 4 12:38:57 EDT 2007


I implemented the click example(click.html) to capture the position of
the click and place a marker there.  I only want it to do this on a
single click, but it is also being called at the end of a pan upon
mouseup and also when I click on the zoom bar anywhere in between + and
-.  Is there anyway to disable the click event during these actions?

 

Here is the code where the click event is being registered:

 

function initializeMapStart(Lon, Lat, Zoom)

{

      layerData.maxExtent = new OpenLayers.Bounds(-94.807800, 35.638191,
-94.472656, 36.161896);

    

      var options = 

            { 

                  'controls':[],

                  'maxExtent': layerData.maxExtent,

                  'maxResolution': 'auto',

                  scales: [2000000, 1000000, 500000, 250000, 125000,
62500, 31250, 15625, 7812, 3906, 1953],

                  projection: 'EPSG:4326',

                  'tileSize': new OpenLayers.Size(200, 200)

            };

      openLayersMap = new OpenLayers.Map('mapDiv', options);

    

      OpenLayers.Util.onImageLoadErrorColor = null;

      

    //Base layer

      layer = new OpenLayers.Layer.KaMap('basemap',

                  kamapUrl,

                  { 

                        'map': 'oklahoma', 

                        'g': 'all', 

                        'i': 'gif'

                  },

                  {

                        'buffer': 1

                  }

            );

      layer.displayOutsideMaxExtent = true;

      openLayersMap.addLayer(layer);

      

      //Marker layer

      var markersLayer = new OpenLayers.Layer.Markers("Locate");

      if (Lon != 0.0 && Lat != 0.0)

      {

        var marker = new OpenLayers.Marker(new OpenLayers.LonLat(Lon,
Lat), new
OpenLayers.Icon("http://kormap/MapService/Images/okiemarker.png", new
OpenLayers.Size(30,60)));

        markersLayer.addMarker(marker);

        openLayersMap.addLayer(markersLayer); 

        var markerbounds = new OpenLayers.Bounds(Lon, Lat, Lon, Lat);

        var newLonLat = markerbounds.getCenterLonLat();

        openLayersMap.setCenter(newLonLat, Zoom);

    }

    

    if (Zoom == 0)

        zoomToExtent(markerbounds);

        

THE CLICK EVENT

    openLayersMap.events.register("click", openLayersMap, function(e) 

    { 

        markersLayer.clearMarkers();

        var lonlat = openLayersMap.getLonLatFromViewPortPx(e.xy);

        var marker = new OpenLayers.Marker(new
OpenLayers.LonLat(lonlat.lon, lonlat.lat), new
OpenLayers.Icon("http://kormap/MapService/Images/okiemarker.png", new
OpenLayers.Size(30,60)));

//        alert("You clicked " + lonlat.lon + ", " + lonlat.lat);

        markersLayer.addMarker(marker);

        openLayersMap.addLayer(markersLayer);  

        

        document.forms[0].txtLatitude.value = lonlat.lat;

        document.forms[0].txtLongitude.value = lonlat.lon;

    });

 

}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20070404/57c821d6/attachment.html


More information about the Users mailing list