<?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: ArcGIS JS Api 4 multiple filters working together in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-api-4-multiple-filters-working-together/m-p/1001691#M70818</link>
    <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;You have to make each of your listener functions listen to each other.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's what I did to make it work (nb I changed the dates to 1856 and 1921 because they were easier to see):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function setFeatureLayerFilter(expression) {
    chartsLayer.definitionExpression = expression;
}

// The filter for the page load map view
// Only show small scale series
setFeatureLayerFilter("Shape_Area &amp;gt;= 9463642202000 AND datepub = 1856");

//setFeatureLayerFilter("scale &amp;lt; 698000" );
// Exclude map scales according to the zoom level
// Use 'Shape_Area' because scale information might be missing for some charts     
view.watch("zoom", function(newValue) {
    switch (selectFilter.value) {
        case "datePub = 1856":
            if (newValue &amp;lt;= 2) {
                setFeatureLayerFilter("Shape_Area &amp;gt;= 9463642202000 AND datePub = 1856");
            } else if (newValue &amp;gt;= 4) {
                setFeatureLayerFilter("Shape_Area &amp;lt;= 946364220200 AND datePub = 1856");
            }
            break;
        case "datePub = 1921":
            if (newValue &amp;lt;= 2) {
                setFeatureLayerFilter("Shape_Area &amp;gt;= 9463642202000 AND datePub = 1921");
            } else if (newValue &amp;gt;= 4) {
                setFeatureLayerFilter("Shape_Area &amp;lt;= 946364220200 AND datePub = 1921");
            }
            break;
    }
});

// Query the layer based on the chart series
var sqlExpressions = [
    "datePub = 1856",
    "datePub = 1921"
];

var selectFilter = document.createElement("select");
selectFilter.setAttribute("class", "esri-widget esri-select");
selectFilter.setAttribute(
    "style",
    "width: 275px; font-family: Avenir Next W00; font-size: 1em;"
);

sqlExpressions.forEach(function(sql) {
    var option = document.createElement("option");
    option.value = sql;
    option.innerHTML = sql;
    selectFilter.appendChild(option);
});

view.ui.add(selectFilter, "top-right");

