加载地图后,Google地图API v3不会停用滚轮 [英] Google Maps API v3 won't disable scroll wheel after map loads

查看:141
本文介绍了加载地图后,Google地图API v3不会停用滚轮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网站上实施谷歌地图,除了我无法在地图加载后禁用滚轮之外,一切都很好。如果我在地图加载之前设置了该选项以滚动:false,那么滚轮将被禁用,但如果稍后尝试并执行操作(我有一个启用/禁用滚轮的复选框)。

以下是我在网页加载时的谷歌地图选项:

  var myOptions = {
zoom:15,
center:currentPosition,
draggable:true,
scrollwheel:true,
mapTypeId:google.maps.MapTypeId.ROADMAP
};

map = new google.maps.Map(document.getElementById(map_canvas),myOptions);

然后在点击事件触发复选框后,我有以下代码来禁用滚轮。

  var checked = $('#chkPin')这是一个非常有趣的例子,draggable = false正在工作并阻止我拖动地图。 )。是( ':检查'); 
log(map active:+ checked);
if(checked){
map.scrollwheel = false;
map.draggable = false;
map.zoomControl = false;
} else {
map.scrollwheel = true;
map.draggable = true;
map.zoomControl = true;


解决方案

在Maps API上编辑未记录的属性对象不受支持,并可能导致不可预知的结果。您不应直接修改地图对象上的属性。相反,使用其中一个记录的选项修改属性:



特定于对象的getter / setter:



  map.setOptions({'scrollwheel':false}); 



MVCObject通用getter / setters:



  map.set('scrollwheel',false); 
var isScrollWheelEnabled = map.get('scrollwheel');

这两个选项都已成功禁用地图缩放后的滚轮缩放。


I'm implementing google maps on a website and everything is working great, except that I can't seem to be able to disable the scrollwheel after the maps has loaded. If I set the option before the map loads to scrollwheel: false, then the scroll wheel is disabled, but if I try and do it later (I have a checkbox that enables/disables the scroll wheel).

Here are my options for the google map on page load:

var myOptions = {
            zoom: 15,
            center: currentPosition,
            draggable: true,
            scrollwheel: true,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };

map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

and then after the click event has trigger on the checkbox, I have the following code to disable the scrollwheel. funny enough, the draggable = false is working and prevents me from dragging the map.

var checked = $('#chkPin').is(':checked');
        log("map active: " + checked);
        if (checked) {
            map.scrollwheel = false;
            map.draggable = false;
            map.zoomControl = false;
        } else {
            map.scrollwheel = true;
            map.draggable = true;
            map.zoomControl = true;
        }

解决方案

Editing undocumented properties on Maps API objects is not supported and can lead to unpredictable results. You shouldn't directly modify properties on a map object. Instead, modify the properties using one of the documented options:

Object specific defined getters/setters:

map.setOptions({'scrollwheel': false});

MVCObject generic getters/setters:

map.set('scrollwheel', false);
var isScrollWheelEnabled = map.get('scrollwheel');

Both of these options successfully disabled scrollwheel zooming of the map after it had already been initialized.

这篇关于加载地图后,Google地图API v3不会停用滚轮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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