通过单击按钮禁用缩放在Google地图中的拖动 [英] disable zooming dragging in Google maps by clicking on a button

查看:118
本文介绍了通过单击按钮禁用缩放在Google地图中的拖动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在disable()函数中添加代码,通过点击禁用按钮来禁用拖动和缩放谷歌地图API v3。

 < script type =text / javascript> 
var map;

函数initialize(){
var uluru = new google.maps.LatLng(21,57);
map = new google.maps.Map(document.getElementById(map),{
zoom:6,
center:uluru,
mapTypeId:google.maps.MapTypeId .HYBRID
});



function disable(){

}

< / script>


< body onload =initialize()>

< input type =buttonid =nextvalue =disableZoomDragonclick =disable()>

< / body>


解决方案

您可以使用 setOptions() 方法地图对象:

  map.setOptions({draggable:false,zoomControl:false,scrollwheel:false,disableDoubleClickZoom:true}) ; 

如果这不能防止缩放,您可以随时将最小和最大缩放设置为当前缩放
$ b 还有 disableDefaultUI 选项,它可能会考虑所有这些事件,但它可能会禁用点击现有元素。


I want to add codes inside disable() function to disable dragging and zooming in Google maps API v3 by clicking on 'disable' button.

<script type="text/javascript">
   var map;

  function initialize() {
var uluru = new google.maps.LatLng(21, 57);
map = new google.maps.Map(document.getElementById("map"), {
  zoom: 6,
  center: uluru,
  mapTypeId: google.maps.MapTypeId.HYBRID
});
}


function disable(){

}

</script>


<body onload="initialize()" >

   <input type="button" id="next" value="disableZoomDrag" onclick="disable()">

</body>

解决方案

You can use the setOptions() method on the map object:

map.setOptions({draggable: false, zoomControl: false, scrollwheel: false, disableDoubleClickZoom: true});

If this doesn't prevent zooming, you could always set the minimum and maximum zoom to the current zoom level.

There is also the disableDefaultUI option, which probably takes all of these events into account, but it might disable clicking on existing elements.

这篇关于通过单击按钮禁用缩放在Google地图中的拖动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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