<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Count featurelayer attributes displayed in a map in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-featurelayer-attributes-displayed-in-a-map/m-p/309796#M28499</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;All you need to do is to count how many graphics are present on the layer each time you change the extent.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;yourFeatureLayerVar.graphics.length;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 14 Jan 2014 12:42:12 GMT</pubDate>
    <dc:creator>JakubMalec</dc:creator>
    <dc:date>2014-01-14T12:42:12Z</dc:date>
    <item>
      <title>Count featurelayer attributes displayed in a map</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-featurelayer-attributes-displayed-in-a-map/m-p/309794#M28497</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have created a basemap and then created a featureLayer. Now I have to count one of the featureLayer attributes value when moving the map and render it in some part the html page using innerHTML.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Suppose on onLoad of a page we get 100 featureLayers, now when I move the map a little bit up then the featureLayer will be 40, so I have to count that and render that value in a page. So whenever we move the map then we have to count the featureLayer displayed in the screen(map) and render it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please help in suggesting how we can achieve this, any suggestion will be highly appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Vikas&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Jan 2014 11:32:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-featurelayer-attributes-displayed-in-a-map/m-p/309794#M28497</guid>
      <dc:creator>VikasNeekhra</dc:creator>
      <dc:date>2014-01-14T11:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: Count featurelayer attributes displayed in a map</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-featurelayer-attributes-displayed-in-a-map/m-p/309795#M28498</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am confused with the info provided. Are you trying to count the number of feature layers loaded or the number of features of one specific feature layer?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Jan 2014 12:40:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-featurelayer-attributes-displayed-in-a-map/m-p/309795#M28498</guid>
      <dc:creator>JasonZou</dc:creator>
      <dc:date>2014-01-14T12:40:06Z</dc:date>
    </item>
    <item>
      <title>Re: Count featurelayer attributes displayed in a map</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-featurelayer-attributes-displayed-in-a-map/m-p/309796#M28499</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;All you need to do is to count how many graphics are present on the layer each time you change the extent.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;yourFeatureLayerVar.graphics.length;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Jan 2014 12:42:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-featurelayer-attributes-displayed-in-a-map/m-p/309796#M28499</guid>
      <dc:creator>JakubMalec</dc:creator>
      <dc:date>2014-01-14T12:42:12Z</dc:date>
    </item>
    <item>
      <title>Re: Count featurelayer attributes displayed in a map</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-featurelayer-attributes-displayed-in-a-map/m-p/309797#M28500</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This should do the trick:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;map.on("extent-change", function(extent){&amp;nbsp; var query = new Query();&amp;nbsp; query.geometry = extent.extent;&amp;nbsp; flayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(result){ &amp;nbsp; console.log(result.length);//This is the number of features in current view&amp;nbsp; }); });&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Jan 2014 12:48:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-featurelayer-attributes-displayed-in-a-map/m-p/309797#M28500</guid>
      <dc:creator>JohnathanBarclay</dc:creator>
      <dc:date>2014-01-14T12:48:38Z</dc:date>
    </item>
    <item>
      <title>Re: Count featurelayer attributes displayed in a map</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-featurelayer-attributes-displayed-in-a-map/m-p/309798#M28501</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for all the responses!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried update-end event but it is not getting called.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;dojo.connect(featureLayer, "update-end", function(evt) {...});&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;also tried extent-change event on map as below, but it is giving me total events...&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;map.on("extent-change", function() {
&amp;nbsp; //var len=Object.keys(featureLayer.toJson().featureSet.features).length;
&amp;nbsp; //alert("hi="+len);
&amp;nbsp; alert(featureLayer.graphics.length);
 });&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks all for your help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:49:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-featurelayer-attributes-displayed-in-a-map/m-p/309798#M28501</guid>
      <dc:creator>VikasNeekhra</dc:creator>
      <dc:date>2021-12-11T14:49:16Z</dc:date>
    </item>
    <item>
      <title>Re: Count featurelayer attributes displayed in a map</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-featurelayer-attributes-displayed-in-a-map/m-p/309799#M28502</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Thanks for all the responses!&lt;BR /&gt;&lt;BR /&gt;I tried update-end event but it is not getting called.&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;dojo.connect(featureLayer, "update-end", function(evt) {...});&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;also tried extent-change event on map as below, but it is giving me total events...&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;map.on("extent-change", function() {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //var len=Object.keys(featureLayer.toJson().featureSet.features).length;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //alert("hi="+len);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; alert(featureLayer.graphics.length);
