From bb487ba0eec5d749dfd8dd94ba85e9af70df5fe2 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Sat, 4 May 2013 11:31:46 -0700 Subject: [PATCH] Use fastMouse --- js/id/modes/select.js | 2 +- js/id/renderer/map.js | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/js/id/modes/select.js b/js/id/modes/select.js index 6c8736032..610c5291b 100644 --- a/js/id/modes/select.js +++ b/js/id/modes/select.js @@ -31,7 +31,7 @@ iD.modes.Select = function(context, selection) { if (entity && entity.type === 'node') { radialMenu.center(context.projection(entity.loc)); } else { - radialMenu.center(d3.mouse(context.surface().node())); + radialMenu.center(context.map().mousePosition()); } } diff --git a/js/id/renderer/map.js b/js/id/renderer/map.js index df269dbb9..fa7804db5 100644 --- a/js/id/renderer/map.js +++ b/js/id/renderer/map.js @@ -25,7 +25,8 @@ iD.Map = function(context) { midpoints = iD.svg.Midpoints(roundedProjection, context), labels = iD.svg.Labels(roundedProjection, context), tail = iD.ui.Tail(), - supersurface, surface; + supersurface, surface, + mouse; function map(selection) { context.history() @@ -79,6 +80,7 @@ iD.Map = function(context) { map.surface = surface; labels.supersurface(supersurface); + mouse = iD.util.fastMouse(supersurface.node()); supersurface .call(tail); @@ -244,13 +246,14 @@ iD.Map = function(context) { return [l[0] * scale + translate[0], l[1] * scale + translate[1]]; } + map.mousePosition = function() { + var e = d3.event, s; + while (s = e.sourceEvent) e = s; + return mouse(e); + }; + map.mouseCoordinates = function() { - try { - return projection.invert(d3.mouse(surface.node())); - } catch(e) { - // when called with hidden elements, d3.mouse() will throw - return [NaN, NaN]; - } + return projection.invert(map.mousePosition()); }; map.dblclickEnable = function(_) {