[英]How to apply filter for multiple layers when using object in JavaScript for ArcGis
I am using ArcGis JavaScript API to display some maps.我正在使用 ArcGis JavaScript API 来显示一些地图。 I have ID of featurelayers in object like this:
我在对象中有特征层的 ID,如下所示:
const layersByYears = [
{ year: 1918, layers: [
{ layerID: "443709212b894e9297888b3194b51100", opacity: 1.0, name: "ORP", featureLayer: null },
{ layerID: "61a605dca69c4aa0ac1b3858ba328fd3", opacity: 1.0, name: "obceSouc", featureLayer: null }
] },
{ year: 1936, layers: [
{ layerID: "443709212b894e9297888b3194b51100", opacity: 1.0, name: "ORP", featureLayer: null },
{ layerID: "61a605dca69c4aa0ac1b3858ba328fd3", opacity: 1.0, name: "obceSouc", featureLayer: null }
] },
{ year: 1950, layers: [
{ layerID: "23bcd52310854d6185e5f22a4eca0303", opacity: 1.0, name: "ORP", featureLayer: null },
{ layerID: "61a605dca69c4aa0ac1b3858ba328fd3", opacity: 1.0, name: "obceSouc", featureLayer: null }
] },
{ year: 1981, layers: [
{ layerID: "401e9530ba074936800a8f596fc49d70", opacity: 1.0, name: "ORP", featureLayer: null },
{ layerID: "61a605dca69c4aa0ac1b3858ba328fd3", opacity: 1.0, name: "obceSouc", featureLayer: null }
] },
]
I have simple input element to choose an year and when the button is clicked, then the layer is changed also.我有简单的输入元素来选择年份,当单击按钮时,图层也会更改。 The project is here: https://www.pramenykrkonos.eu/wp-content/uploads/2022/06/index-3.html It is in czech language - what I need is to apply filter for actual layer.
该项目在这里: https ://www.pramenykrkonos.eu/wp-content/uploads/2022/06/index-3.html 它是捷克语 - 我需要为实际图层应用过滤器。
This is where variable for each layer is created:这是为每一层创建变量的地方:
const createFL = (layer) => {
if(layer.featureLayer !== null && layer.featureLayer !== undefined)
return;
layer.featureLayer = new FeatureLayer({ portalItem: {
id: layer.layerID,
opacity: layer.opacity !== undefined ? layer.opacity : 1.0,
visible: false,
} })
}
Expression for filter is defined here and should be applied when button "doBtn" is clicked.过滤器的表达式在这里定义并且应该在单击按钮“doBtn”时应用。
document.getElementById("doBtn").addEventListener("click",doQuery);
const attributeName = document.getElementById("attSelect");
const expressionSign = document.getElementById("signSelect");
const inputValue = document.getElementById("valSelect");
let expression;
function doQuery() {
expression = attributeName.value +
expressionSign.value +
"'"+inputValue.value+"'";
document.getElementById("printResults").innerHTML = expression;
featureLayer.definitionExpression = expression;
}
If I understand the issue, then I guess a simple solution would be to get the visible layers and apply the filter.如果我理解这个问题,那么我想一个简单的解决方案是获取可见层并应用过滤器。 Visible layers in this context are the "current" layers, I am guessing.
我猜,这种情况下的可见层是“当前”层。
If that is the case then your function will be something like this,如果是这种情况,那么您的功能将是这样的,
function doQuery() {
expression = attributeName.value +
expressionSign.value +
"'" + inputValue.value + "'";
document.getElementById("printResults").innerHTML = expression;
// get visible feature layers, and then apply filter
concatedLayers.filter(l => l.visible).forEach(l => l.definitionExpression = expression);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.