//地图在触摸屏上放大缩小
var mapDom = document.getElementById('cheliangditu');
_offsetHeight = mapDom.offsetHeight;
_offsetWidth = mapDom.offsetWidth;
let _touchPoint,_touchStartDistance,_isPinch,_touchEndDistance;
document.getElementById("cheliangditu").addEventListener("touchstart", function(e){
e.preventDefault();
//console.log(e.touches.length);
if(e.touches.length ==1){
_touchPoint = {
x:e.touches[0].pageX,
y:e.touches[0].pageY
};
}else if(e.touches.length == 2){
let xDistance = e.touches[0].pageX - e.touches[1].pageX;
let yDistance = e.touches[0].pageY - e.touches[1].pageY;
_touchStartDistance = Math.abs( Math.pow((xDistance * xDistance + yDistance * yDistance), 0.5));
}
});
document.getElementById("cheliangditu").addEventListener("touchmove", function(e){
e.preventDefault();
console.log(e.touches.length);
if(e.touches.length == 1){
if(!_touchPoint) return;
var dx = e.touches[0].pageX - _touchPoint.x;
var dy = e.touches[0].pageY - _touchPoint.y;
map.panBy(dx,dy,{
noAnimation : true
});
_touchPoint.x = e.touches[0].pageX;
_touchPoint.y = e.touches[0].pageY;
}
else if(e.touches.length == 2){
_isPinch = true;
let xDistance = e.touches[0].pageX - e.touches[1].pageX;
let yDistance = e.touches[0].pageY - e.touches[1].pageY;
_touchEndDistance = Math.abs( Math.pow((xDistance * xDistance + yDistance * yDistance), 0.5));
}
});
document.getElementById("cheliangditu").addEventListener("touchend", function(e){
e.preventDefault();
if(_isPinch){
if(_touchEndDistance > _touchStartDistance && Math.abs(_touchEndDistance-_touchStartDistance)>50){
map.zoomIn();
}else if(_touchEndDistance < _touchStartDistance && Math.abs(_touchEndDistance-_touchStartDistance)>50){
map.zoomOut();
}
_touchEndDistance = 0;
_isPinch = false;
}
_touchPoint = null;
});