Openlayers ol.interaction.Select取消默认选中效果

说明:

在使用ol.interaction.Select进行点击查询时,默认会把点击选中的要素显示在地图上

我的需求是做轨迹回放,并可以点击轨迹上某一点,进行查询。这时候如果重新播放轨迹,会发现这个选中的残留,这时候我并不需要显示选中的要素。

解决方案:

这里可以用this.getFeatures().clear()解决问题,这里的this指向的是ol.interaction.Select

selecthover.on("select", function (evt) {
    if (evt.selected[0] == null) return;
    //取消选中要素高亮
    this.getFeatures().clear();
});

 

原文地址:https://www.cnblogs.com/giser-s/p/11855339.html