Openlayers 遍历查找交互事件(ol.interaction)

说明

有时候需要遍历openlayers的交互事件,并根据不同类型进行操作/监控。

解决方案

方法一:实现了找到交互事件中的Select事件,并删除

map.getInteractions().forEach(function (interaction) {
            if (interaction instanceof ol.interaction.Select) {
                map.removeInteraction(interaction);
            }
        });

方法二:其实还有另一种写法,getArray()获取到的是Interactions的数组,可以用操作数组的方式去操作

var selectInteraction = map
        .getInteractions()
        .getArray()
        .find(interaction => {
          return interaction instanceof ol.interaction.Select;
        });
map.removeInteraction(selectInteraction);
原文地址:https://www.cnblogs.com/giser-s/p/12124075.html