Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable mouse scroll wheel scaling with Google Maps API

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 }; 
like image 704
aaronrussell Avatar asked Feb 24 '10 22:02

aaronrussell


People also ask

How do I stop my scroll wheel from zooming?

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.

How do I stop the scroll wheel from zooming in Chrome?

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.

How do I turn off zoom on Google Maps?

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.

Why is Google zooming in when I scroll?

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.


2 Answers

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.

like image 123
Daniel Vassallo Avatar answered Oct 22 '22 21:10

Daniel Vassallo


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

like image 42
Simon East Avatar answered Oct 22 '22 20:10

Simon East