Openlayers 3:以编程方式选择功能 [英] Openlayers 3: Select a feature programmatically
问题描述
我正在尝试将系统从Openlayers 2升级到Openlayers 3,但有一个我似乎无法弄清的特殊问题.
I am trying to upgrade my system from Openlayers 2 to Openlayers 3 and I have having one particular issue that I cannot seem to figure out.
我的应用程序有一个网格和一个地图,当用户单击网格时,我想在地图上选择相关点.
My application has a grid and a map and when a user clicks on the grid I want to select the relevant point on the map.
在Openlayers 2中,我使用了以下内容:
In Openlayers 2 I used the following:
self.selectControl.select(feature[0]);
我无法找到或理解如何在Openlayers 3中执行相同的操作.
I cannot find or understand how to do the same in Openlayers 3.
很明显,我有一个以编程方式找到的功能,我想在地图上(以编程方式)选择该功能!
So to be clear, I have a feature which I have found programmatically and I want to select that feature on a map (programmatically)!
我似乎无法在API中找到任何内容,但这可能是由于我不了解Openlayers所致.
I cannot seem to find anything in the APIs but that might be due to my lack of understanding as I am new to Openlayers.
推荐答案
为此,您需要执行以下操作:
To do this you need to do the following:
mySelectControl.getFeatures().clear() -> removes the selected items
mySelectControl.getFeatures().push(featureToSelect) -> selects the applied feature
这篇关于Openlayers 3:以编程方式选择功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!