mirror of
https://github.com/FoggedLens/iD.git
synced 2026-03-03 18:03:38 +00:00
Remove operation, hooked into inspector
This commit is contained in:
@@ -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 = {};
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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');
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user