|
@@ -65,16 +65,27 @@
|
65
|
65
|
// 绑定事件 - 很多手机 click 有问题
|
66
|
66
|
map.addEventListener('click', (e) => onClick(e.point));
|
67
|
67
|
|
68
|
|
- //触摸移动时触发此事件 此时开启可以拖动。虽然刚初始化该地图不可以拖动,但是可以触发拖动事件。
|
69
|
|
- map.addEventListener("touchmove", function (e) {
|
70
|
|
- map.enableDragging();
|
|
68
|
+ // 下面使用短时间的模拟点击
|
|
69
|
+ let starPoint = null;
|
|
70
|
+ map.addEventListener("touchstart", function (e) {
|
|
71
|
+ starPoint = e.ab;
|
|
72
|
+ console.log('touchstart', starPoint, e);
|
|
73
|
+ // map.enableDragging();
|
71
|
74
|
});
|
72
|
|
- //触摸结束时触发次此事件 此时开启禁止拖动
|
|
75
|
+
|
73
|
76
|
map.addEventListener("touchend", function (e) {
|
74
|
|
- map.disableDragging();
|
75
|
|
- });
|
|
77
|
+ const endPoint = e.ab;
|
|
78
|
+ console.log('touchend', endPoint, e);
|
|
79
|
+
|
|
80
|
+ const dx = Math.abs(endPoint.x - starPoint.x);
|
|
81
|
+ const dy = Math.abs(endPoint.y - starPoint.x);
|
|
82
|
+ const dis = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
|
76
|
83
|
|
77
|
|
- map.disableDragging();
|
|
84
|
+ if (Math.abs(dis) < 50) {
|
|
85
|
+ onClick(e.point)
|
|
86
|
+ }
|
|
87
|
+ // map.disableDragging();
|
|
88
|
+ });
|
78
|
89
|
|
79
|
90
|
// 显示 marker
|
80
|
91
|
countries.value.forEach(renderCountry);
|