Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript GMAPSV3:如何在鼠标滚动地图之前取消鼠标滚动事件_Javascript_Google Maps_Google Maps Api 3_Overlay_Dom Events - Fatal编程技术网

Javascript GMAPSV3:如何在鼠标滚动地图之前取消鼠标滚动事件

Javascript GMAPSV3:如何在鼠标滚动地图之前取消鼠标滚动事件,javascript,google-maps,google-maps-api-3,overlay,dom-events,Javascript,Google Maps,Google Maps Api 3,Overlay,Dom Events,使用GoogleMapsV2,我能够通过处理和取消鼠标滚动事件来阻止鼠标滚动(DOMMouseScroll)事件转到地图并缩放地图。然而,在v3中,这不再有效 请注意,拖动和双击在到达地图之前是如何取消的,但是如果您尝试滚动文本,则DOMMouseScroll事件将直接进入地图 取消事件的代码与v2基本相同,如下所示: // Set the overlay's div_ property to this DIV this.div_ = div; var cancelEvent =

使用GoogleMapsV2,我能够通过处理和取消鼠标滚动事件来阻止鼠标滚动(DOMMouseScroll)事件转到地图并缩放地图。然而,在v3中,这不再有效

请注意,拖动和双击在到达地图之前是如何取消的,但是如果您尝试滚动文本,则DOMMouseScroll事件将直接进入地图

取消事件的代码与v2基本相同,如下所示:

  // Set the overlay's div_ property to this DIV
  this.div_ = div;

  var cancelEvent = function(e)
  {

        if( (navigator.userAgent.toLowerCase().indexOf('msie') != -1    && document.all) ||
                  navigator.userAgent.indexOf('Opera') > -1)  {
            window.event.cancelBubble = true;
            window.event.returnValue = false;
        } else {
            e.stopPropagation();
        }

        return false;
  }

  var panes = this.getPanes();
  panes.floatPane.appendChild(div);

  var stealEvents = [ 'mousedown', 'dblclick', 'DOMMouseScroll', 'onmousewheel', 'drag'];

  for( i=0; i < stealEvents.length; i++ ){
    google.maps.event.addDomListener(this.div_, stealEvents[i], cancelEvent);
  }


    // for IE/Opera
    if( (navigator.userAgent.toLowerCase().indexOf('msie') != -1    && document.all) || 
                    navigator.userAgent.indexOf('Opera') > -1)  {
        this.div_.attachEvent('onmousewheel', cancelEvents);
    }

    // for safari
    if ( navigator.userAgent.indexOf('AppleWebKit/') > -1)  {
        this.div_.onmousewheel = cancelEvents;
    }
//将覆盖的div_uu属性设置为此div
this.div=div;
var cancelEvent=函数(e)
{
if((navigator.userAgent.toLowerCase().indexOf('msie')!=-1&&document.all)||
navigator.userAgent.indexOf('Opera')>-1){
window.event.cancelBubble=true;
window.event.returnValue=false;
}否则{
e、 停止传播();
}
返回false;
}
var panes=this.getPanes();
窗格.floatPane.appendChild(div);
var stealEvents=['mousedown','dblclick','DOMMouseScroll','onmouseheel','drag'];
对于(i=0;i-1){
this.div_.attachEvent('onmousewheel',cancelEvents);
}
//狩猎旅行
if(navigator.userAgent.indexOf('AppleWebKit/')>-1){
this.div_.onmouseheel=cancelEvents;
}

初始化V3地图时,您可以指定一个选项来禁用滚轮缩放:

var mapOptions = {
  center: new google.maps.LatLng(-34.397, 150.644),
  zoom: 8,
  mapTypeId: google.maps.MapTypeId.ROADMAP,
  scrollwheel: false
};
var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);


您正在寻找的选项是滚动滚轮-您想将其设置为False-默认情况下,此设置为True。

John的回答非常棒,我无法评论[由于rep],所以我以这种方式回答-尽管答案已被接受(大约两年前)

显然JS的布尔值是小写的,所以正确的代码是:

var mapOptions = {
  center: new google.maps.LatLng(-34.397, 150.644),
  zoom: 8,
  mapTypeId: google.maps.MapTypeId.ROADMAP,
  scrollwheel: false
};
var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);

好啊我只是想取消活动,但在必要时关闭地图缩放/移动也可以。我想你不能像在v2中那样取消那个活动。