Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scrollWheelZoom set as false, map is still zoomable with mouse wheel #2720

Closed
Oxonium opened this issue Jun 3, 2014 · 8 comments
Closed

Comments

@Oxonium
Copy link

Oxonium commented Jun 3, 2014

Hey ! :)

I have a hard time disabling the scroll wheel zoom on my map. The scrollWheelZoom option is set as false, but the map is still zoomable :

Code :

_map.leafletMap.options.scrollWheelZoom = false;

Result in console :

scrollwheelzoom

Do you have any idea about this issue ?

Thanks a lot in advance !

Em.

@mourner
Copy link
Member

mourner commented Jun 3, 2014

The right way is map.scrollWheelZoom.disable().

@mourner mourner closed this as completed Jun 3, 2014
@Oxonium
Copy link
Author

Oxonium commented Jun 3, 2014

Great !

I thought this option was to be set like minZoom and maxZoom. Anyway.

Thanks ;)

@timkelty
Copy link

@mourner Why is it listed as an option then if it doesn't work? http://leafletjs.com/reference.html#map-scrollwheelzoom

@perliedman
Copy link
Member

perliedman commented Apr 25, 2017

@timblakely it works; if you set scrollWheelZoom: false when creating your map, it will not let you zoom with the scroll wheel.

Although not entirely apparent from the question, the issue is if you want to disable scroll wheel zoom after the map is instantiated. You can't do it by just overwriting the option, Leaflet has no way of knowing that you changed the option. Instead, you need to disable the scrollWheelZoom handler as described by @mourner above.

@timkelty
Copy link

@perliedman Ah, sorry for the confusion.
All makes sense now, thanks.

@snehakamble
Copy link

map.scrollWheelZoom.disable(). is not working for my case.
I have initialised map earlier like :
map = new L.Map('container',
{
center: [20, 0],
zoom: 2,
attributionControl: false,
scrollWheelZoom: false
});

now on ctrl+scroll need to set scrollWheelZoom: true. Can anyone please help , how to update the leaflet properties?

@perliedman
Copy link
Member

@snehakamble if you want to enabled the scroll wheel again, simply use map.scrollWheelZoom.enable() instead.

@lbrassaw
Copy link

lbrassaw commented Dec 1, 2023

I'm trying to disable an existing map scrollWheelZoom as per the above

document.addEventListener("DOMContentLoaded", function () { var existingMap = L.DomUtil.get('map-edit-field-geo-location-0-value'); existingMap.scrollWheelZoom.disable(); });

but am getting a TypeError: Cannot read properties of undefined (reading 'disable'). What am I missing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants