简体   繁体   English

在Google地图上禁用捏缩放[桌面]

[英]Disabling pinch-zoom on google maps [Desktop]

I have a website which uses Google Maps API v3 and i couldn't get the pinch-zoom property to work properly. 我有一个使用Google Maps API v3的网站,但我无法使pinch-zoom属性正常工作。 Instead of a Pinch-to-Zoom-In, the gesture always performs a Zoom-Out. 手势始终执行“缩小”,而不是“捏到放大”。

This is a PC monitor with Touch capability. 这是具有触摸功能的PC显示器。 So, as i was unable to get it work properly, i decided to disable the feature. 因此,由于无法正常工作,我决定禁用该功能。

I cancelled the touch event using below 我使用以下取消了触摸事件

document.documentElement.ontouchstart = function() {return false}

This has an unwanted side-effect. 这具有不希望的副作用。 This code cancels the entire touch events and hence user cannot use the Google Maps default Zoom control. 此代码会取消整个触摸事件,因此用户无法使用Google Maps默认的Zoom控件。 I tried changing the 'ontouchstart' to a 'ontouchmove' event but this is not preventing the map from zooming out. 我尝试将'ontouchstart'更改为'ontouchmove'事件,但这并不能阻止地图缩小。

Any ideas on how to disable the feature or may be how to fix the pinch-to-zoomIn feature? 关于如何禁用该功能的任何想法,或者可能是如何修复“捏到zoomIn”功能的想法? I can post the website url but its just a plain google map and you will not notice the issue unless if you a have touch enabled monitor. 我可以发布网站网址,但它只是一个简单的Google地图,除非您启用了触摸屏,否则您不会注意到该问题。

Here someone with a similar problem solved it this way, maybe it will work for you 在这里,有类似问题的人通过这种方式解决了问题,也许对您有用

var tblock = function (e) {
if (e.touches.length > 1) {
    e.preventDefault()
}

return false;
}

document.body.addEventListener("touchmove", tblock, true);

Google Maps API v3 Disable Pinch to Zoom on iPad Safari Google Maps API v3禁用在iPad Safari上缩放

And here 和这里

How to disable pinch in Android MapView 如何在Android MapView中禁用捏

Disabling "touchmove" only solves part of the problem, as Google Maps has its own ideas. 禁用“ touchmove”只能解决部分问题,因为Google Maps有其自己的想法。 Your device will allow you to pinch-zoom (to an extent, and inconsistently), until you disable Google Maps' own draggable option, eg 您的设备将允许您在一定程度上(不一致地)进行缩放,直到您禁用Google Maps自身的可拖动选项,例如

mymap.setOptions({draggable: false});

At least that's how it is on Android 4.4.2. 至少在Android 4.4.2上是这样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM