First shot at implementing reversing way direction

This commit is contained in:
Tom MacWright
2012-11-27 11:47:43 -05:00
parent e6cbe55592
commit d8db151553
6 changed files with 42 additions and 16 deletions

View File

@@ -66,6 +66,15 @@ input[type=text]:focus {
button {
background:#3f5ca5;
border:0;
color:#fff;
font:normal 12px/18px 'Helvetica Neue', sans-serif;
margin:5px 5px 0 0;
cursor:pointer;
}
button:hover {
background:#000;
}
#bar button {

View File

@@ -9,20 +9,18 @@ iD.Util.id = function(counter) {
};
iD.Util.friendlyName = function(entity) {
// summary: Rough-and-ready function to return a human-friendly name
// for the object. Really just a placeholder for something better.
// returns: A string such as 'river' or 'Fred's House'.
// Generate a string such as 'river' or 'Fred's House' for an entity.
if (!Object.keys(entity.tags).length) { return ''; }
var mainkeys = ['highway','amenity','railway','waterway'];
var n = [];
var mainkeys = ['highway','amenity','railway','waterway'],
n = [];
if (entity.tags.name) n.push(entity.tags.name);
if (entity.tags.ref) n.push(entity.tags.ref);
if (!n.length) {
for (var k in entity.tags) {
if (mainkeys[k]) {
if (mainkeys.indexOf(k) !== -1) {
n.push(entity.tags[k]);
break;
}

View File

@@ -35,6 +35,15 @@ iD.actions.changeWayNodes = function(way, node) {
};
};
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/AddNodeToWayAction.as
iD.actions.changeWayDirection = function(way) {
return function(graph) {
return graph.replace(way.update({
nodes: way.nodes.slice()
}), 'changed way direction');
};
};
iD.actions.changeTags = function(node, tags) {
return function(graph) {
return graph.replace(node.update({

View File

@@ -96,7 +96,7 @@ var iD = function(container) {
.on('click', function(d) { return d[2](); });
container.append('div')
.attr('class', 'inspector-wrap');
.attr('class', 'inspector-wrap').style('display', 'none');
container.append('div')
.attr('id', 'about')

View File

@@ -372,16 +372,14 @@ iD.Map = function(elem, connection) {
redraw();
}
inspector.on('change', function(d, tags) {
inspector.on('changeTags', function(d, tags) {
map.perform(iD.actions.changeTags(d, tags));
});
inspector.on('remove', function(d) {
}).on('changeWayDirection', function(d, tags) {
map.perform(iD.actions.changeWayDirection(d));
}).on('remove', function(d) {
map.perform(iD.actions.remove(d));
hideInspector();
});
inspector.on('close', function(d) {
}).on('close', function(d) {
deselectClick();
hideInspector();
});

View File

@@ -1,5 +1,5 @@
iD.Inspector = function() {
var event = d3.dispatch('change', 'update', 'remove', 'close');
var event = d3.dispatch('changeTags', 'changeWayDirection', 'update', 'remove', 'close');
function inspector(selection) {
// http://jsfiddle.net/7WQjr/
@@ -44,6 +44,18 @@ iD.Inspector = function() {
iD.format.GeoJSON.mapping(entity), null, 2));
});
if (entity.type === 'way') {
head.append('a')
.attr('class', 'permalink')
.attr('href', '#')
.text('Reverse Direction')
.on('click', function() {
event.changeWayDirection(iD.Entity(entity, {
nodes: _.pluck(entity.nodes.slice().reverse(), 'id')
}));
});
}
var table = d3.select(this)
.append('table')
.attr('class', 'inspector');
@@ -98,7 +110,7 @@ iD.Inspector = function() {
.attr('class', 'save')
.text('Save')
.on('click', function() {
event.change(entity, newtags(table));
event.changeTags(entity, newtags(table));
});
d3.select(this)