2016-12-30 79 views
0

我有标记层载体层OpenLayers3如何取消选择ol.layer.Vector编程

var iconLayer = new ol.layer.Vector({ 
     source: iconSource, 
     style: styles.iconStyle 
}); 

上的标记Click事件做一些东西,也当选择像

var markerClickInteraction = new ol.interaction.Select({ 
    condition: ol.events.condition.click, 
    layers:[iconLayer], 
    style:styles.iconSelectedStyle 
}); 
更改标记样式

我怎样才能以编程方式取消选定的功能(不是通过默认的取消选择行为(例如点击地图上的其他地方等))。

回答

1

在创建ol.interaction.Select互动时,您可以指定功能选项。如果设置了此选项,则所有选定的功能都将放置在此ol.Collection对象中。使用这ol.Collection你可以操纵选择的功能,如clear()或其他。如果ol.Collection对象被清除,则所有选中的功能都将被自动取消选择。

var featuresColl = new ol.Collection(); 
var markerClickInteraction = new ol.interaction.Select({ 
    condition: ol.events.condition.click, 
    layers:[iconLayer], 
    style:styles.iconSelectedStyle, 
    features : featuresColl 
});