5

Google Maps API shows a message over the map when a user scrolls with mouse over the map.

The message advises the user to press the Control key while scrolling with the mouse over map. This is a very nice solution to preserve normal page scroll with the mouse.

Is this possible in OpenLayers 3?

Really there are two behaviors that we want to achieve:

  1. How to detect that the user is doing scroll on the map with the mouse and show an alert that you must press control key?

  2. How can you make it so the zoom on the map can only be done by pressing control in addition to scrolling with the mouse?

  • Welcome to SE. PLease have a look at this link:gis.stackexchange.com/tour . It explains how SE works and provides a guide on how best to ask questions on the site. Try to be specific in asking your question, and if you have tried something, please post your code and where you are having trouble. Try to limit your question to only one question. If a question is too broad / unfocused it will be difficult for users to give you a definite answer. – Keagan Allan Feb 26 '18 at 8:11
  • Excuse my bad English. It was very important for me this question this morning, I was in a great hurry. I make it clearer. developers.google.com/maps/documentation/javascript/interaction This URL is link to behavior on google map and what We want to achieve with Open Layer – Falinsito Feb 26 '18 at 15:56
2

Here the answers to your questions:

  1. How to detect that the user is doing scroll on the map with the mouse and show an alert that you must press control key?
map.on('wheel', function(){
       //write whatyou like and add it in popup window

});

  1. How can you make it so the zoom on the map can only be done by pressing control in addition to scrolling with the mouse?

OpenLayers doesn't have this functionality but you can do it by creating something like in this link.

Also, you can do it with only (shift key) or (alt key)

     map.on('wheel', function(evt) {
            map.on('wheel', function(evt) {
    wheelZoom(evt);
});
function wheelZoom(evt) {
      if (ol.events.condition.shiftKeyOnly(evt) !== true) {
          evt.browserEvent.preventDefault();
      }
  };

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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