How does one get a specific ol.control or ol.interaction from ol.Map? I have several dynamically added maps on a single page and I want to be able to access the ol.interaction.Select.
Asked
Active
Viewed 7,060 times
10
-
1It's very unclear what do you need! – Jonatas Walker Aug 12 '15 at 16:42
-
For example, how would I get the ol.interaction.Select interaction from a ol.Map? Something like myMap.getInteraction("ol.interaction.Select")... – MoreScratch Aug 12 '15 at 17:14
-
Should be able to call `map.getInteractions()` or `map.getControls()` https://github.com/openlayers/ol3/blob/e848acd806d2cbb5e7134da9d05e0a48a48e0ac5/src/ol/map.js#L790 – Timh Aug 12 '15 at 17:15
1 Answers
17
map.getInteractions().forEach(function (interaction) {
if(interaction instanceof ol.interaction.Select) { ... }
});
Same thing for controls.

Timh
- 492
- 3
- 11
-
Thank you very much. I was doing (interaction.constructor.name === "DragZoom"). It was working in dev mode but not in production mode with webpack. – Nicolas Boisteault Jan 03 '19 at 17:17