Skip to content

Commit

Permalink
No longer basing touch interactions off of initial coordinate.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom MacWright committed Aug 2, 2011
1 parent 011353c commit ecdb8fe
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 39 deletions.
54 changes: 35 additions & 19 deletions modestmaps.js
Expand Up @@ -66,8 +66,8 @@ if (!com) {
[(point.scale || '1'), '0,0,0,0', [(point.scale || '1'), '0,0,0,0',
(point.scale || '1'), '0,0', (point.scale || '1'), '0,0',
'0,0,1,0', '0,0,1,0',
point.x + (((point.width * point.scale) - point.width) / 2), (point.x + (((point.width * point.scale) - point.width) / 2)).toFixed(4),
point.y + (((point.height * point.scale) - point.height) / 2), (point.y + (((point.height * point.scale) - point.height) / 2)).toFixed(4),
0,1].join(',') + ')'; 0,1].join(',') + ')';
} else { } else {
return 'matrix(' + return 'matrix(' +
Expand Down Expand Up @@ -781,7 +781,6 @@ if (!com) {
maxTapDistance: 10, maxTapDistance: 10,
maxDoubleTapDelay: 350, maxDoubleTapDelay: 350,
locations: {}, locations: {},
coordinate: null,
taps: [], taps: [],


init: function(map, options) { init: function(map, options) {
Expand All @@ -802,6 +801,7 @@ if (!com) {
for (var i = 0; i < e.touches.length; i += 1) { for (var i = 0; i < e.touches.length; i += 1) {
var t = e.touches[i]; var t = e.touches[i];
this.locations[t.identifier] = { this.locations[t.identifier] = {
scale: e.scale,
screenX: t.screenX, screenX: t.screenX,
screenY: t.screenY, screenY: t.screenY,
time: +new Date() time: +new Date()
Expand All @@ -825,7 +825,6 @@ if (!com) {


touchStartMachine: function(e) { touchStartMachine: function(e) {
this.interruptTouches(e); this.interruptTouches(e);
this.coordinate = this.map.coordinate.copy();
return MM.cancelEvent(e); return MM.cancelEvent(e);
}, },


Expand Down Expand Up @@ -924,34 +923,51 @@ if (!com) {


// Re-transform the actual map parent's CSS transformation // Re-transform the actual map parent's CSS transformation
onPanning: function(touch) { onPanning: function(touch) {
var start = this.locations[touch.identifier];
this.map.coordinate = this.coordinate.copy();
this.map.panBy( this.map.panBy(
touch.screenX - start.screenX, touch.screenX - this.locations[touch.identifier].screenX,
touch.screenY - start.screenY); touch.screenY - this.locations[touch.identifier].screenY);
},


onPanned: function(touch) { this.locations[touch.identifier] = {
// var m = this.oneTouchMatrix(touch); screenX: touch.screenX,
// this.map.panBy(m.x, m.y]); screenY: touch.screenY,
time: +new Date()
};
}, },


// During a pinch event, don't recalculate zooms and centers, onPanned: function(touch) { },
// but recalculate the CSS transformation
onPinching: function(e) { onPinching: function(e) {
this.map.coordinate = this.coordinate.copy(); this.map.zoomByAbout(
Math.log(e.scale) / Math.LN2 -
Math.log(this.locations[e.touches[0].identifier].scale) / Math.LN2,
new MM.Point(
((e.touches[0].screenX + e.touches[1].screenX) / 2),
((e.touches[0].screenY + e.touches[1].screenY) / 2))
);


this.map.panBy( this.map.panBy(
((e.touches[0].screenX + ((e.touches[0].screenX +
e.touches[1].screenX) / 2) - e.touches[1].screenX) / 2) -

// centerpoint of previous x
((this.locations[e.touches[0].identifier].screenX + ((this.locations[e.touches[0].identifier].screenX +
this.locations[e.touches[1].identifier].screenX) / 2), this.locations[e.touches[1].identifier].screenX) / 2),

((e.touches[0].screenY + ((e.touches[0].screenY +
e.touches[1].screenY) / 2) - e.touches[1].screenY) / 2) -

// centerpoint of previous y
((this.locations[e.touches[0].identifier].screenY + ((this.locations[e.touches[0].identifier].screenY +
this.locations[e.touches[1].identifier].screenY) / 2) this.locations[e.touches[1].identifier].screenY) / 2));
);
this.map.zoomBy(Math.log(e.scale) / Math.LN2 + this.coordinate.zoom - this.map.getZoom()); for (var i = 0; i < e.touches.length; i++) {
this.locations[e.touches[i].identifier] = {
screenX: e.touches[i].screenX,
screenY: e.touches[i].screenY,
scale: e.scale,
time: +new Date()
};
}
}, },


// When a pinch event ends, recalculate the zoom and center // When a pinch event ends, recalculate the zoom and center
Expand Down

0 comments on commit ecdb8fe

Please sign in to comment.