【发布时间】:2020-10-11 15:08:37
【问题描述】:
我已经成功地能够通过属性 id 过滤,例如抖动图 - 我已经成功地实现了多种方式 - 但都以同样的问题结束。
1.) 使用 where 过滤器 2.) 定义表达式 3.) 遍历所有属性 id 并将它们带回来。
问题: 一次只允许/显示每个attribute id 一个.. 我的目标是将attribute ids 输入复选框列表(我已经这样做了),但是允许通过属性 id 将项目添加到地图中,因为它们一次被检查,共同地,一次出现一个 - 目前我似乎无法让它与一次出现多个或多个然后一个的方面一起工作地图。
1.) 即下面的过滤器(尝试逻辑 1)&CodePen:
.....
function filterByID(event) {
const selectedID = event.target.getAttribute("data-id");
eqLayerView.filter = {
where: "id = '" + selectedID + "'"
};
}
view.whenLayerView(fl)
.then(function(layerView) {
eqLayerView = layerView;
eqLayerView.filter = {
where: "id = ''"
};
.............
2.) 即另一个尝试的逻辑(在此处一次添加多个,逐行或通过数组):
layer.definitionExpression = "id = 'us70008jr5'",
layer.definitionExpression = "id = 'cgi988jr52'",
3.) 即第 3 次尝试,这里有关于 GIS 交换的建议:https://gis.stackexchange.com/questions/364578/loop-through-attribute-ids-of-featurelayer
layer
.load()
.then(() => {
// create a query from the layer
const query = layer.createQuery();
query.returnDistinctValues = true;
query.where = "grid_value > 2"; // or 1=1 if you need them all
// the field you want distinct values for
query.outFields = ["id"];
return layer.queryFeatures(query);
})
.then(({ features }) => {
// extract the ids to a list
const ids = features.map(({ attributes }) => attributes.id);
return ids;
})
.then((ids) => {
// You can store them how you want, in this case,
// I put them in a dropdown select menu
const fragment = document.createDocumentFragment();
ids.forEach((id) => {
const option = document.createElement('option');
option.value = id;
option.innerText = id;
fragment.appendChild(option);
});
list.appendChild(fragment);
map.add(layer);
});
以上所有尝试的逻辑都会导致 attribute id 一次只显示一个抖动图 - 通过切换一个新的打开,前一个关闭,我需要能够有多个能够存在地图。
ArcGIS - javascript - 4.15
【问题讨论】:
标签: javascript esri arcgis-js-api