首页 文章

在嵌入式Google Map 上禁用鼠标滚轮放大

提问于
浏览
193

我正在使用WordPress网站,作者通常在大多数帖子中使用iFrame嵌入Google Map .

有没有办法使用Javascript通过鼠标滚轮禁用所有这些缩放?

30 回答

  • 1

    我遇到了同样的问题:当滚动页面然后指针变成 Map 时,它开始放大/缩小 Map 而不是继续滚动页面 . :(

    所以我解决了这个问题,在每个gmap iframe 插入之前放了一个带有 .overlay.overlay ,请参阅:

    <html>
      <div class="overlay" onClick="style.pointerEvents='none'"></div>
      <iframe src="https://mapsengine.google.com/map/embed?mid=some_map_id" width="640" height="480"></iframe>
    </html>
    

    在我的CSS中我创建了这个类:

    .overlay {
       background:transparent; 
       position:relative; 
       width:640px;
       height:480px; /* your iframe height */
       top:480px;  /* your iframe height */
       margin-top:-480px;  /* your iframe height */
    }
    

    div将覆盖 Map ,防止指针事件进入 . 但是如果你单击div,它对指针事件变得透明,再次激活 Map !

    我希望得到你的帮助:)

  • 1

    我在这次讨论中尝试了第一个答案,无论我做了什么,它都不适合我,所以我提出了自己的解决方案:

    用一个类(本例中为.maps)包装iframe,理想情况下嵌入代码:http://embedresponsively.com/ - 将iframe的CSS更改为 pointer-events: none ,然后使用jQuery的click元素将父元素更改为iframes css为 pointer-events:auto

    HTML

    <div class='embed-container maps'>
        <iframe width='600' height='450' frameborder='0' src='http://foo.com'></iframe>
    </div>
    

    CSS

    .maps iframe{
        pointer-events: none;
    }
    

    jQuery的

    $('.maps').click(function () {
        $('.maps iframe').css("pointer-events", "auto");
    });
    
    $( ".maps" ).mouseleave(function() {
      $('.maps iframe').css("pointer-events", "none"); 
    });
    

    我确信只有JavaScript才能做到这一点,如果有人想要添加到这个感觉上 .

    重新激活指针事件的JavaScript方法非常简单 . 只需给iFrame(即“iframe”)提供一个Id,然后将onclick事件应用于该币体div:

    onclick="document.getElementById('iframe').style.pointerEvents= 'auto'"
    
    <div class="maps" onclick="document.getElementById('iframe').style.pointerEvents= 'auto'">
       <iframe id="iframe" src="" width="100%" height="450" frameborder="0" style="border:0" allowfullscreen></iframe>
    </div>
    
  • 1

    我扩展了@nathanielperales解决方案 .

    在行为描述下面:

    • 单击 Map 以启用滚动

    • 当鼠标离开 Map 时,禁用滚动

    在javascript代码下面:

    // Disable scroll zooming and bind back the click event
    var onMapMouseleaveHandler = function (event) {
      var that = $(this);
    
      that.on('click', onMapClickHandler);
      that.off('mouseleave', onMapMouseleaveHandler);
      that.find('iframe').css("pointer-events", "none");
    }
    
    var onMapClickHandler = function (event) {
      var that = $(this);
    
      // Disable the click handler until the user leaves the map area
      that.off('click', onMapClickHandler);
    
      // Enable scrolling zoom
      that.find('iframe').css("pointer-events", "auto");
    
      // Handle the mouse leave event
      that.on('mouseleave', onMapMouseleaveHandler);
    }
    
    // Enable map zooming with mouse scroll when the user clicks the map
    $('.maps.embed-container').on('click', onMapClickHandler);
    

    here is an jsFiddle example .

  • 0

    我正在重新编辑#nathanielperales编写的代码,它真的对我有用 . 简单易捕,但只工作一次 . 所以我在JavaScript上添加了mouseleave() . 改编自#Bogdan的想法现在它完美无缺 . 试试这个 . 积分归#nathanielperales和#Bogdan所有 . 我只是结合了两个想法 . 感谢你们 . 我希望这也能帮助别人......

    HTML

    <div class='embed-container maps'>
        <iframe width='600' height='450' frameborder='0' src='http://foo.com'>  </iframe>
    </div>
    

    CSS

    .maps iframe{
        pointer-events: none;
    }
    

    jQuery的

    $('.maps').click(function () {
        $('.maps iframe').css("pointer-events", "auto");
    });
    
    $( ".maps" ).mouseleave(function() {
      $('.maps iframe').css("pointer-events", "none"); 
    });
    

    即兴 - 适应 - 克服

    这是一个jsFiddle example.

  • 3

    是的,很容易 . 我遇到了类似的问题 . 只需将css属性 "pointer-events" 添加到iframe div并将其设置为 'none' .

    Example:< iframe style="pointer-events:none" src= ........ >

    SideNote:此修复程序将禁用 Map 上的所有其他鼠标事件 . 它对我有用,因为我们不需要在 Map 上进行任何用户交互 .

  • 13
    var mapOptions = {
       scrollwheel: false,
       center: latlng,
       mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    
  • 249

    做了一些研究后,你有2个选择 . 由于嵌入了iframe的新 Map api似乎不支持禁用鼠标滚轮 .

    First 将使用旧的谷歌 Map (https://support.google.com/maps/answer/3045828?hl=en) .

    Second 将创建一个javascript函数,以简化为每个注释嵌入 Map 并使用参数(它的示例代码仅指向位置未显示精确解决方案)

    function createMap(containerid, parameters) {
      var mymap = document.getElementById(containerid),
      map_options = {
        zoom: 13,
        scrollwheel: false,
        /* rest of options */
      },
      map = new google.maps.Map(mymap, map_options);
    
      /* 'rest of code' to take parameters into account */
    }
    
  • 7

    有一个很棒的简单解决方案 .

    您需要在css中添加一个自定义类,用于设置指针事件以将canvas映射为none:

    .scrolloff{
       pointer-events: none;
    }
    

    然后,使用jQuery,您可以根据不同的事件添加和删除该类,例如:

    $( document ).ready(function() {
    
        // you want to enable the pointer events only on click;
    
            $('#map_canvas').addClass('scrolloff'); // set the pointer events to none on doc ready
            $('#canvas').on('click', function() {
                $('#map_canvas').removeClass('scrolloff'); // set the pointer events true on click
            });
    
        // you want to disable pointer events when the mouse leave the canvas area;
    
         $( "#map_canvas" ).mouseleave(function() {
              $('#map_canvas').addClass('scrolloff'); // set the pointer events to none when mouse leaves the map area
         });    
    });
    

    我在jsfiddle中创建了一个例子,希望有所帮助!

  • 2

    我只是在developers.google.com上注册了一个帐户,并获得了一个用于调用Maps API的令牌,并且只是禁用它(滚动:false):

    var map;
        function initMap() {
            map = new google.maps.Map(document.getElementById('container_google_maps'), {
                center: {lat: -34.397, lng: 150.644},
                zoom: 8,
                scrollwheel: false
            });
        }
    
  • 3

    这是我的方法 . 我发现很容易在各种网站上实现并一直使用它

    CSS和JavaScript:

    <style type="text/css">
    .scrolloff iframe   {
        pointer-events: none ;
    }
    </style>
    
    <script type="text/javascript">
    function scrollOn() {
        $('#map').removeClass('scrolloff'); // set the pointer events true on click
    
    }
    
    function scrollOff() {
        $('#map').addClass('scrolloff'); 
    
    }
    </script>
    

    在HTML中,您需要将iframe包装在div中 . <div id="map" class="scrolloff" onclick="scrollOn()" onmouseleave="scrollOff()" >

    function scrollOn() {
        $('#map').removeClass('scrolloff'); // set the pointer events true on click
       
    }
    
    function scrollOff() {
        $('#map').addClass('scrolloff'); // set the pointer events true on click
        
    }
    
    .scrolloff iframe   {
            pointer-events: none ;
        }
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div id="map" class="scrolloff" onclick="scrollOn()" onmouseleave="scrollOff()" ><iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d23845.03946309692!2d-70.0451736316453!3d41.66373705082399!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x89fb159980380d21%3A0x78c040f807017e30!2sChatham+Tides!5e0!3m2!1sen!2sus!4v1452964723177" width="100%" height="450" frameborder="0" style="border:0" allowfullscreen></iframe></div>
    

    希望这有助于任何寻找简单解决方案的人 .

  • 4

    这是一个简单的解决方案 . 只需将 pointer-events: none CSS设置为 <iframe> 即可禁用鼠标滚动 .

    <div id="gmap-holder">
        <iframe width="100%" height="400" frameborder="0" style="border:0; pointer-events:none"
                src="https://www.google.com/maps/embed/v1/place?q=XXX&key=YYY"></iframe>
    </div>
    

    如果要在用户单击 Map 时激活鼠标滚动,请使用以下JS代码 . 当鼠标移出 Map 时,它还将再次禁用鼠标滚动 .

    $(function() {
        $('#gmap-holder').click(function(e) {
            $(this).find('iframe').css('pointer-events', 'all');
        }).mouseleave(function(e) {
            $(this).find('iframe').css('pointer-events', 'none');
        });
    })
    
  • 0

    要在嵌入式Google Map 上禁用鼠标滚轮缩放,您只需将iframe的css属性指针事件设置为无:

    <style>
    #googlemap iframe {
        pointer-events:none;
    }
    </style>
    

    多数民众赞成......非常整洁吧?

    <div id="googlemap">
        <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3648.6714814904954!2d90.40069809681577!3d23.865796688563787!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x3755c425897f1f09%3A0x2bdfa71343f07395!2sArcadia+Green+Point%2C+Rd+No.+16%2C+Dhaka+1230%2C+Bangladesh!5e0!3m2!1sen!2sin!4v1442184916780" width="400" height="300" frameborder="0" style="border:0" allowfullscreen></iframe>
    </div>
    
  • 132

    嗯,对我来说,最好的解决方案是简单地使用这样:

    HTML:

    <div id="google-maps">
    <iframe frameborder="0" height="450" src="***embed-map***"  width="100"</iframe>
    </div>
    

    CSS:

    #google-maps iframe { pointer-events:none; }
    

    JS:

    <script>
      $(function() {
        $('#google-maps').click(function(e) {
            $(this).find('iframe').css('pointer-events', 'auto');
        }).mouseleave(function(e) {
            $(this).find('iframe').css('pointer-events', 'none');
        });
      })
    </script>
    

    RESULT

    注意事项:

    最好的方法是添加一个带有深色透明度和文本的叠加层:当 mouse wheel is deactivated 时点击浏览“但是当它是 activated (点击它之后)后,带文字的透明度将消失,用户可以按预期浏览 Map . 任何线索怎么做?

  • 1

    添加样式 pointer-events:none; 这个工作正常

    <iframe style="pointer-events:none;" src=""></iframe>
    
  • 0

    这是我的问题的解决方案,我正在构建一个WP站点,所以这里有一些PHP代码 . 但关键是 Map 对象中的 scrollwheel: false, .

    function initMap() {
            var uluru = {lat: <?php echo $latitude; ?>, lng: <?php echo $Longitude; ?>};
            var map = new google.maps.Map(document.getElementById('map'), {
                zoom: 18,
                scrollwheel: false,
                center: uluru
            });
            var marker = new google.maps.Marker({
                position: uluru,
                map: map
            });
        }
    

    希望这会有所帮助 . 干杯

  • 2

    最简单的方法是使用像 :before:after 这样的伪元素 .
    此方法不需要任何其他html元素或jquery .
    如果我们有这个html结构:

    <div class="map_wraper">
    
        <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d405689.7826944034!2d-122.04109805!3d37.40280355!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x808fb68ad0cfc739%3A0x7eb356b66bd4b50e!2sSilicon+Valley%2C+CA!5e0!3m2!1sen!2sro!4v1438864791455" width="600" height="450" frameborder="0" style="border:0" allowfullscreen></iframe>
    
    </div>
    

    然后我们需要做的就是使包装器相对于我们将创建的伪元素来阻止滚动

    .map_wraper{
        position:relative;
    }
    

    在此之后,我们将创建将在 Map 上定位的伪元素,以防止滚动:

    .map_wraper:after{
        background: none;
        content: " ";
        display: inline-block;
        font-size: 0;
        height: 100%;
        left: 0;
        opacity: 0;
        position: absolute;
        top: 0;
        width: 100%;
        z-index: 9;
    }
    

    而你已经完成了,没有jquery没有额外的HTML元素!这是一个有效的jsfiddle示例:http://jsfiddle.net/e6j4Lbe1/

  • 19

    这是我的简单解决方案 .

    例如,将iframe放在div中,并使用名为“maps”的类 .

    这将是您的iframe的CSS

    .maps iframe { pointer-events: none }
    

    这里有一个小的javascript,当你将div元素悬停至少1秒时,将iframe的pointer-events属性设置为“auto”(最适合我 - 将它设置为你喜欢的任何东西)并清除超时/当鼠标离开元素时,再次将其设置为“none” .

    var maptimer;
    
    $(".maps").hover(function(){
        maptimer = setTimeout(function(){
            $(".maps").find("iframe").css("pointer-events", "auto");
        },1000);
    },function(){
        clearTimeout(maptimer);
        $(".maps").find("iframe").css("pointer-events", "none");
    });
    

    干杯 .

  • 54

    我创建了一个非常简单的jQuery插件来解决这个问题 . 检查https://diazemiliano.github.io/googlemaps-scrollprevent

    (function() {
      $(function() {
        $("#btn-start").click(function() {
          $("iframe[src*='google.com/maps']").scrollprevent({
            printLog: true
          }).start();
          return $("#btn-stop").click(function() {
            return $("iframe[src*='google.com/maps']").scrollprevent().stop();
          });
        });
        return $("#btn-start").trigger("click");
      });
    }).call(this);
    
    Edit in JSFiddle Result JavaScript HTML CSS .embed-container {
      position: relative !important;
      padding-bottom: 56.25% !important;
      height: 0 !important;
      overflow: hidden !important;
      max-width: 100% !important;
    }
    .embed-container iframe {
      position: absolute !important;
      top: 0 !important;
      left: 0 !important;
      width: 100% !important;
      height: 100% !important;
    }
    .mapscroll-wrap {
      position: static !important;
    }
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script src="https://cdn.rawgit.com/diazemiliano/googlemaps-scrollprevent/v.0.6.5/dist/googlemaps-scrollprevent.min.js"></script>
    <div class="embed-container">
      <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d12087.746318586604!2d-71.64614110000001!3d-40.76341959999999!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x9610bf42e48faa93%3A0x205ebc786470b636!2sVilla+la+Angostura%2C+Neuqu%C3%A9n!5e0!3m2!1ses-419!2sar!4v1425058155802"
      width="400" height="300" frameborder="0" style="border:0"></iframe>
    </div>
    <p><a id="btn-start" href="#">"Start Scroll Prevent"</a>  <a id="btn-stop" href="#">"Stop Scroll Prevent"</a>
    </p>
    
  • 3

    使用来自@nathanielperales的回答我已经添加了悬停功能,因为当用户失去对 Map 的注意力再次停止滚动时,它会更好用:)

    $(function(){
        $('.mapa').hover(function(){
            stopScroll();},
                         function () {
        $('.mapa iframe').css("pointer-events", "none");
        });
    });
    
    function stopScroll(){
    $('.mapa').click(function () {
        $('.mapa iframe').css("pointer-events", "auto");
    });
    }
    
  • 0

    主题的变化:使用jQuery的简单解决方案,无需编辑CSS .

    // make iframe active on click, disable on mouseleave
    $('iframe.google_map').each( function(i, iframe) {
        $(iframe).parent().hover( // make inactive on hover
            function() { $(iframe).css('pointer-events', 'none');
        }).click( // activate on click
            function() { $(iframe).css('pointer-events', 'auto');
        }).trigger('mouseover'); // make it inactive by default as well
    });
    

    悬停侦听器附加到父元素,因此如果当前父元素较大,则只需在第3行之前用if包装iframe即可 .

    希望它对某些人有用 .

  • 24

    我自己偶然发现了这个问题,并在这个问题上使用了两个非常有用的答案的混搭:czerasz的回答和_1426317的回答 .

    他们都有很多事实,但在我的测试中,我发现一个人没有在移动设备上工作(移动设备中没有指针)和it doesn't work on任何不是v11的IE版本 . 通常我不会在意,但是有很多用户,我们需要一致的功能,所以我选择了覆盖解决方案,使用包装器使代码更容易 .

    所以,我的标记看起来像这样:

    <div class="map embed-container">
      <div id="map-notice" style="display: block;"> {Tell your users what to do!} </div>
      <div class="map-overlay" style="display: block;"></div>
      <iframe style="width:100%" src="https://www.google.com/maps/embed?pb=!1m14!1m8!1m3!1d3785.684302567802!2d-66.15578327375803!3d18.40721382009222!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x8c036a35d02b013f%3A0x5962cad95b9ec7f8!2sPlaza+Del+Sol!5e0!3m2!1sen!2spr!4v1415284687548" width="633" height="461" frameborder="0"></iframe>
    </div>
    

    然后样式是这样的:

    .map.embed-container {
      position:relative;
    }
    
    .map.embed-container #map-notice{
      position:absolute;
      right:0;
      top:0;
      background-color:rgb(100,100,100);/*for old IE browsers with no support for rgba()*/
      background-color: rgba(0,0,0,.50);
      color: #ccc;
      padding: 8px;
    }
    .map.embed-container .map-overlay{
      height:100%;
      width:100%;
      position:absolute;
      z-index:9999;
      background-color:rgba(0,0,0,0.10);/*should be transparent but this will help you see where the overlay is going in relation with the markup*/
    }
    

    最后剧本:

    //using jquery...
    var onMapMouseleaveHandler = function (event) {
      $('#map-notice').fadeIn(500);
      var elemento = $$(this);
      elemento.on('click', onMapClickHandler);
      elemento.off('mouseleave', onMapMouseleaveHandler);
      $('.map-overlay').fadeIn(500);
    }
    
    var onMapClickHandler = function (event) {
      $('#map-notice').fadeOut(500);
      var elemento = $$(this);
      elemento.off('click', onMapClickHandler);
      $('.map-overlay').fadeOut(500);
      elemento.on('mouseleave', onMapMouseleaveHandler);
    }
    $('.map.embed-container').on('click', onMapClickHandler);
    

    我还在GitHub gist中添加了我的测试解决方案,如果你想从那里得到东西......

  • 1

    这是一个使用CSS和Javascript的解决方案(即Jquery,但也适用于纯Javascript) . 同时 Map 也是响应式的 . 滚动时避免使用 Map 进行缩放,但可以通过单击来激活 Map .

    HTML / JQuery Javascript

    <div id="map" onclick="$('#googlemap').css('pointerEvents','auto'); return true;"> 
        <iframe id="googlemap" src="http://your-embed-url" height="350"></iframe>
    </div>
    

    CSS

    #map {
        position: relative; 
        padding-bottom: 36%; /* 16:9 ratio for responsive */ 
        height: 0; 
        overflow: hidden; 
        background:transparent; /* does the trick */
        z-index:98; /* does the trick */
    }
    #map iframe { 
        pointer-events:none; /* does the trick */
        position: absolute; 
        top: 0; 
        left: 0; 
        width: 100% !important; 
        height: 100% !important; 
        z-index:97; /* does the trick */
    }
    

    玩得开心 !

  • 8

    在Google Maps v3中,您现在可以禁用滚动缩放功能,从而获得更好的用户体验 . 其他 Map 功能仍然有效,您不需要额外的div . 我还认为应该为用户提供一些反馈,以便他们可以看到何时启用滚动,因此我添加了 Map 边框 .

    // map is the google maps object, '#map' is the jquery selector
    preventAccidentalZoom(map, '#map'); 
    
    // Disables and enables scroll to zoom as appropriate. Also
    // gives the user a UI cue as to when scrolling is enabled.
    function preventAccidentalZoom(map, mapSelector){
      var mapElement = $(mapSelector);
    
      // Disable the scroll wheel by default
      map.setOptions({ scrollwheel: false })
    
      // Enable scroll to zoom when there is a mouse down on the map.
      // This allows for a click and drag to also enable the map
      mapElement.on('mousedown', function () {
        map.setOptions({ scrollwheel: true });
        mapElement.css('border', '1px solid blue')
      });
    
      // Disable scroll to zoom when the mouse leaves the map.
      mapElement.mouseleave(function () {
        map.setOptions({ scrollwheel: false })
        mapElement.css('border', 'none')
      });
    };
    
  • 4

    这将为您提供一个响应式Google Map ,它将停止在iframe上滚动,但一旦点击就会让您缩放 .

    将其复制并粘贴到您的HTML中,但用您自己的iframe链接替换 . 他的一篇文章就是一个例子:Disable the mouse scroll wheel zoom on embedded Google Map iframes

    <style>
        .overlay {
        background:transparent;
        position:relative;
        width:100%; /* your iframe width */
        height:480px; /* your iframe height */
        top:480px; /* your iframe height */
        margin-top:-480px; /* your iframe height */
        }
    </style>
    <div class="overlay" onClick="style.pointerEvents='none'"></div>
    <iframe src="https://mapsengine.google.com/map/embed?mid=some_map_id" width="100%" height="480"></iframe>
    
  • 31

    将其添加到您的脚本:

    function initMap() {
        var uluru = {lat: -25.363, lng: 131.044};
        var map = new google.maps.Map(document.getElementById('map'), {
            zoom: 12,
            center: uluru,
            scrollwheel: false,
            disableDefaultUI: true,
            disableDoubleClickZoom: true
        });
        var marker = new google.maps.Marker({
            position: uluru,
            map: map
    });
    }
    
  • 0

    这是我的方法 .

    将其弹出到我的main.js或类似文件中:

    // Create an array of styles.
    var styles = [
                    {
                        stylers: [
                            { saturation: -300 }
    
                        ]
                    },{
                        featureType: 'road',
                        elementType: 'geometry',
                        stylers: [
                            { hue: "#16a085" },
                            { visibility: 'simplified' }
                        ]
                    },{
                        featureType: 'road',
                        elementType: 'labels',
                        stylers: [
                            { visibility: 'off' }
                        ]
                    }
                  ],
    
                    // Lagitute and longitude for your location goes here
                   lat = -7.79722,
                   lng = 110.36880,
    
                  // Create a new StyledMapType object, passing it the array of styles,
                  // as well as the name to be displayed on the map type control.
                  customMap = new google.maps.StyledMapType(styles,
                      {name: 'Styled Map'}),
    
                // Create a map object, and include the MapTypeId to add
                // to the map type control.
                  mapOptions = {
                      zoom: 12,
                    scrollwheel: false,
                      center: new google.maps.LatLng( lat, lng ),
                      mapTypeControlOptions: {
                          mapTypeIds: [google.maps.MapTypeId.ROADMAP],
    
                      }
                  },
                  map = new google.maps.Map(document.getElementById('map'), mapOptions),
                  myLatlng = new google.maps.LatLng( lat, lng ),
    
                  marker = new google.maps.Marker({
                    position: myLatlng,
                    map: map,
                    icon: "images/marker.png"
                  });
    
                  //Associate the styled map with the MapTypeId and set it to display.
                  map.mapTypes.set('map_style', customMap);
                  map.setMapTypeId('map_style');
    

    然后只需在您希望 Map 显示在页面上的地方插入一个空div .

    <div id="map"></div>

    您显然也需要调用Google Maps API . 我只是创建了一个名为mapi.js的文件并将其扔到my / js文件夹中 . 需要在上面的javascript之前调用此文件 .

    `window.google = window.google || {};
    google.maps = google.maps || {};
    (function() {
    
      function getScript(src) {
        document.write('<' + 'script src="' + src + '"' +
                       ' type="text/javascript"><' + '/script>');
      }
    
      var modules = google.maps.modules = {};
      google.maps.__gjsload__ = function(name, text) {
        modules[name] = text;
      };
    
      google.maps.Load = function(apiLoad) {
        delete google.maps.Load;
        apiLoad([0.009999999776482582,[[["http://mt0.googleapis.com/vt?lyrs=m@228000000\u0026src=api\u0026hl=en-US\u0026","http://mt1.googleapis.com/vt?lyrs=m@228000000\u0026src=api\u0026hl=en-US\u0026"],null,null,null,null,"m@228000000"],[["http://khm0.googleapis.com/kh?v=135\u0026hl=en-US\u0026","http://khm1.googleapis.com/kh?v=135\u0026hl=en-US\u0026"],null,null,null,1,"135"],[["http://mt0.googleapis.com/vt?lyrs=h@228000000\u0026src=api\u0026hl=en-US\u0026","http://mt1.googleapis.com/vt?lyrs=h@228000000\u0026src=api\u0026hl=en-US\u0026"],null,null,null,null,"h@228000000"],[["http://mt0.googleapis.com/vt?lyrs=t@131,r@228000000\u0026src=api\u0026hl=en-US\u0026","http://mt1.googleapis.com/vt?lyrs=t@131,r@228000000\u0026src=api\u0026hl=en-US\u0026"],null,null,null,null,"t@131,r@228000000"],null,null,[["http://cbk0.googleapis.com/cbk?","http://cbk1.googleapis.com/cbk?"]],[["http://khm0.googleapis.com/kh?v=80\u0026hl=en-US\u0026","http://khm1.googleapis.com/kh?v=80\u0026hl=en-US\u0026"],null,null,null,null,"80"],[["http://mt0.googleapis.com/mapslt?hl=en-US\u0026","http://mt1.googleapis.com/mapslt?hl=en-US\u0026"]],[["http://mt0.googleapis.com/mapslt/ft?hl=en-US\u0026","http://mt1.googleapis.com/mapslt/ft?hl=en-US\u0026"]],[["http://mt0.googleapis.com/vt?hl=en-US\u0026","http://mt1.googleapis.com/vt?hl=en-US\u0026"]],[["http://mt0.googleapis.com/mapslt/loom?hl=en-US\u0026","http://mt1.googleapis.com/mapslt/loom?hl=en-US\u0026"]],[["https://mts0.googleapis.com/mapslt?hl=en-US\u0026","https://mts1.googleapis.com/mapslt?hl=en-US\u0026"]],[["https://mts0.googleapis.com/mapslt/ft?hl=en-US\u0026","https://mts1.googleapis.com/mapslt/ft?hl=en-US\u0026"]]],["en-US","US",null,0,null,null,"http://maps.gstatic.com/mapfiles/","http://csi.gstatic.com","https://maps.googleapis.com","http://maps.googleapis.com"],["http://maps.gstatic.com/intl/en_us/mapfiles/api-3/14/0","3.14.0"],[2635921922],1,null,null,null,null,0,"",null,null,0,"http://khm.googleapis.com/mz?v=135\u0026",null,"https://earthbuilder.googleapis.com","https://earthbuilder.googleapis.com",null,"http://mt.googleapis.com/vt/icon",[["http://mt0.googleapis.com/vt","http://mt1.googleapis.com/vt"],["https://mts0.googleapis.com/vt","https://mts1.googleapis.com/vt"],[null,[[0,"m",228000000]],[null,"en-US","US",null,18,null,null,null,null,null,null,[[47],[37,[["smartmaps"]]]]],0],[null,[[0,"m",228000000]],[null,"en-US","US",null,18,null,null,null,null,null,null,[[47],[37,[["smartmaps"]]]]],3],[null,[[0,"h",228000000]],[null,"en-US","US",null,18,null,null,null,null,null,null,[[50],[37,[["smartmaps"]]]]],0],[null,[[0,"h",228000000]],[null,"en-US","US",null,18,null,null,null,null,null,null,[[50],[37,[["smartmaps"]]]]],3],[null,[[4,"t",131],[0,"r",131000000]],[null,"en-US","US",null,18,null,null,null,null,null,null,[[5],[37,[["smartmaps"]]]]],0],[null,[[4,"t",131],[0,"r",131000000]],[null,"en-US","US",null,18,null,null,null,null,null,null,[[5],[37,[["smartmaps"]]]]],3],[null,null,[null,"en-US","US",null,18],0],[null,null,[null,"en-US","US",null,18],3],[null,null,[null,"en-US","US",null,18],6],[null,null,[null,"en-US","US",null,18],0]]], loadScriptTime);
      };
      var loadScriptTime = (new Date).getTime();
      getScript("http://maps.gstatic.com/intl/en_us/mapfiles/api-3/14/0/main.js");
    })();`
    

    当您调用mapi.js文件时,请确保传递传感器false属性 .

    即: <script type="text/javascript" src="js/mapi.js?sensor=false"></script>

    API的新版本3由于某种原因需要包含传感器 . 确保在main.js文件之前包含mapi.js文件 .

  • 6

    对于谷歌 Map v2 - GMap2:

    ar map = new GMap2(document.getElementById("google_map"));
    map.disableScrollWheelZoom();
    
  • 3

    如果您使用Google Map 嵌入式API的iframe如下:

    <iframe width="320" height="400" frameborder="0" src="https://www.google.com/maps/embed/v1/place?q=Cagli ... "></iframe>
    

    你可以添加这个css样式:pointer-event:none; ES .

    <iframe width="320" height="400" frameborder="0" style="pointer-event:none;" src="https://www.google.com/maps/embed/v1/place?q=Cagli ... "></iframe>
    
  • 8

    这是我对@nathanielperales答案延伸的看法@chams,现在再次由我扩展 .

    HTML

    <div class='embed-container maps'>
        <iframe width='600' height='450' frameborder='0' src='http://foo.com'></iframe>
    </div>
    

    jQuery

    // we're doing so much with jQuery already, might as well set the initial state
    $('.maps iframe').css("pointer-events", "none");
    
    // as a safety, allow pointer events on click
    $('.maps').click(function() {
      $(this).find('iframe').css("pointer-events", "auto");
    });
    
    
    $('.maps').mouseleave(function() {
      // set the default again on mouse out - disallow pointer events
      $(this).find('iframe').css("pointer-events", "none");
      // unset the comparison data so it doesn't effect things when you enter again
      $(this).removeData('oldmousepos');
    });
    
    $('.maps').bind('mousemove', function(e){
      $this = $(this);
      // check the current mouse X position
      $this.data('mousepos', e.pageX);
      // set the comparison data if it's null or undefined
      if ($this.data('oldmousepos') == null) {
        $this.data('oldmousepos', $this.data('mousepos'));
      }
      setTimeout(function(){
        // some left/right movement - allow pointer events
        if ($this.data('oldmousepos') != $this.data('mousepos')) {
          $this.find('iframe').css("pointer-events", "auto");
        }
        // set the compairison variable
        $this.data('oldmousepos', $this.data('mousepos'));
      }, 300);
      console.log($this.data('oldmousepos')+ ' ' + $this.data('mousepos'));
    });
    
  • 0

    The simplest one

    <div id="myIframe" style="width:640px; height:480px;">
       <div style="background:transparent; position:absolute; z-index:1; width:100%; height:100%; cursor:pointer;" onClick="style.pointerEvents='none'"></div>
       <iframe src="https://www.google.com/maps/d/embed?mid=XXXXXXXXXXXXXX" style="width:640px; height:480px;"></iframe>
    </div>
    

相关问题