Solved! Go to Solution.
map.on("extent-change", function(extent){ var query = new Query(); query.geometry = extent.extent; flayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(result){ console.log(result.length);//This is the number of features in current view }); });
yourFeatureLayerVar.graphics.length;
map.on("extent-change", function(extent){ var query = new Query(); query.geometry = extent.extent; flayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(result){ console.log(result.length);//This is the number of features in current view }); });
dojo.connect(featureLayer, "update-end", function(evt) {...});
map.on("extent-change", function() { //var len=Object.keys(featureLayer.toJson().featureSet.features).length; //alert("hi="+len); alert(featureLayer.graphics.length); });
Thanks for all the responses!
I tried update-end event but it is not getting called.dojo.connect(featureLayer, "update-end", function(evt) {...});
also tried extent-change event on map as below, but it is giving me total events...map.on("extent-change", function() { //var len=Object.keys(featureLayer.toJson().featureSet.features).length; //alert("hi="+len); alert(featureLayer.graphics.length); });
I am just trying to count the no. of attributes value of the layers drawn on a map and if we move the move then the layers on that map will change, so the count should also change.
Thanks all for your help!
dojo.connect(featureLayer, "onUpdateEnd", function(evt) {...});
on(featureLayer, "update-end", function(evt) {...});
I am just trying to count the no. of attributes value of the layers drawn on a map and if we move the move then the layers on that map will change, so the count should also change.
map.on("extent-change", function(extent){ var query = new Query(); query.geometry = extent.extent; flayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(result){ var count = 0; array.forEach(result, function(feature){ count = count + feature.attributes.YOURFIELD; }); console.log(count); }); });
All you need to do is to count how many graphics are present on the layer each time you change the extent.
To be able to do that, you have to initialize your FeatureLayer with mode set to MODE_ONDEMAND - it will get all features from current extent on every extent change.
Then, you need to listen to "update-end" event on the layer. Each time the event fires, you can fill your counter's innerHTML with following value:yourFeatureLayerVar.graphics.length;
dojo.connect(featureLayer, "onUpdateEnd", function(evt) { //alert(featureLayer.toJson()); alert("graphics len="+featureLayer.graphics.length);
In that case you need to iterate through the selectFeatures callback result, something like this:map.on("extent-change", function(extent){ var query = new Query(); query.geometry = extent.extent; flayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(result){ var count = 0; array.forEach(result, function(feature){ count = count + feature.attributes.YOURFIELD; }); console.log(count); }); });
featureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(result){ alert("inside"); var count = 0; array.forEach(result, function(feature){ count = count + feature.attributes.CustomersAffected; }); alert("CustomersAffected="+count); });
Hello Johnathan,
I tried above code which is getting called on every drag of a map, but it is not going inside below code.featureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(result){ alert("inside"); var count = 0; array.forEach(result, function(feature){ count = count + feature.attributes.CustomersAffected; }); alert("CustomersAffected="+count); });