Select to view content in your preferred language

Hide polygons resulting from a spatial query

1103
5
Jump to solution
01-30-2019 09:18 AM
DanielaPetrova
Emerging Contributor

Hi ARCGIS/JS experts,

I have a bunch of web layers and want to hide all polygons that are intersect with a given geometry/other layer.

I filter these intersecting polygons using spatial query, but then I don't know how to hide them. I was thinking that can manipulate renderer of resulting polygons, something like: hide(), opacity = 0, visible=false... Or maybe I need filter only those that are not intersecting and render only them?

Here is my query:

view.whenLayerView(layer).then(function(layerView){
   var query = layer.createQuery();
   query.geometry = new Extent({
      xmin: 6902682.7633,
      ymin: -3519872.5095,
      xmax: 11221869.7958,
      ymax: -2276864.0272,
      spatialReference: 102100
   });
   query.spatialRelationship = "intersects";


   layer.queryFeatures(query).then(function(results){
      for (var index in results.features) {
         //hide as manipulate its rendering

      }

      // or something like layerView.highlight(results.features)

   })

});

Is this right approach, or I need first to query polygons that are not intersecting and then add results to a new layer and render only them? In such case what should be query.spatialRelationship?

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Daniela,

   You would just query for the ObjectIds and then set the layer definition query to be :

"NOT ObjectID IN (" + QueryResultsArr.join() + ")"

View solution in original post

5 Replies
RobertScheitlin__GISP
MVP Emeritus

Daniela,

   You would just query for the ObjectIds and then set the layer definition query to be :

"NOT ObjectID IN (" + QueryResultsArr.join() + ")"

DanielaPetrova
Emerging Contributor

Thanks a lot, I haven't know about I can pass a query results to a definition expression

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Daniela,

   Not actually pass the query result but a SQL statement from the results.

Don't forget to mark this question as answered by clicking on the "Mark Correct" link on the reply that answered your question.

0 Kudos
DanielaPetrova
Emerging Contributor

 A problem has appeared. When I'm working with feature layers the app performance is very poor, processing and loading FeatureLayer's is extremely slow. Therefore I've decided to work with MapImageLayer, which is loaded immediately. But now how to query sublayers of MapImageLayer for get those ObjectIds that are intersects with given extent?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Daniela,

   When using a MapImageLayer for the visualization in the map you will use a QueryTask and Query classes to query the sublayer and return the ObjectIds

0 Kudos