简体   繁体   中英

How to set style on selection of vector layer in Open layer 3?

I just drawn a polygon and modifying it. How to set style on selection of polygon in Open layer 3

thanks

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);
}); 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM