From 2a597e8e279e3093412ee58ee820147fb7d054bc Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Tue, 27 Nov 2012 17:04:38 -0500 Subject: [PATCH] Fix way node dragging. Fixes #97 --- js/iD/Util.js | 6 ++++++ js/iD/graph/Graph.js | 8 ++++++++ js/iD/renderer/Map.js | 7 ++++--- js/iD/ui/Inspector.js | 3 +-- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/js/iD/Util.js b/js/iD/Util.js index 2aa1edfa1..52ba8898b 100644 --- a/js/iD/Util.js +++ b/js/iD/Util.js @@ -8,6 +8,12 @@ iD.Util.id = function(counter) { return counter[0] + (--iD.Util._counters[counter]); }; +iD.Util.trueObj = function(arr) { + var o = {}; + for (var i = 0, l = arr.length; i < l; i++) o[arr[i]] = true; + return o; +}; + iD.Util.friendlyName = function(entity) { // Generate a string such as 'river' or 'Fred's House' for an entity. if (!Object.keys(entity.tags).length) { return ''; } diff --git a/js/iD/graph/Graph.js b/js/iD/graph/Graph.js index 1fcb69245..96d28a8ed 100644 --- a/js/iD/graph/Graph.js +++ b/js/iD/graph/Graph.js @@ -31,6 +31,14 @@ iD.Graph.prototype = { return this.entities[id]; }, + parents: function(id) { + // This is slow and a bad hack. + return _.filter(this.entities, function(e) { + if (e.type !== 'way') return false; + return e.nodes.indexOf(id) !== -1; + }); + }, + merge: function(graph) { var entities = _.clone(this.entities); _.defaults(entities, graph.entities); diff --git a/js/iD/renderer/Map.js b/js/iD/renderer/Map.js index 5bc316ec2..ca02bf773 100644 --- a/js/iD/renderer/Map.js +++ b/js/iD/renderer/Map.js @@ -16,9 +16,12 @@ iD.Map = function(elem, connection) { .scale(projection.scale()) .scaleExtent([256, 134217728]) .on('zoom', zoomPan), + only, dragbehavior = d3.behavior.drag() .origin(function(entity) { var p = projection(ll2a(entity)); + only = iD.Util.trueObj([entity.id].concat( + _.pluck(history.graph().parents(entity.id), 'id'))); return { x: p[0], y: p[1] }; }) .on('dragstart', function() { @@ -27,8 +30,6 @@ iD.Map = function(elem, connection) { .on('drag', function(entity) { var to = projection.invert([d3.event.x, d3.event.y]); history.replace(iD.actions.move(entity, to)); - var only = {}; - only[entity.id] = true; redraw(only); }) .on('dragend', update), @@ -126,7 +127,7 @@ iD.Map = function(elem, connection) { if (!only) { all = graph.intersects(extent); } else { - for (var id in only) all.push(graph.entity(id)); + for (var id in only) all.push(graph.fetch(id)); } var filter = only ? diff --git a/js/iD/ui/Inspector.js b/js/iD/ui/Inspector.js index 9cbdf3d5f..47df3193f 100644 --- a/js/iD/ui/Inspector.js +++ b/js/iD/ui/Inspector.js @@ -26,7 +26,7 @@ iD.Inspector = function() { iD.format.GeoJSON.mapping(d), null, 2)); }); if (selection.datum().type === 'way') { - head.append('a') + selection.append('a') .attr('class', 'permalink') .attr('href', '#') .text('Reverse Direction') @@ -39,7 +39,6 @@ iD.Inspector = function() { } function inspector(selection) { - // http://jsfiddle.net/7WQjr/ selection.each(function(entity) { selection.html("").append('button') .text('x').attr({ title: 'close', 'class': 'close' })