ol/interaction之——select
一、参数
import Select from ‘ol/interaction/Select’;
this.selectClick = new Select({
condition: click,//click点击,pointerMove鼠标指针移动
});
this.map.addInteraction(this.selectClick)
二、事件
1.select事件
select.on('select', function (e) {
if(e.target.getFeatures().array_.length>0){
// e.target.getFeatures(),是选中的Features
e.target.getFeatures().array_.forEach(item=>{
item.setStyle(null) //这里去掉选中时默认的样式 //去除openlayers默认高亮显示样式
})
document.getElementById("OLmap").style.cursor = 'pointer'//选中时鼠标样式为pointer(一只手)
}else{
document.getElementById("OLmap").style.cursor = 'default'//未选中时鼠标为默认样式(一个箭头)
}
});
参考文章
openlayers 去除默认高亮显示样式: