如何通过属性属性值选择特征

huangapple go评论54阅读模式
英文:

How to select features via attribute property values

问题

我正在使用 OpenLayers 7.3,并尝试基于属性值选择 GeoJSON 矢量图层的要素。我尝试使用 Select 类与过滤器,但无法使其正常工作。我只需从地图上方的按钮运行一些预设的查询;例如,选择所有带有 "[fid] > 5" 的要素:

var selectAttributes = new Select({
  layers: [VectorLayer],
  filter: new GreaterThan({propertyName: 'fid', expression: 5}),
});

有办法做到这一点吗?我已经阅读了早期 OL 版本的方法,但没有找到适用的方法。我尝试了非常好用的 ol-ext Select 控件,它让我对 7.3 版本有了一些希望,但我不能使用控件,只需要有一些允许用户通过单击按钮运行并查看选择结果的东西。感谢任何帮助。

英文:

I'm using OpenLayers 7.3 and am trying to select features of a GeoJSON vector layer based on attribute values. I've tried using the Select Class with filters but haven't been able to get it to work. I just need to run some preset queries from the button above the map; for example, select all with "[fid] > 5":

var selectAttributes = new Select({
  layers: [VectorLayer],
  filter: new GreaterThan({propertyName: 'fid', expression: 5}),
});

Is there a way to do this? I've read about approaches from earlier OL versions but haven't found anything that works well. I've tried the very nice ol-ext Select control, which gives me hope this type of selection is possible at 7.3, but I can't use a control and just need to have something that allows the user to run and see the results of the selection from a single button push. Thanks for any help.

答案1

得分: 0

如Mike在上面的评论中所说:

> Select是为用户交互而设计的,但您可以像在codesandbox.io/s/modify-features-forked-3u6thw?file=/main.js中一样填充其功能集合。

英文:

As Mike said in the comments above:

>Select is intended for user interactions but you can populate its feature collection as in codesandbox.io/s/modify-features-forked-3u6thw?file=/main.js

huangapple
  • 本文由 发表于 2023年5月29日 06:49:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76353876.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定