Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed issues on touch devices

  • Loading branch information...
commit cd2d753fce0586b8c892d4a84798b9a6634b6878 1 parent 9a3f579
@bjornd authored
Showing with 13 additions and 2 deletions.
  1. +12 −2 lib/world-map.js
  2. +1 −0  tests/index.html
View
14 lib/world-map.js
@@ -309,7 +309,10 @@ jvm.WorldMap.prototype = {
lastTouchesLength,
handleTouchEvent = function(e){
var touches = e.originalEvent.touches,
- scale;
+ offset,
+ scale,
+ transXOld,
+ transYOld;
if (e.type == 'touchstart') {
lastTouchesLength = 0;
@@ -317,11 +320,15 @@ jvm.WorldMap.prototype = {
if (touches.length == 1) {
if (lastTouchesLength == 1) {
+ transXOld = map.transX;
+ transYOld = map.transY;
map.transX -= (touchX - touches[0].pageX) / map.scale;
map.transY -= (touchY - touches[0].pageY) / map.scale;
map.applyTransform();
map.label.hide();
- e.preventDefault();
+ if (transXOld != map.transX || transYOld != map.transY) {
+ e.preventDefault();
+ }
}
touchX = touches[0].pageX;
touchY = touches[0].pageY;
@@ -339,6 +346,7 @@ jvm.WorldMap.prototype = {
map.label.hide();
e.preventDefault();
} else {
+ offset = jvm.$(map.container).offset();
if (touches[0].pageX > touches[1].pageX) {
centerTouchX = touches[1].pageX + (touches[0].pageX - touches[1].pageX) / 2;
} else {
@@ -349,6 +357,8 @@ jvm.WorldMap.prototype = {
} else {
centerTouchY = touches[0].pageY + (touches[1].pageY - touches[0].pageY) / 2;
}
+ centerTouchX -= offset.left;
+ centerTouchY -= offset.top;
touchStartScale = map.scale;
touchStartDistance = Math.sqrt(
Math.pow(touches[0].pageX - touches[1].pageX, 2) +
View
1  tests/index.html
@@ -253,6 +253,7 @@
</script>
</head>
<body>
+ <div style="height: 400px"></div>
<div id="map1" style="width: 600px; height: 400px"></div>
<button id="focus-single">Focus on Australia</button>
<button id="focus-multiple">Focus on Australia and Japan</button>

1 comment on commit cd2d753

@mshetler

I've been trying to muddle through adding support for MSTouch (IE10+). So far I'm not having much luck. Any chance this could be included for touch support?

Please sign in to comment.
Something went wrong with that request. Please try again.