如何在Open Layer 3中选择矢量图层时设置样式?

时间:2016-04-21 13:45:45

标签: javascript openlayers-3

我刚画了一个多边形并修改它。 如何在Open Layer 3中选择多边形时设置样式

感谢

1 个答案:

答案 0 :(得分:0)

var selectClick = new ol.interaction.Select();
map.addInteraction(selectClick);
var sf =selectClick.getFeatures();
sf.on('add', addSelectionListener);
sf.on('remove', removeSelectionListener);

function addSelectionListener(){
var sf = selectClick.getFeatures(); 
sf.forEach(function(feature){
feature.setStyle(styles);
}); 
}
function removeSelectionListener(){
var sf = source.getFeatures();
sf.forEach(function(feature){
feature.setStyle(null);
}); 
}