Select to view content in your preferred language

Need some OnClick clarification

1076
2
Jump to solution
05-21-2012 12:34 PM
SteveCole
Honored Contributor
I'm building a small app that has a basemap and one featureLayer that has an infoWindow associated with it. When the user clicks on one of those features, I also need to retrieve the coordinates of the feature that the user clicked on. My understanding is that you can use the OnClick event with dojo.connect to do this:

       dojo.connect(map,"onClick",function(evt){    var query = new esri.tasks.Query();    query.geometry = pointToExtent(map,evt.mapPoint,10);     var deferred = theFeatureLayer.selectFeatures(query,esri.layers.FeatureLayer.SELECTION_NEW);     map.infoWindow.setFeatures([deferred]);    map.infoWindow.show(evt.mapPoint);     alert('Made it here!');    var pt = new esri.geometry.Point(evt.mapPoint.y,evt.mapPoint.x, new esri.SpatialReference({wkid:3857}));    var MercPt = esri.geometry.webMercatorToGeographic(evt.mapPoint);    var theLong = MercPt.x;    var theLat = MercPt.y;    var didSucceed = window.clipboardData.setData('Text', '@Coord:' + theLong.toString() + ',' + theLat.toString() );   });


If a user clicks on the map where there isn't a feature, the OnClick event captures it and I'm able to access the click point's coordinates. If they click on a feature, it seems to bypass the OnClick code (hence my small alert line in the code above). What's the best way to capture the coordinates of a clicked feature??

Thanks!
Steve
0 Kudos
1 Solution

Accepted Solutions
AR
by
Occasional Contributor
I'll give a stab at it-


Your dojo event handler is pointing to the map, not the feature layer. Do something like:

dojo.connect(featurelayer, "onClick", function(evt){  console.log(evt)  })


Let me know if this works.

View solution in original post

0 Kudos
2 Replies
AR
by
Occasional Contributor
I'll give a stab at it-


Your dojo event handler is pointing to the map, not the feature layer. Do something like:

dojo.connect(featurelayer, "onClick", function(evt){  console.log(evt)  })


Let me know if this works.
0 Kudos
SteveCole
Honored Contributor
GENIUS!

I feel so dumb. Thanks- that was the problem!
0 Kudos