AnsweredAssumed Answered

Select points within polygon of separate layers

Question asked by ClintonLT16 on Feb 23, 2018
Latest reply on Feb 23, 2018 by rscheitlin

Hi all, 


I am trying to achieve something similar to a Select by Location operation. I am using the Javascript API 4.6. I have 2 layers: 1 is a point layer, and the second is a polygon layer of city boundaries. Essentially, I would like to select a city and return all of the points within that city boundary.


What I have done: 

I am using the search widget to enable me to text search the layer, where I have connected my layer of points. In this search widget, I can filter on a where statement, or geometry.


I have been able to successfully use the where statement when searching for objects within the same layer, but have not been able to get the filter by geometry to work. Here is a snippet of what I have come up with so far. In the console, it is showing that I am returning geometry objects, and it doesn't throw an error when I try to set the searchWidget geometry to the response geometry. However, it still returns points outside of my city boundary. 


     //on change, get the value (name) of the city
    var city = document.getElementById("filterCityPanel");
    var cityStr = query("#filterCityPanel").on("change", function(e) {
      var task = new QueryTask({
        url: url,
      var params = new Query();
      params.returnGeometry = true;
      params.where = "name = '" + + "'";
      params.outFields = ["name"];

      .then(function(response) {
      searchWidget.sources.items[0].filter.geometry = response.features[0].geometry;



Thank you! 

Clinton Lunn