&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;Thanks all for your help!&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think it might be:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;dojo.connect(featureLayer, "onUpdateEnd", function(evt) {...});&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;or&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;on(featureLayer, "update-end", function(evt) {...});&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:49:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-featurelayer-attributes-displayed-in-a-map/m-p/309799#M28502</guid>
      <dc:creator>JonathanUihlein</dc:creator>
      <dc:date>2021-12-11T14:49:18Z</dc:date>
    </item>
    <item>
      <title>Re: Count featurelayer attributes displayed in a map</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-featurelayer-attributes-displayed-in-a-map/m-p/309800#M28503</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;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.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;In that case you need to iterate through the selectFeatures callback result, something like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;map.on("extent-change", function(extent){
 var query = new Query();
 query.geometry = extent.extent;
 flayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(result){
&amp;nbsp; var count = 0;
&amp;nbsp; array.forEach(result, function(feature){
&amp;nbsp;&amp;nbsp; count = count + feature.attributes.YOURFIELD;
&amp;nbsp; });
&amp;nbsp; console.log(count);
 });
});&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:49:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-featurelayer-attributes-displayed-in-a-map/m-p/309800#M28503</guid>
      <dc:creator>JohnathanBarclay</dc:creator>
      <dc:date>2021-12-11T14:49:21Z</dc:date>
    </item>
    <item>
      <title>Re: Count featurelayer attributes displayed in a map</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-featurelayer-attributes-displayed-in-a-map/m-p/309801#M28504</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;All you need to do is to count how many graphics are present on the layer each time you change the extent.&lt;BR /&gt;&lt;BR /&gt;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. &lt;BR /&gt;&lt;BR /&gt;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:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;yourFeatureLayerVar.graphics.length;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Hello Jakub,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have set the feature layer mode to MODE_ONDEMAND and wrote below event which fires on every drag of a map but it is giving the total length of the featureLayer, but I need to find the count of whatever feature layers are in the map. Suppose there are 100 FL and when we drag the map then the FL is 40 then I should get the count as 40, but not 100.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So two things I am trying to fetch from featureLayer when dragging the map.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1. the count of FL whatever we have in the screen&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. count of one of the attributes of FL&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;dojo.connect(featureLayer, "onUpdateEnd", function(evt) {
&amp;nbsp; //alert(featureLayer.toJson());
&amp;nbsp; alert("graphics len="+featureLayer.graphics.length);&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:49:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-featurelayer-attributes-displayed-in-a-map/m-p/309801#M28504</guid>
      <dc:creator>VikasNeekhra</dc:creator>
      <dc:date>2021-12-11T14:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: Count featurelayer attributes displayed in a map</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-featurelayer-attributes-displayed-in-a-map/m-p/309802#M28505</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;In that case you need to iterate through the selectFeatures callback result, something like this:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;map.on("extent-change", function(extent){
 var query = new Query();
 query.geometry = extent.extent;
 flayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(result){
&amp;nbsp; var count = 0;
&amp;nbsp; array.forEach(result, function(feature){
&amp;nbsp;&amp;nbsp; count = count + feature.attributes.YOURFIELD;
&amp;nbsp; });
&amp;nbsp; console.log(count);
 });
});&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hello Johnathan,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried above code which is getting called on every drag of a map, but it is not going inside below code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;featureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(result){
&amp;nbsp;&amp;nbsp; alert("inside");
&amp;nbsp;&amp;nbsp; var count = 0;
&amp;nbsp;&amp;nbsp; array.forEach(result, function(feature){
&amp;nbsp;&amp;nbsp;&amp;nbsp; count = count + feature.attributes.CustomersAffected;
&amp;nbsp;&amp;nbsp; });
&amp;nbsp;&amp;nbsp; alert("CustomersAffected="+count);
&amp;nbsp; });&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:49:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-featurelayer-attributes-displayed-in-a-map/m-p/309802#M28505</guid>
      <dc:creator>VikasNeekhra</dc:creator>
      <dc:date>2021-12-11T14:49:26Z</dc:date>
    </item>
    <item>
      <title>Re: Count featurelayer attributes displayed in a map</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-featurelayer-attributes-displayed-in-a-map/m-p/309803#M28506</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hello Johnathan,&lt;BR /&gt;&lt;BR /&gt;I tried above code which is getting called on every drag of a map, but it is not going inside below code.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;featureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(result){
&amp;nbsp;&amp;nbsp; alert("inside");
&amp;nbsp;&amp;nbsp; var count = 0;
&amp;nbsp;&amp;nbsp; array.forEach(result, function(feature){
&amp;nbsp;&amp;nbsp;&amp;nbsp; count = count + feature.attributes.CustomersAffected;
&amp;nbsp;&amp;nbsp; });
&amp;nbsp;&amp;nbsp; alert("CustomersAffected="+count);
&amp;nbsp; });&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Have you required "dojo/_base/array"? You need this module to execute the forEach method.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:49:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-featurelayer-attributes-displayed-in-a-map/m-p/309803#M28506</guid>
      <dc:creator>JohnathanBarclay</dc:creator>
      <dc:date>2021-12-11T14:49:29Z</dc:date>
    </item>
    <item>
      <title>Re: Count featurelayer attributes displayed in a map</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-featurelayer-attributes-displayed-in-a-map/m-p/309804#M28507</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Johnathan! It worked...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also thanks to all the responses I get on this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jan 2014 11:06:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-featurelayer-attributes-displayed-in-a-map/m-p/309804#M28507</guid>
      <dc:creator>VikasNeekhra</dc:creator>
      <dc:date>2014-01-15T11:06:23Z</dc:date>
    </item>
  </channel>
</rss>

