1

I have a map that I wish to integrate into a page. When I simply scroll over it, the map won't zoom and I can view the next content. But when I ctrl + scroll over the map, it will zoom in.

How can I do that with mapbox?

2 Answers 2

2

Try this (no jquery required):

map.on("wheel", event => {
  if (event.originalEvent.ctrlKey) {
    return;
  }

  if (event.originalEvent.metaKey) {
    return;
  }

  if (event.originalEvent.altKey) {
    return;
  }

  event.preventDefault();
});

see https://github.com/mapbox/mapbox-gl-js/issues/6884

Sign up to request clarification or add additional context in comments.

1 Comment

2024, it works as intended. Great tip!
0

Try this, where map is your map variable. Also, you can bind this event on some div, I think, not the whole window.

$(window).bind('mousewheel DOMMouseScroll', function(event) 
{
    if(event.ctrlKey == true) {
        map['scrollZoom'].enable();
    }
    else {
        map['scrollZoom'].disable();
    }
});

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.