From 08ed9c5af2c0d61689eae54f100ad884d697d30b Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Tue, 6 Nov 2012 17:35:56 -0500 Subject: [PATCH] Remove operation, hooked into inspector --- js/iD/actions/operations.js | 8 +++++ js/iD/renderer/Map.js | 4 +++ js/iD/ui/Inspector.js | 62 +++++++++++++++++++++---------------- 3 files changed, 47 insertions(+), 27 deletions(-) diff --git a/js/iD/actions/operations.js b/js/iD/actions/operations.js index 76b9af4cd..4653db994 100644 --- a/js/iD/actions/operations.js +++ b/js/iD/actions/operations.js @@ -18,6 +18,14 @@ iD.operations.startWay = function(map, way) { map.update(); }; +iD.operations.remove = function(map, node) { + map.graph.modify(function(graph) { + console.log(node.id); + return graph.remove(node.id); + }, 'removed a feature'); + map.update(); +}; + iD.operations.changeWayNodes = function(map, way, node) { map.graph.modify(function(graph) { var o = {}; diff --git a/js/iD/renderer/Map.js b/js/iD/renderer/Map.js index d741a40d8..500c70583 100755 --- a/js/iD/renderer/Map.js +++ b/js/iD/renderer/Map.js @@ -228,6 +228,10 @@ iD.Map = function(elem) { iD.operations.changeTags(map, d, tags); }); + inspector.on('remove', function(d) { + iD.operations.remove(map, d); + }); + function zoomPan() { projection .translate(d3.event.translate) diff --git a/js/iD/ui/Inspector.js b/js/iD/ui/Inspector.js index 43d45e69e..dec278d12 100644 --- a/js/iD/ui/Inspector.js +++ b/js/iD/ui/Inspector.js @@ -1,5 +1,5 @@ iD.Inspector = function(graph) { - var event = d3.dispatch('change', 'update'); + var event = d3.dispatch('change', 'update', 'remove'); function inspector(selection) { // http://jsfiddle.net/7WQjr/ @@ -64,8 +64,8 @@ iD.Inspector = function(graph) { .property('value', function(d) { return d.key; }) .on('change', function(row) { row.key = this.value; - event.update(d, newtags()); - draw(formtags()); + event.update(d, newtags(table)); + draw(formtags(table)); }); row.append('td').append('input') @@ -73,43 +73,51 @@ iD.Inspector = function(graph) { .property('value', function(d) { return d.value; }) .on('change', function(row) { row.value = this.value; - event.update(d, newtags()); - draw(formtags()); + event.update(d, newtags(table)); + draw(formtags(table)); }); } var data = d3.entries(d.tags).concat([{ key: '', value: ''}]); draw(data); - // TODO: there must be a function for this - function unentries(x) { - var obj = {}; - for (var i = 0; i < x.length; i++) { - obj[x[i].key] = x[i].value; - } - return obj; - } - function formtags() { - var t = newtags(); - if (Object.keys(t).indexOf('') === -1) t[''] = ''; - return d3.entries(t); - } - - function newtags() { - var inputs = table.selectAll('input.tag-value') - .data(); - return unentries(inputs); - } - - var save = d3.select(this) + save = d3.select(this) .append('button') .text('Save') .on('click', function(d, i) { - event.change(d, newtags()); + event.change(d, newtags(table)); + }); + + d3.select(this) + .append('button') + .text('Delete') + .on('click', function(d, i) { + event.remove(d); }); }); } + // TODO: there must be a function for this + function unentries(x) { + var obj = {}; + for (var i = 0; i < x.length; i++) { + obj[x[i].key] = x[i].value; + } + return obj; + } + + function formtags(table) { + var t = newtags(table); + if (Object.keys(t).indexOf('') === -1) t[''] = ''; + return d3.entries(t); + } + + function newtags(table) { + var inputs = table.selectAll('input.tag-value') + .data(); + return unentries(inputs); + } + return d3.rebind(inspector, event, 'on'); };