From dc37eb99b4c9188f2cf79d330d25346bee280bb2 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Thu, 6 Dec 2012 15:51:48 -0500 Subject: [PATCH] Fix dragging while drawing, fix delete binding. Fixes #184 --- js/id/modes/draw_area.js | 2 +- js/id/modes/draw_road.js | 14 ++++++++------ js/id/renderer/map.js | 14 ++++++++++++-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/js/id/modes/draw_area.js b/js/id/modes/draw_area.js index 9fbd03b14..70ef0aaee 100644 --- a/js/id/modes/draw_area.js +++ b/js/id/modes/draw_area.js @@ -57,7 +57,7 @@ iD.modes.DrawArea = function(way_id) { mode.map.keybinding().on('⌫.drawarea', function() { d3.event.preventDefault(); var lastNode = _.last(way.nodes); - mode.history.replace(iD.actions.removeWayNode(way, + mode.history.replace(iD.actions.RemoveWayNode(way, mode.history.graph().entity(lastNode))); mode.history.replace(iD.actions.DeleteNode( mode.history.graph().entity(lastNode))); diff --git a/js/id/modes/draw_road.js b/js/id/modes/draw_road.js index 2a437e884..4ea9a55b4 100644 --- a/js/id/modes/draw_road.js +++ b/js/id/modes/draw_road.js @@ -9,9 +9,10 @@ iD.modes.DrawRoad = function(way_id, direction) { 'Click on other roads to connect to them, and double-click to ' + 'end the road.'); mode.map.dragEnable(false); + mode.map.fastEnable(false); var index = (direction === 'forward') ? undefined : -1, - node = iD.Node({loc: mode.map.mouseCoordinates()}), + node = iD.Node({loc: mode.map.mouseCoordinates(), tags: { elastic: true } }), way = mode.history.graph().entity(way_id), firstNode = way.nodes[0], lastNode = _.last(way.nodes); @@ -26,11 +27,11 @@ iD.modes.DrawRoad = function(way_id, direction) { mode.map.surface.on('mousemove.drawroad', function() { mode.history.replace(iD.actions.AddWayNode(way, - node.update({loc: mode.map.mouseCoordinates()}), index)); + node.update({ loc: mode.map.mouseCoordinates() }), index)); }); mode.map.surface.on('click.drawroad', function() { - d3.event.stopPropagation(); + // d3.event.stopPropagation(); var datum = d3.select(d3.event.target).datum() || {}; @@ -52,7 +53,7 @@ iD.modes.DrawRoad = function(way_id, direction) { mode.history.replace(iD.actions.AddWayNode(way, datum, index)); } } else if (datum.type === 'way') { - node = node.update({loc: mode.map.mouseCoordinates()}); + node = node.update({loc: mode.map.mouseCoordinates(), tags: {} }); mode.history.replace(iD.actions.AddWayNode(way, node, index)); var connectedWay = mode.history.graph().entity(datum.id); @@ -63,7 +64,7 @@ iD.modes.DrawRoad = function(way_id, direction) { node, connectedIndex)); } else { - node = node.update({loc: mode.map.mouseCoordinates()}); + node = node.update({loc: mode.map.mouseCoordinates(), tags: {} }); mode.history.replace(iD.actions.AddWayNode(way, node, index)); } @@ -76,7 +77,7 @@ iD.modes.DrawRoad = function(way_id, direction) { mode.map.keybinding().on('⌫.drawroad', function() { d3.event.preventDefault(); - mode.history.replace(iD.actions.removeWayNode(way, + mode.history.replace(iD.actions.RemoveWayNode(way, mode.history.graph().entity(lastNode))); mode.history.replace(iD.actions.DeleteNode( mode.history.graph().entity(lastNode))); @@ -87,6 +88,7 @@ iD.modes.DrawRoad = function(way_id, direction) { mode.exit = function() { mode.map.hint(false); + mode.map.fastEnable(true); mode.map.surface .on('mousemove.drawroad', null) .on('click.drawroad', null); diff --git a/js/id/renderer/map.js b/js/id/renderer/map.js index fd32156e5..9f5e4e6c8 100644 --- a/js/id/renderer/map.js +++ b/js/id/renderer/map.js @@ -13,6 +13,7 @@ iD.Map = function() { .on('zoom', zoomPan), dblclickEnabled = true, dragEnabled = true, + fastEnabled = true, dragging, dragbehavior = d3.behavior.drag() .origin(function(entity) { @@ -176,7 +177,10 @@ iD.Map = function() { handles.exit().remove(); handles.enter().append('image') .attr({ width: 6, height: 6, 'class': 'handle', 'xlink:href': 'css/handle.png' }) - .call(dragbehavior); + .each(function(d) { + if (d.tags && d.tags.elastic) return; + d3.select(this).call(dragbehavior); + }); handles.attr('transform', function(entity) { var p = projection(entity.loc); return 'translate(' + [~~p[0], ~~p[1]] + ') translate(-3, -3) rotate(45, 3, 3)'; @@ -304,7 +308,7 @@ iD.Map = function() { if (d3.event && d3.event.sourceEvent.type === 'dblclick') { if (!dblclickEnabled) return; } - var fast = (d3.event.scale === projection.scale()); + var fast = (d3.event.scale === projection.scale() && fastEnabled); projection .translate(d3.event.translate) .scale(d3.event.scale); @@ -379,6 +383,12 @@ iD.Map = function() { return map; }; + map.fastEnable = function(_) { + if (!arguments.length) return fastEnabled; + fastEnabled = _; + return map; + }; + map.zoom = function(z) { if (!arguments.length) { return Math.max(Math.log(projection.scale()) / Math.LN2 - 8, 0);