Skip to content

Commit

Permalink
Fix preventDefault for touch events.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Apr 8, 2011
1 parent 2035dac commit 4defaf6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 33 deletions.
2 changes: 1 addition & 1 deletion examples/iphone4/iphone4.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" />
<meta name="viewport" content="initial-scale=1,maximum-scale=1"/>
<script type="text/javascript" src="../../polymaps.js"></script>
<style type="text/css">

Expand Down
9 changes: 2 additions & 7 deletions polymaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -1847,7 +1847,6 @@ po.touch = function() {
locations = {}; // touch identifier -> location

window.addEventListener("touchmove", touchmove, false);
window.addEventListener("touchend", touchend, false);

function touchstart(e) {
var i = -1,
Expand All @@ -1857,14 +1856,14 @@ po.touch = function() {
t = e.touches[i];
locations[t.identifier] = map.pointLocation(map.mouse(t));
}
e.preventDefault();
}

function touchmove(e) {
switch (e.touches.length) {
case 1: {
var t0 = e.touches[0];
map.zoomBy(0, map.mouse(t0), locations[t0.identifier]);
e.preventDefault();
break;
}
case 2: { // TODO rotation!
Expand All @@ -1885,14 +1884,10 @@ po.touch = function() {
dc = Math.sqrt(cx * cx + cy * cy),
z2 = Math.log(dp / dc) / Math.log(2); // zoom level
map.zoomBy(z2 - map.zoom(), p2, l2);
e.preventDefault();
break;
}
}
e.preventDefault();
}

function touchend(e) {
e.preventDefault();
}

touch.map = function(x) {
Expand Down
Loading

0 comments on commit 4defaf6

Please sign in to comment.