1

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.

1

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 ...
});
  • That works perfectly! Thank you so much for taking the time to answer. – oborden2 Apr 15 '13 at 1:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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