uiscrollview - Azure Maps 禁用触摸拖动
问题描述
在天蓝色地图上,我有以下示例:https ://docs.microsoft.com/en-us/azure/azure-maps/map-events
拖动被正确禁用,但触摸地图时页面根本不滚动任何人都经历过这种情况或以前使用过天蓝色地图。 使用安卓 Chrome 浏览器。
谢谢
解决方案
好的,我已经弄清楚了如何在触摸在地图顶部时实现地图的两指平移和页面的单指平移。这是一个代码示例:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="IE=Edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<!-- Add references to the Azure Maps Map control JavaScript and CSS files. -->
<link rel="stylesheet" href="https://atlas.microsoft.com/sdk/css/atlas.min.css?api-version=2" type="text/css" />
<script src="https://atlas.microsoft.com/sdk/js/atlas.min.js?api-version=2"></script>
<script type='text/javascript'>
var map, datasource;
function GetMap() {
//Initialize a map instance.
map = new atlas.Map('myMap', {
//Add your Azure Maps subscription key to the map SDK. Get an Azure Maps key at https://azure.com/maps
authOptions: {
authType: 'subscriptionKey',
subscriptionKey: '<Your Azure Maps Key>'
}
});
//Restrict the map to two finger panning only.
RestrictMapToTwoFingerPan(map);
}
function RestrictMapToTwoFingerPan(map) {
var pointerCount = 0;
//Monitor the drag start event.
map.events.add('dragstart', function (e) {
//Determine if the drag event is due to touch.
if (e.originalEvent && pointerCount === 1) {
//If there is only one touch point, disable drag panning by disablling, then re-enabling to cancel the current pan request.
//Disable then re-enable the drag panning. This will cancel the single touch drag functionality.
map.setUserInteraction({ dragPanInteraction: false });
map.setUserInteraction({ dragPanInteraction: true });
}
});
//Add touch events to the map container and monitor the movement and move the page accordingly when there is a single touch.
var pageX = 0;
var pageY = 0;
var scale = 1;
var mapDiv = map.getMapContainer();
var touchStartHandler = function (e) {
var px, py;
if (window.PointerEvent) {
if (e.pointerType !== 'touch') {
return;
}
pointerCount++;
px = e.pageX;
py = e.pageY;
} else {
pointerCount = e.touches.length;
px = e.touches[0].pageX;
py = e.touches[0].pageY;
}
if (pointerCount === 2) {
e.stopImmediatePropagation();
e.preventDefault();
return;
}
pageX = px;
pageY = py;
};
var touchMoveHandler = function (e) {
var px, py;
if (window.PointerEvent) {
if (e.pointerType !== 'touch') {
return;
}
px = pageX - e.screenX;
py = pageY - e.screenY;
} else {
pointerCount = e.touches.length;
px = pageX - e.touches[0].screenX;
py = pageY - e.touches[0].screenY;
}
if (pointerCount === 2) {
return;
}
if (scale === e.scale) {
e.stopImmediatePropagation();
e.preventDefault();
}
scale = e.scale;
window.scrollTo(px, py);
};
//Add support for Pointer Events and fallback onto touch events. Edge only supports pointer events, and Safari only supports touch events. Chrome supports both.
if (window.PointerEvent) {
mapDiv.addEventListener('pointerdown', touchStartHandler, false);
mapDiv.addEventListener('pointerup', (e) => {
if (e.pointerType === 'touch') {
pointerCount--;
}
}, false);
mapDiv.addEventListener('pointermove', touchMoveHandler, false);
} else {
mapDiv.addEventListener('touchstart', touchStartHandler, false);
mapDiv.addEventListener('touchmove', touchMoveHandler, false);
}
}
</script>
</head>
<body onload="GetMap()">
<div id="myMap" style="position:relative;width:100%;height:600px;"></div>
<br /><br />Adding several new lines so that the sample can be scrolled.<br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
</body>
</html>
推荐阅读
- sql - 如何在单个记录中输出不同的值
- javascript - 如何使用 color-thief javascript 库指定图像中提取颜色的数量?
- apache-spark - spark delta 覆盖特定分区
- json - 如何使用 JSON_EXTRACT 或 JSON_EXTRACT_SCALAR 在 Big Query 中读取多级 JSON 数据
- php - 如何在 Laravel 中使用 Faker 格式化程序创建随机名称?
- python - 根据两个numpy数组上的多个条件创建numpy数组
- ios - UIViewController 的字典属性被设置但在 viewDidLoad() 中为空
- javascript - Marklogic 异常处理
- go - 使用字符串访问 []byte 类型的结构字段
- java - 如何在 JUnit 中测试这样的复杂方法?