I am using Google Maps API (v3) to draw a few maps on a page. One thing I'd like to do is disable zooming when you scroll the mouse wheel over the map, but I'm unsure how.
I have disabled the scaleControl (i.e. removed the scaling UI element), but this doesn't prevent scroll wheel scaling.
Here is part of my function (it's a simple jQuery plugin):
$.fn.showMap = function(options, addr){ options = $.extend({ navigationControl: false, mapTypeControl: false, scaleControl: false, draggable: false, mapTypeId: google.maps.MapTypeId.ROADMAP }, options); var map = new google.maps.Map(document.getElementById($(this).attr('id')), options); // Code cut from this example as not relevant };
Disable the Pinch zoom option In the Mouse Properties pop-up window, select the Device Settings tab. Click on the Options button, and open the specific Synaptic settings. Inside the Synaptic Touchpad Properties window, select the Pinch zoom option. Uncheck the option associated with Enable Pinch Zoom.
By default, Chrome sets the zoom level to 100%. To manually adjust the settings, use the Ctrl key and “+” or “-” combos to increase or decrease the page magnification. If you are using a mouse, you can hold down the keyboard Ctrl key and use the mouse wheel to zoom in or out.
Show activity on this post. map. setOptions({draggable: false, zoomControl: false, scrollwheel: false, disableDoubleClickZoom: true}); If this doesn't prevent zooming, you could always set the minimum and maximum zoom to the current zoom level.
Method 1: Testing for stuck CTRL key As it turns out, one of the most common causes that will trigger this kind of behavior is a stuck CTRL-key. If you didn't know, if you press any of the CTRL keys and scroll upwards or downwards, the mouse's scroll will produce zooming.
In version 3 of the Maps API you can simply set the scrollwheel
option to false within the MapOptions properties:
options = $.extend({ scrollwheel: false, navigationControl: false, mapTypeControl: false, scaleControl: false, draggable: false, mapTypeId: google.maps.MapTypeId.ROADMAP }, options);
If you were using version 2 of the Maps API you would have had to use the disableScrollWheelZoom() API call as follows:
map.disableScrollWheelZoom();
The scrollwheel
zooming is enabled by default in version 3 of the Maps API, but in version 2 it is disabled unless explicitly enabled with the enableScrollWheelZoom()
API call.
Daniel's code does the job (thanks a heap!). But I wanted to disable zooming completely. I found I had to use all four of these options to do so:
{ zoom: 14, // Set the zoom level manually zoomControl: false, scaleControl: false, scrollwheel: false, disableDoubleClickZoom: true, ... }
See: MapOptions object specification
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With