Hello. i'm using arcgis api 4.10 where i want to show the total num of count, let's suppose i have a Map Server service (http://...:.../...//MapServer/13) of customers so i want to show the total number of customers by using service and relevant field like (Number_of_SUM) of this service, how can i do this!!
Irtiza,
Here is a snipit of code for that:
<SPAN class="keyword token">var</SPAN> statisticDefinition2 <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">StatisticDefinition</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN> statisticType<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"count"</SPAN><SPAN class="punctuation token">,</SPAN> onStatisticField<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Muni"</SPAN><SPAN class="punctuation token">,</SPAN> outStatisticFieldName<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"muniCount"</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> query<SPAN class="punctuation token">.</SPAN>where <SPAN class="operator token">=</SPAN> <SPAN class="string token">"1=1"</SPAN><SPAN class="punctuation token">;</SPAN> query<SPAN class="punctuation token">.</SPAN>outStatistics <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>statisticDefinition2<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN> query<SPAN class="punctuation token">.</SPAN>groupByFieldsForStatistics <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"Muni"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN> query<SPAN class="punctuation token">.</SPAN>outFields <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"Muni"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN> featureLayer<SPAN class="punctuation token">.</SPAN><SPAN class="token function">queryFeatures</SPAN><SPAN class="punctuation token">(</SPAN>query<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">then</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">function</SPAN><SPAN class="punctuation token">(</SPAN>results<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> <SPAN class="keyword token">var</SPAN> count <SPAN class="operator token">=</SPAN> feat<SPAN class="punctuation token">.</SPAN>attributes<SPAN class="punctuation token">.</SPAN>muniCount<SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Thanks Undral,
Can you show some working samples of this!! as it is difficult to understand for me.
Thanks Robert,
Can you show some working examples of this!! as it is difficult to understand for me.
Hi there,
What Robert suggested. You can also use queryFeatureCount on FeatureLayer or FeatureLayerView if you have created a FeatureLayer.
Use FeatureLayerView.queryFeatureCount, if you want to get the total count of features available on the client (fast and performant).
User FeatureLayer.queryFeatureCount, if you want to get the exact number of features that meet your requirements. This will issue a network request to the server.
Have you looked into StatisticDefintion? This class is for exactly what you are wanting to do.
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.