1

How to prevent the map from moving when a user zooms in with scrollwheel?

I would like the center to be preserved in any case.

var mymap = L.map('spotmap', {
   dragging: false
}).setView(spot_LatLng, 18);

var marker = L.marker(spot_LatLng).addTo(mymap);

1 Answer 1

3

Set scrollWheelZoom option to 'center' when defining map:

var mymap = L.map('spotmap', {
   dragging: false,
   scrollWheelZoom: 'center'
}).setView(spot_LatLng, 18);
1
  • In the doc : Whether the map can be zoomed by using the mouse wheel. If passed 'center', it will zoom to the center of the view regardless of where the mouse was. Thank you very much @TomazicM
    – rudak
    Apr 24, 2019 at 20:26

Your Answer

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

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