selectFilter.addEventListener('change', function(event) {
    if (view.zoom &amp;gt;= 2) {
        setFeatureLayerFilter("Shape_Area &amp;lt;= 9463642202000 AND" + event.target.value);
    } else {
        setFeatureLayerFilter("Shape_Area &amp;gt;= 9463642202000 AND" + event.target.value);
    }
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 16 Nov 2020 11:48:51 GMT</pubDate>
    <dc:creator>Gianna_BBSRC</dc:creator>
    <dc:date>2020-11-16T11:48:51Z</dc:date>
    <item>
      <title>ArcGIS JS Api 4 multiple filters working together</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-api-4-multiple-filters-working-together/m-p/1001545#M70814</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using ArcGIS API 4 and am trying to combine filters. I have a featureLayer that is filtered depending on the zoom level and then can also be filtered with a dropdown but the problem is that these filters override each other. I would like them to be dependent on one another. If the zoom filter is set on the layer, it should remain applied if the dropdown menu is set. I can't find an example of how to to set this up. Any help would be highly appreciated.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="utf-8"&amp;gt;
    &amp;lt;meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no"&amp;gt;
    &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.17/esri/css/main.css"&amp;gt;
    &amp;lt;script src="https://js.arcgis.com/4.17/"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;title&amp;gt;UWM Historical Nautical Charts&amp;lt;/title&amp;gt;
    &amp;lt;style&amp;gt;
      html, body, #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }
    &amp;lt;/style&amp;gt;
    &amp;lt;script&amp;gt;
  require(["esri/Map", "esri/views/MapView", "esri/layers/FeatureLayer", "esri/geometry/Extent"], function(
  Map,
  MapView,
  FeatureLayer,
  Extent
) {

  // Create a style for the chartsLayer
  var renderer = {
  type: "simple",  // autocasts as new SimpleRenderer()
  symbol: {
    type: "simple-fill",  // autocasts as new SimpleFillSymbol()
    color: [ 255, 128, 0, 0.5 ],
    outline: {  // autocasts as new SimpleLineSymbol()
      width: 1,
      color: "white"
    }
  }
  };

  // Create a FeatureLayer
  var chartsLayer = new FeatureLayer({
    url: "https://webgis.uwm.edu/arcgisuwm/rest/services/AGSL/agsl_nautical/MapServer/0",
    outFields: ["*"], // Return all fields so it can be queried client-side
    renderer: renderer
  });

  // Create the Map and add the featureLayer defined above
  map = new Map({
    basemap: "oceans",
    layers: [chartsLayer]
  });

  // Create the MapView
  var view = new MapView({
    container: "viewDiv",
    map: map,
    center: [0,0],    
    zoom: 2
  });

  // setup the contraints of the map
  view.constraints = {
  geometry: {            // Constrain lateral movement to the entire globe with no repeat
    type: "extent",
    xmin: -90,
    ymin: -180,
    xmax: 90,
    ymax: 180
  },
  minZoom: 2,          
  rotationEnabled: false // Disables map rotation
};

  // Create a template for the popup
  var template = {
  // autocasts as new PopupTemplate()
  title: "{title}",
  content: [
    {
      type: "fields",
      fieldInfos: [
        {
          fieldName: "label",
          label: "label"
        },
        {
          fieldName: "west",
          label: "West"
        },
        {
          fieldName: "east",
          label: "East"
        },
        {
          fieldName: "north",
          label: "North"
        },
        {
          fieldName: "south",
          label: "South"
        },
        {
          fieldName: "scale",
          label: "Scale"
        }
      ]
    }
  ]
};

// Set the popup template on the layer
chartsLayer.popupTemplate = template;

function setFeatureLayerFilter(expression) {
  chartsLayer.definitionExpression = expression;
}
// The filter for the page load map view
// Only show small scale series
setFeatureLayerFilter("Shape_Area &amp;gt;= 9463642202000" );

//setFeatureLayerFilter("scale &amp;lt; 698000" );
// Exclude map scales according to the zoom level
// Use 'Shape_Area' because scale information might be missing for some charts     
view.watch("zoom", function(newValue) {
  if (newValue &amp;lt;= 2) {    
    setFeatureLayerFilter("Shape_Area &amp;gt;= 9463642202000" ); 
  } else if (newValue &amp;gt;= 4) {
    setFeatureLayerFilter("Shape_Area &amp;lt;= 946364220200" );
  }

  console.log("scale property changed: ", newValue);
});

// Query the layer based on the chart series
var sqlExpressions = [
  "datePub = 1911",
  "datePub = 1912"  
];

var selectFilter = document.createElement("select");
selectFilter.setAttribute("class", "esri-widget esri-select");
selectFilter.setAttribute(
  "style",
  "width: 275px; font-family: Avenir Next W00; font-size: 1em;"
);

sqlExpressions.forEach(function (sql) {
  var option = document.createElement("option");
  option.value = sql;
  option.innerHTML = sql;
  selectFilter.appendChild(option);
});

view.ui.add(selectFilter, "top-right");

 selectFilter.addEventListener('change', function (event) {
        setFeatureLayerFilter(event.target.value);
      });

});




  &amp;lt;/script&amp;gt;
    &amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Nov 2020 17:22:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-api-4-multiple-filters-working-together/m-p/1001545#M70814</guid>
      <dc:creator>rcwisc</dc:creator>
      <dc:date>2020-11-14T17:22:55Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS JS Api 4 multiple filters working together</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-api-4-multiple-filters-working-together/m-p/1001691#M70818</link>
      <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;You have to make each of your listener functions listen to each other.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's what I did to make it work (nb I changed the dates to 1856 and 1921 because they were easier to see):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function setFeatureLayerFilter(expression) {
    chartsLayer.definitionExpression = expression;
}

// The filter for the page load map view
// Only show small scale series
setFeatureLayerFilter("Shape_Area &amp;gt;= 9463642202000 AND datepub = 1856");

//setFeatureLayerFilter("scale &amp;lt; 698000" );
// Exclude map scales according to the zoom level
// Use 'Shape_Area' because scale information might be missing for some charts     
view.watch("zoom", function(newValue) {
    switch (selectFilter.value) {
        case "datePub = 1856":
            if (newValue &amp;lt;= 2) {
                setFeatureLayerFilter("Shape_Area &amp;gt;= 9463642202000 AND datePub = 1856");
            } else if (newValue &amp;gt;= 4) {
                setFeatureLayerFilter("Shape_Area &amp;lt;= 946364220200 AND datePub = 1856");
            }
            break;
        case "datePub = 1921":
            if (newValue &amp;lt;= 2) {
                setFeatureLayerFilter("Shape_Area &amp;gt;= 9463642202000 AND datePub = 1921");
            } else if (newValue &amp;gt;= 4) {
                setFeatureLayerFilter("Shape_Area &amp;lt;= 946364220200 AND datePub = 1921");
            }
            break;
    }
});

// Query the layer based on the chart series
var sqlExpressions = [
    "datePub = 1856",
    "datePub = 1921"
];

var selectFilter = document.createElement("select");
selectFilter.setAttribute("class", "esri-widget esri-select");
selectFilter.setAttribute(
    "style",
    "width: 275px; font-family: Avenir Next W00; font-size: 1em;"
);

sqlExpressions.forEach(function(sql) {
    var option = document.createElement("option");
    option.value = sql;
    option.innerHTML = sql;
    selectFilter.appendChild(option);
});

view.ui.add(selectFilter, "top-right");

selectFilter.addEventListener('change', function(event) {
    if (view.zoom &amp;gt;= 2) {
        setFeatureLayerFilter("Shape_Area &amp;lt;= 9463642202000 AND" + event.target.value);
    } else {
        setFeatureLayerFilter("Shape_Area &amp;gt;= 9463642202000 AND" + event.target.value);
    }
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2020 11:48:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-api-4-multiple-filters-working-together/m-p/1001691#M70818</guid>
      <dc:creator>Gianna_BBSRC</dc:creator>
      <dc:date>2020-11-16T11:48:51Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS JS Api 4 multiple filters working together</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-api-4-multiple-filters-working-together/m-p/1007780#M71059</link>
      <description>&lt;P&gt;Sorry to be late on getting back to you on this. This works great, thank you very much.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Dec 2020 17:59:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-api-4-multiple-filters-working-together/m-p/1007780#M71059</guid>
      <dc:creator>rcwisc</dc:creator>
      <dc:date>2020-12-08T17:59:46Z</dc:date>
    </item>
  </channel>
</rss>

