Remove operation, hooked into inspector

This commit is contained in:
Tom MacWright
2012-11-06 17:35:56 -05:00
parent f00ad5b169
commit 08ed9c5af2
3 changed files with 47 additions and 27 deletions

View File

@@ -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 = {};

View File

@@ -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)

View File

@@ -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');
};