如何使用 Google Maps API 禁用鼠标滚轮缩放 [英] How to disable mouse scroll wheel scaling with Google Maps API

查看:22
本文介绍了如何使用 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 版中,您只需将 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();

scrollwheel 缩放在 Maps API 版本 3 中默认启用,但在版本 2 中它被禁用,除非通过 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