AnsweredAssumed Answered

Count all points in all polygons in a feature layer when map is loaded

Question asked by xupla on Apr 21, 2014
Latest reply on Apr 21, 2014 by kenbuja
I have two layers. One containing points and the other containing polygons.

I would like to count the number of points belonging to a polygon when the map loads for all the polygons in the feature layer using ArcGIS Javascript API. I have this functionality but it is affecting the performance of the map, since it is updating when the map is updated.

     var polygonFeature = new FeatureLayer("feature layer with polygons", {             mode: FeatureLayer.MODE_ONDEMAND,             outFields: ["*"]         });     map.on("update-end", function () {                     array.forEach(polygonFeature.graphics, function (feature) {                         var name = feature.attributes.NAME;                         var query = new Query();                         var queryTask = new QueryTask("feature layer with points");                         query.geometry = feature.geometry                         query.returnGeometry = true;                          queryTask.executeForCount(query, function (count) {                             console.log("Locality " + name + " has " + count + " points");                         });                     });                 });

Outcomes