+ // Calculate new center of the map - same point stays under the mouse.
+ // This means that the pixel distance between the old center and point
+ // must equal the pixel distance of the new center and that point.
+ var x = coordObj.clientX - gCanvas.offsetLeft;
+ var y = coordObj.clientY - gCanvas.offsetTop;
+ // Zoom factor after this action.
+ var newZoomFactor = Math.pow(2, gMaxZoom - gPos.z + (delta > 0 ? -1 : 1));
+ gPos.x -= (x - gCanvas.width / 2) * (newZoomFactor - gZoomFactor);
+ gPos.y -= (y - gCanvas.height / 2) * (newZoomFactor - gZoomFactor);
+ document.getElementById("debug").textContent = newZoomFactor + " - " + gZoomFactor;
+