如何使用Google Maps API禁用鼠标滚轮缩放 [英] How to disable mouse scroll wheel scaling with Google Maps API
问题描述
我正在使用Google Maps API(v3)在页面上绘制几张地图。我想要做的一件事就是在地图上滚动鼠标滚轮时禁用缩放,但我不确定如何。
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.
我禁用了scaleControl(即删除缩放UI元素),但这并不妨碍滚轮缩放。
I have disabled the scaleControl (i.e. removed the scaling UI element), but this doesn't prevent scroll wheel scaling.
这是我的函数的一部分(它是一个简单的jQuery插件):
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
};
推荐答案
在Maps API的第3版中,您可以简单地设置在滚轮选项设置为false =noreferrer> MapOptions 属性:
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);
如果您使用Maps API的版本2,则必须使用 disableScrollWheelZoom() API调用如下:
If you were using version 2 of the Maps API you would have had to use the disableScrollWheelZoom() API call as follows:
map.disableScrollWheelZoom();
enableScrollWheelZoom()
API调用,否则它将被禁用。
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.
这篇关于如何使用Google Maps API禁用鼠标滚轮缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!