Thanks for the update Andy, I understand multi-touch wasn't really available in previous versions of Android. I'm hoping that by the end of the summer most devices (that can support it) will use ICS and support this feature.In the meantime I've continued with my own custom solution. I'm still planning to allow users to zoom manually, because I understand I can't rely on pinch exclusively atm.I've improved it a bit, zooming in now takes consideration of the position of the fingers when doing the pinch. Anyone like me who wants to play with this, maybe this can inspire you:However note I'm only testing on a Samsung Galaxy Tab 10.1 with Android 3.2, so ymmvWhen the map is ready:
$("#mapDiv").fidget({ pinch: function(){ _this.onMapPinch.apply(_this, arguments); } });
The pinch handler
MapPage.prototype.onMapPinch = function(event, fidget){
if (fidget.pinch.status == "end"){
switch(fidget.pinch.direction){
case "out": // Zoom in
var midpoint = this.calculateMidpoint(fidget.pinch.touches);
midpoint = this.map.toMap( new esri.geometry.Point(midpoint.x, midpoint.y) );
this.map.centerAndZoom(midpoint, this.map.getLevel() + 1);
fidget.pinch.direction = "unknown";
break;
case "in": // Zoom out
this.map.setLevel(this.map.getLevel() - 1);
fidget.pinch.direction = "unknown";
break;
case "unknown": break;
}
}
else if (fidget.pinch.status == "move" || fidget.pinch.status == "start"){
event.preventDefault();
}
};
MapPage.prototype.calculateMidpoint = function(touches){
var midx = 0;
var midy = 0;
if (touches.length > 1) {
midx = (touches[0].pageX + touches[1].pageX) / 2;
midy = (touches[0].pageY + touches[1].pageY) / 2;
midx -= $("#mapDiv").offset().left;
midy -= $("#mapDiv").offset().top;
}
return { x: midx, y: midy };
};
The 2 changes I made in the fidget plugin:1- Commented out first line of the fidgetStart function //event.preventDefault();2- Saved the start position of the two pinch "fingers":
function callPinchHandler() {
if (defaults.pinch) {
//if (defaults.zoomThis) {
//var zoomFactor = calculateDistance() / fidget.pinch.startDistance;
//console.log(fidget.pinch.distance + ' ' + calculateDistance());
//$this.css('webkitTransform', 'scale(' + zoomFactor + ')');
//}
if (fidget.pinch.status == "start"){
fidget.pinch.touches = event.touches; // [YB 2012/05/10 : Save the positions so we can calculate the midpoint later, for our map pinch zoom]
}
defaults.pinch.call($this, event, fidget);
}
}