From 1641f38632685d9860dec48dfe8673c2ed11633a Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 9 May 2013 21:51:11 -0700 Subject: [PATCH] Use context.mouse() --- js/id/behavior/draw.js | 2 +- js/id/behavior/draw_way.js | 2 +- js/id/behavior/lasso.js | 4 ++-- js/id/id.js | 1 + js/id/modes/drag_node.js | 4 ++-- js/id/modes/move.js | 6 +----- js/id/modes/rotate_way.js | 6 +----- js/id/modes/select.js | 5 ++--- js/id/renderer/map.js | 4 ++-- js/id/svg/labels.js | 13 ++----------- 10 files changed, 15 insertions(+), 32 deletions(-) diff --git a/js/id/behavior/draw.js b/js/id/behavior/draw.js index e2553dc67..f6c6f183f 100644 --- a/js/id/behavior/draw.js +++ b/js/id/behavior/draw.js @@ -58,7 +58,7 @@ iD.behavior.Draw = function(context) { function click() { var d = datum(); if (d.type === 'way') { - var choice = iD.geo.chooseEdge(context.childNodes(d), d3.mouse(context.surface().node()), context.projection), + var choice = iD.geo.chooseEdge(context.childNodes(d), context.mouse(), context.projection), edge = [d.nodes[choice.index - 1], d.nodes[choice.index]]; event.clickWay(choice.loc, edge); diff --git a/js/id/behavior/draw_way.js b/js/id/behavior/draw_way.js index f47dced81..9d49c5115 100644 --- a/js/id/behavior/draw_way.js +++ b/js/id/behavior/draw_way.js @@ -37,7 +37,7 @@ iD.behavior.DrawWay = function(context, wayId, index, mode, baseGraph) { } else if (datum.type === 'node') { loc = datum.loc; } else if (datum.type === 'way') { - loc = iD.geo.chooseEdge(context.childNodes(datum), d3.mouse(context.surface().node()), context.projection).loc; + loc = iD.geo.chooseEdge(context.childNodes(datum), context.mouse(), context.projection).loc; } context.replace(iD.actions.MoveNode(end.id, loc)); diff --git a/js/id/behavior/lasso.js b/js/id/behavior/lasso.js index e334eba64..c82bdd8cb 100644 --- a/js/id/behavior/lasso.js +++ b/js/id/behavior/lasso.js @@ -8,7 +8,7 @@ iD.behavior.Lasso = function(context) { function mousedown() { if (d3.event.shiftKey === true) { - mouse = d3.mouse(context.surface().node()); + mouse = context.mouse(); lasso = null; selection @@ -27,7 +27,7 @@ iD.behavior.Lasso = function(context) { context.surface().call(lasso); } - lasso.b(d3.mouse(context.surface().node())); + lasso.b(context.mouse()); } function normalize(a, b) { diff --git a/js/id/id.js b/js/id/id.js index a45e49bf0..8db7d4d4a 100644 --- a/js/id/id.js +++ b/js/id/id.js @@ -138,6 +138,7 @@ window.iD = function () { context.layers = function() { return map.layers; }; context.background = function() { return map.layers[0]; }; context.surface = function() { return map.surface; }; + context.mouse = map.mouse; context.projection = map.projection; context.tail = map.tail; context.redraw = map.redraw; diff --git a/js/id/modes/drag_node.js b/js/id/modes/drag_node.js index 072313d8c..a4070e3fb 100644 --- a/js/id/modes/drag_node.js +++ b/js/id/modes/drag_node.js @@ -101,7 +101,7 @@ iD.modes.DragNode = function(context) { if (d.type === 'node' && d.id !== entity.id) { loc = d.loc; } else if (d.type === 'way') { - loc = iD.geo.chooseEdge(context.childNodes(d), d3.mouse(context.surface().node()), context.projection).loc; + loc = iD.geo.chooseEdge(context.childNodes(d), context.mouse(), context.projection).loc; } context.replace( @@ -115,7 +115,7 @@ iD.modes.DragNode = function(context) { var d = datum(); if (d.type === 'way') { - var choice = iD.geo.chooseEdge(context.childNodes(d), d3.mouse(context.surface().node()), context.projection); + var choice = iD.geo.chooseEdge(context.childNodes(d), context.mouse(), context.projection); context.replace( iD.actions.AddMidpoint({ loc: choice.loc, edge: [d.nodes[choice.index - 1], d.nodes[choice.index]] }, entity), connectAnnotation(d)); diff --git a/js/id/modes/move.js b/js/id/modes/move.js index b1fd7146f..06cb4f8ea 100644 --- a/js/id/modes/move.js +++ b/js/id/modes/move.js @@ -43,12 +43,8 @@ iD.modes.Move = function(context, entityIDs) { nudgeInterval = null; } - function point() { - return d3.mouse(context.map().surface.node()); - } - function move() { - var p = point(); + var p = context.mouse(); var delta = origin ? [p[0] - context.projection(origin)[0], diff --git a/js/id/modes/rotate_way.js b/js/id/modes/rotate_way.js index 8dfe93249..35d6a7432 100644 --- a/js/id/modes/rotate_way.js +++ b/js/id/modes/rotate_way.js @@ -19,13 +19,9 @@ iD.modes.RotateWay = function(context, wayId) { iD.actions.Noop(), annotation); - function point() { - return d3.mouse(context.map().surface.node()); - } - function rotate() { - var mousePoint = point(), + var mousePoint = context.mouse(), newAngle = Math.atan2(mousePoint[1] - pivot[1], mousePoint[0] - pivot[0]); if (typeof angle === 'undefined') angle = newAngle; diff --git a/js/id/modes/select.js b/js/id/modes/select.js index 610c5291b..450256b54 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(context.map().mousePosition()); + radialMenu.center(context.mouse()); } } @@ -131,8 +131,7 @@ iD.modes.Select = function(context, selection) { datum = target.datum(); if (datum instanceof iD.Way && !target.classed('fill')) { - var choice = iD.geo.chooseEdge(context.childNodes(datum), - d3.mouse(context.surface().node()), context.projection), + var choice = iD.geo.chooseEdge(context.childNodes(datum), context.mouse(), context.projection), node = iD.Node(); var prev = datum.nodes[choice.index - 1], diff --git a/js/id/renderer/map.js b/js/id/renderer/map.js index fa7804db5..5dc8fa9c2 100644 --- a/js/id/renderer/map.js +++ b/js/id/renderer/map.js @@ -246,14 +246,14 @@ iD.Map = function(context) { return [l[0] * scale + translate[0], l[1] * scale + translate[1]]; } - map.mousePosition = function() { + map.mouse = function() { var e = d3.event, s; while (s = e.sourceEvent) e = s; return mouse(e); }; map.mouseCoordinates = function() { - return projection.invert(map.mousePosition()); + return projection.invert(map.mouse()); }; map.dblclickEnable = function(_) { diff --git a/js/id/svg/labels.js b/js/id/svg/labels.js index f69784576..aa776982f 100644 --- a/js/id/svg/labels.js +++ b/js/id/svg/labels.js @@ -236,10 +236,7 @@ iD.svg.Labels = function(projection, context) { function hideOnMouseover() { - - if (!mousePosition) return; - - var mouse = mousePosition(d3.event), + var mouse = context.mouse(), pad = 50, rect = new RTree.Rectangle(mouse[0] - pad, mouse[1] - pad, 2*pad, 2*pad), labels = _.pluck(rtree.search(rect, this), 'leaf'), @@ -273,16 +270,10 @@ iD.svg.Labels = function(projection, context) { var rtree = new RTree(), rectangles = {}, - lang = 'name:' + iD.detect().locale.toLowerCase().split('-')[0], - mousePosition, cacheDimensions; + lang = 'name:' + iD.detect().locale.toLowerCase().split('-')[0]; function labels(surface, graph, entities, filter, dimensions, fullRedraw) { - if (!mousePosition || dimensions.join(',') !== cacheDimensions) { - mousePosition = iD.util.fastMouse(surface.node().parentNode); - cacheDimensions = dimensions.join(','); - } - var hidePoints = !surface.select('.node.point').node(); var labelable = [], i, k, entity;