getFeaturesByAttribute 不是函数错误

getFeaturesByAttribute is not a function error

我正在使用 openlayers 创建地图应用程序,并尝试在按下按钮时更改图层功能图标。 我看过一些示例,他们建议我使用此代码

let feature = this.vectorLayer.getFeaturesByAttribute('id', 1);

feature.style = this.iconiSelected;
this.vectorLayer.redraw();

但是我收到错误 this.vectorLayer.getFeaturesByAttribute is not a function 该功能已有一个图标,但我想在按下按钮时更改它,这是正确的方法吗,还是有其他方法吗?

请尝试:

let feature = this.vectorLayer.getSource().getFeatureById(1);
feature.setStyle(this.iconiSelected);

看这里:https://openlayers.org/en/latest/apidoc/module-ol_source_Vector-VectorSource.html#getFeatureById and https://openlayers.org/en/latest/apidoc/module-ol_Feature-Feature.html#setStyle