<?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: Filter a shapefile in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/filter-a-shapefile/m-p/102680#M9409</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There are no methods in the API to do this but you could write your own.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first thing I would do is to make sure that your graphics layer gets an Id with it is created. Check out the options parameter when creating the GraphicsLayer. Then when you want to apply a definition query:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Get your graphics layer object&lt;/LI&gt;&lt;LI&gt;Loop through all of the graphics&lt;/LI&gt;&lt;LI&gt;Test your definition query against a property in the attributes&lt;/LI&gt;&lt;LI&gt;Set the visibility of each graphic (based on your test condition)&lt;/LI&gt;&lt;LI&gt;Redraw the graphics layer&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;var gl = map.getLayer('shapefileGL');&amp;nbsp; // &amp;lt; this needs to be your graphics layer id
var value = dom.byId('defValue').value;&amp;nbsp; // this is the value to filter on
var field = "STRAHLER"; // this is the field (attribute) to filter on
setSimpleDefinitionQuery(gl, field, value);

function setSimpleDefinitionQuery(gl, field, value){ 
&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.forEach(gl.graphics,function(gr){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gr.visible = (gr.attributes[field] == value);
&amp;nbsp;&amp;nbsp;&amp;nbsp; });
&amp;nbsp;&amp;nbsp;&amp;nbsp; gl.redraw();
}&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 06:19:22 GMT</pubDate>
    <dc:creator>OwenEarley</dc:creator>
    <dc:date>2021-12-11T06:19:22Z</dc:date>
    <item>
      <title>Filter a shapefile</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/filter-a-shapefile/m-p/102676#M9405</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is it possible to filter a shapefile by its attributes once it's loaded onto the map?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Mar 2015 20:55:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/filter-a-shapefile/m-p/102676#M9405</guid>
      <dc:creator>VygintasCesnauskas</dc:creator>
      <dc:date>2015-03-04T20:55:39Z</dc:date>
    </item>
    <item>
      <title>Re: Filter a shapefile</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/filter-a-shapefile/m-p/102677#M9406</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How are you adding the shapefile? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Mar 2015 21:14:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/filter-a-shapefile/m-p/102677#M9406</guid>
      <dc:creator>KellyHutchins</dc:creator>
      <dc:date>2015-03-04T21:14:15Z</dc:date>
    </item>
    <item>
      <title>Re: Filter a shapefile</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/filter-a-shapefile/m-p/102678#M9407</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This question is a bit vague - how are you adding the shapefile to a javascript map?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are talking about a &lt;A href="https://developers.arcgis.com/javascript/jsapi/featurelayer-amd.html"&gt;FeatureLayer&lt;/A&gt; then you can use &lt;A href="https://developers.arcgis.com/javascript/jsapi/featurelayer-amd.html#setdefinitionexpression"&gt;setDefinitionExpression&lt;/A&gt;:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;SPAN style="color: #000000; font-family: 'Lucida Grande', 'Segoe UI', Arial, sans-serif;"&gt;Set's the definition expression for the FeatureLayer. Only the features that match the definition expression are displayed. A definition expression limits the features available for display and queries by applying constraints to the layer's attribute fields.&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;If you are talking about an &lt;A href="https://developers.arcgis.com/javascript/jsapi/arcgisdynamicmapservicelayer-amd.html"&gt;ArcgisDynamicMapServiceLayer&lt;/A&gt; then you can use &lt;A href="https://developers.arcgis.com/javascript/jsapi/arcgisdynamicmapservicelayer-amd.html#setlayerdefinitions"&gt;setlayerdefinitions&lt;/A&gt;:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;SPAN style="color: #4d4d4d; font-family: 'Lucida Grande', 'Segoe UI', Arial, sans-serif;"&gt;Sets the layer definitions used to filter the features of individual layers in the map service. &lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Mar 2015 21:14:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/filter-a-shapefile/m-p/102678#M9407</guid>
      <dc:creator>OwenEarley</dc:creator>
      <dc:date>2015-03-04T21:14:56Z</dc:date>
    </item>
    <item>
      <title>Re: Filter a shapefile</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/filter-a-shapefile/m-p/102679#M9408</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Apologies for the lack of detail, shapefile is uploaded using esri/request:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;var uploadRequest = esriRequest({
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; url: this._uploadUrl,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; form: dojo.byId("formUploadShapeFile")
});&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then it's added to the map as a GraphicsLayer.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:19:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/filter-a-shapefile/m-p/102679#M9408</guid>
      <dc:creator>VygintasCesnauskas</dc:creator>
      <dc:date>2021-12-11T06:19:19Z</dc:date>
    </item>
    <item>
      <title>Re: Filter a shapefile</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/filter-a-shapefile/m-p/102680#M9409</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There are no methods in the API to do this but you could write your own.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first thing I would do is to make sure that your graphics layer gets an Id with it is created. Check out the options parameter when creating the GraphicsLayer. Then when you want to apply a definition query:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Get your graphics layer object&lt;/LI&gt;&lt;LI&gt;Loop through all of the graphics&lt;/LI&gt;&lt;LI&gt;Test your definition query against a property in the attributes&lt;/LI&gt;&lt;LI&gt;Set the visibility of each graphic (based on your test condition)&lt;/LI&gt;&lt;LI&gt;Redraw the graphics layer&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;var gl = map.getLayer('shapefileGL');&amp;nbsp; // &amp;lt; this needs to be your graphics layer id
var value = dom.byId('defValue').value;&amp;nbsp; // this is the value to filter on
var field = "STRAHLER"; // this is the field (attribute) to filter on
setSimpleDefinitionQuery(gl, field, value);

function setSimpleDefinitionQuery(gl, field, value){ 
&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.forEach(gl.graphics,function(gr){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gr.visible = (gr.attributes[field] == value);
&amp;nbsp;&amp;nbsp;&amp;nbsp; });
&amp;nbsp;&amp;nbsp;&amp;nbsp; gl.redraw();
}&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:19:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/filter-a-shapefile/m-p/102680#M9409</guid>
      <dc:creator>OwenEarley</dc:creator>
      <dc:date>2021-12-11T06:19:22Z</dc:date>
    </item>
  </channel>
</rss>

