Support removing nodes from ways

This commit is contained in:
Tom MacWright
2012-11-29 10:10:14 -05:00
parent f7fcf37197
commit abf2941425
3 changed files with 41 additions and 19 deletions

View File

@@ -27,6 +27,11 @@ rect.handle {
fill:#FFF694;
}
rect.handle.active {
stroke:red;
fill:#FFC5C5;
}
circle.teaser-point {
stroke-width: 2;
stroke:#1DCAFF;

View File

@@ -164,12 +164,12 @@ iD.Map = function(elem, connection) {
.data(waynodes, key);
handles.exit().remove();
handles.enter().append('rect')
.attr({ width: 4, height: 4, 'class': 'handle' })
.attr({ width: 6, height: 6, 'class': 'handle' })
.call(dragbehavior);
handles.attr('transform', function(entity) {
var p = projection(ll2a(entity));
return 'translate(' + [~~p[0], ~~p[1]] + ') translate(-2, -2) rotate(45, 2, 2)';
});
return 'translate(' + [~~p[0], ~~p[1]] + ') translate(-3, -3) rotate(45, 2, 2)';
}).classed('active', classActive);
}
function hideHandles() { hit_g.selectAll('rect.handle').remove(); }
@@ -377,13 +377,24 @@ iD.Map = function(elem, connection) {
redraw();
}
function removeEntity(entity) {
var parents = map.history.graph().parents(entity.id);
parents
.filter(function(d) { return d.type === 'way'; })
.forEach(function(parent) {
parent.nodes = _.without(parent.nodes, entity.id);
map.perform(iD.actions.removeWayNode(parent, entity));
});
map.perform(iD.actions.remove(entity));
}
inspector.on('changeTags', function(d, tags) {
var entity = map.history.graph().entity(d.id);
map.perform(iD.actions.changeTags(entity, tags));
}).on('changeWayDirection', function(d) {
map.perform(iD.actions.changeWayDirection(d));
}).on('remove', function(d) {
map.perform(iD.actions.remove(d));
removeEntity(d);
hideInspector();
}).on('close', function() {
deselectClick();

View File

@@ -9,7 +9,7 @@ iD.Inspector = function() {
.attr('class', 'permalink')
.attr('href', function(d) {
return 'http://www.openstreetmap.org/browse/' +
d.type + '/' + d.id.slice(1);
d.type + '/' + d.id.slice(1);
})
.text('View on OSM');
selection.append('a')
@@ -83,11 +83,13 @@ iD.Inspector = function() {
});
}
function clean(x) {
// Remove any blank key-values
function clean(x) {
for (var i in x) if (!i) delete x[i];
return x;
}
// Add a blank row for new tags
function pad(x) {
if (!x['']) x[''] = '';
return x;
@@ -100,6 +102,7 @@ iD.Inspector = function() {
return grabbed;
}
// fill values and add blank field if necessary
function update() {
draw(pad(grabtags()));
}
@@ -108,20 +111,23 @@ iD.Inspector = function() {
draw(data);
update();
selection.append('button')
.attr('class', 'save').text('Save')
.on('click', function() {
event.changeTags(entity, clean(grabtags()));
event.close(entity);
});
selection.append('div')
.attr('class', 'buttons').call(drawbuttons);
selection.append('button')
.attr('class', 'cancel').text('Cancel')
.on('click', function() { event.close(entity); });
selection.append('button')
.attr('class', 'delete').text('Delete')
.on('click', function() { event.remove(entity); });
function drawbuttons(selection) {
selection.append('button')
.attr('class', 'save').text('Save')
.on('click', function() {
event.changeTags(entity, clean(grabtags()));
event.close(entity);
});
selection.append('button')
.attr('class', 'cancel').text('Cancel')
.on('click', function() { event.close(entity); });
selection.append('button')
.attr('class', 'delete').text('Delete')
.on('click', function() { event.remove(entity); });
}
});
}