Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I've got a simple map with a set of 10 markers on it. When they are clicked an infoWindow appears however I would like to instead display the data in the infoWindow in a table. How do I find out which marker was clicked?

This is the code I'm using to determine which marker was clicked:

          // Find the identity of the marker that was clicked
          featureLayer.clearSelection();
          var selectQuery = new esri.tasks.Query();
          var tol = map.extent.getWidth()/map.width * 10;
          var x = evt.mapPoint.x;
          var y = evt.mapPoint.y;
          var queryExtent = new esri.geometry.Extent(x-tol,y-tol,x+tol,y+tol,evt.mapPoint.spatialReference);
          selectQuery.geometry = queryExtent;
          var t = featureLayer.selectFeatures(selectQuery,esri.layers.FeatureLayer.SELECTION_NEW);
          console.log(t.results[0][0][0].attributes);

This partially works, however when the map zooms out this code will sometimes the wrong marker information. I'm thinking that I can change the queryExtent variable to account for the zoom level of the map. Does anyone know if this would work?

Thank you for reading this question and hopefully someone more experienced than myself can help.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

sorry but I couldn't reproduce it. But anyway, there is more easier way to get clicked feature from FeatureLayer. this is sample code

dojo.connect(featureLayer, "onClick", function (evt) {
    var graphicAttributes = evt.graphic.attributes;
    //do anything ...
});
share|improve this answer
    
That works perfectly! Thank you so much for taking the time to answer. –  oborden2 Apr 15 '13 at 1:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.