我有一堆Web图层,想要隐藏与给定几何/其他图层相交的所有多边形。
我使用空间查询过滤了这些相交的多边形,但是后来我不知道如何隐藏它们。我以为可以操纵所得多边形的渲染器,例如: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)
})
});
答案 0 :(得分:2)
如果您根本不想显示要素,则可以使用QueryTask仅从MapService检索与范围相交的要素。然后,您可以使用结果创建一个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
});
});
});
从性能的角度来看,这个答案可能是最好的,因为交集是在服务器端进行的,客户端不必下载不需要的功能。
答案 1 :(得分:1)
您可以将图形的visible属性更改为false
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)
})
});