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

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

问题描述

我想在 disable() 函数中添加代码,通过单击禁用"按钮来禁用在 Google 地图 API v3 中的拖动和缩放.

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>

推荐答案

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

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.

还有 disableDefaultUI 选项,它可能会考虑所有这些事件,但它可能会禁止点击现有元素.

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天全站免登陆