1

I would like to fully implement Google Map API-s solution in Openlayers. I activated the ctrl+scroll zoom, but the poor user cannot know how to zoom now, and the nicest solution would be this: https://developers.google.com/maps/documentation/javascript/interaction

I tought i could add an Overlay to the Map when scrolling and ctrl button is not pressed. But Ol doesn't have this kind of event listener. Any idea?

document.getElementById("map").addEventListener("scroll",function(){console.log("scroll")})
this.map.addEventListener("scroll",function(){console.log("scroll")})
1
  • Sorry, but it's not clear what your question is. In the title you talk about "adding a tooltip overlay event listener for scrolling', but in the body you talk about "fully implementing Google Map API-s solution"? What is this solution? How it's connected with the question implied in the title?
    – TomazicM
    Commented Nov 5, 2020 at 17:42

1 Answer 1

1

Try to attach this event listener to the viewport instead of the map itself. Also scroll event refers to the actual page being scrolled. What you probably need is to capture the mouse wheel event.

   map.getViewport().addEventListener("wheel", e => {
       //do your thing..
   });

Some default JS event listeners such as contextmenu, or wheel in your case, cannot be attached to the map because they are not included in the abstraction layer of the map object. However, keep in mind that I haven't tested it locally to see if this works, but I have made something similar with the contextmenu event listener. Apart from that, your case might need different handling of events meaning that you might want to capture the mouse wheel event in general and just check if the cursor is over the map or not in order to show the corresponding message. If you elaborate a bit more regarding your setup and show some more code, I'll be able to further help on this.

1
  • Thank you so much!
    – gregi1991
    Commented Nov 13, 2020 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.