我正在使用 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和https://openlayers.org/en/latest/apidoc/module-ol_Feature-Feature.html#setStyle
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句