ARCGIS:隐藏空间查询产生的多边形

ARCGIS: Hide polygons resulting from a spatial query

我有一堆 Web 图层,想隐藏与给定 geometry/other 图层相交的所有多边形。

我使用空间查询过滤了这些相交的多边形,但后来我不知道如何隐藏它们。我在想可以操纵结果多边形的渲染器,比如:hide()、opacity = 0、visible = false ...这是正确的方法吗,或者我需要先查询不相交的多边形,然后将结果添加到新层并只渲染它们?在这种情况下应该是 query.spatialRelationship?

这是我的查询:

    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)    
       })
    });

如果您根本不想显示要素,可以使用 QueryTask 仅检索与地图服务范围相交的要素。然后您可以使用结果创建一个 FeatureLayer。

require(["esri/tasks/QueryTask", "esri/tasks/support/Query", "esri/geometry/Extent", "esri/layers/FeatureLayer"], function(QueryTask, Query, Extent, FeatureLayer){
  var layerUrl = " ... "; // Represents the REST endpoint for your layer
  var queryTask = new QueryTask({
    url: layerUrl 
  });
  var query = new Query();
  query.returnGeometry = true;
  query.outFields = ["*"];
  query.geometry = new Extent({ 
     xmin: 6902682.7633,
     ymin: -3519872.5095,
     xmax: 11221869.7958,
     ymax: -2276864.0272,
     spatialReference: 102100
  });
  query.spatialRelationship = "intersects";

  // When resolved, create the featureLayer with the results
  queryTask.execute(query).then(function(results){
    var layer = new FeatureLayer({
      source: results.features
    });
  });
});

从性能的角度来看,这个答案可能是最好的,因为交集是在服务器端进行的,客户端不必下载不需要的功能。

您可以将图形的可见性属性更改为假

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) { 
       results.features[index].visible = false;  
     }    
    // or something like layerView.highlight(results.features)    
   })
});