How to get a Map Control or Interaction
Asked Answered
W

1

10

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.

Whenever answered 12/8, 2015 at 16:21 Comment(3)
It's very unclear what do you need!Zygodactyl
For example, how would I get the ol.interaction.Select interaction from a ol.Map? Something like myMap.getInteraction("ol.interaction.Select")...Whenever
Should be able to call map.getInteractions() or map.getControls() github.com/openlayers/ol3/blob/…Galatea
G
17
map.getInteractions().forEach(function (interaction) {
  if(interaction instanceof ol.interaction.Select) { ... }
});

Same thing for controls.

Galatea answered 12/8, 2015 at 17:23 Comment(1)
Thank you very much. I was doing (interaction.constructor.name === "DragZoom"). It was working in dev mode but not in production mode with webpack.Penrod

© 2022 - 2024 — McMap. All rights reserved.