如何获得地图控件或交互

Mor*_*tch 9 openlayers-3

如何从ol.Map获得特定的ol.control或ol.interaction?我在一个页面上有几个动态添加的地图,我希望能够访问ol.interaction.Select.

小智 15

map.getInteractions().forEach(function (interaction) {
  if(interaction instanceof ol.interaction.Select) { ... }
});
Run Code Online (Sandbox Code Playgroud)

控件也一样.