Browse files

Fixed mouse position

  • Loading branch information...
1 parent 80561a6 commit 65a48cf2e9f946951b6eb7aba85c6ebd5c63debc @migurski committed Aug 3, 2012
Showing with 9 additions and 3 deletions.
  1. +9 −3 index.html
View
12 index.html
@@ -653,9 +653,15 @@
return true;
}
+ function mousePosition()
+ {
+ var div = map.node();
+ return {x: d3.mouse(div)[0], y: d3.mouse(div)[1]}
+ }
+
function onMouseDown()
{
- var prevMouse = {x: d3.event.pageX, y: d3.event.pageY};
+ var prevMouse = mousePosition();
d3.select(window)
.on('mousemove.map', onMouseMove)
@@ -666,7 +672,7 @@
function onMouseMove()
{
var mouse = prevMouse;
- prevMouse = {x: d3.event.pageX, y: d3.event.pageY};
+ prevMouse = mousePosition();
coord = Coordinates.offsetBy(coord, {
c: -((prevMouse.x - mouse.x) / tileSize.w),
r: -((prevMouse.y - mouse.y) / tileSize.h),
@@ -690,7 +696,7 @@
// 18 = max zoom, 0 = min zoom
var delta = Math.min(18-coord.z,Math.max(0-coord.z,d3_behavior_zoomDelta()));
if (delta != 0) {
- var mouse = {x: d3.event.pageX, y: d3.event.pageY};
+ var mouse = mousePosition();
coord = Coordinates.offsetBy(coord, {
c: ((mouse.x-center.x) / tileSize.w),
r: ((mouse.y-center.y) / tileSize.h),

0 comments on commit 65a48cf

Please sign in to comment.