From d8db1515538549a8bc0c12bc10e95f43596d7d3b Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Tue, 27 Nov 2012 11:47:43 -0500 Subject: [PATCH] First shot at implementing reversing way direction --- css/app.css | 9 +++++++++ js/iD/Util.js | 10 ++++------ js/iD/actions/actions.js | 9 +++++++++ js/iD/id.js | 2 +- js/iD/renderer/Map.js | 12 +++++------- js/iD/ui/Inspector.js | 16 ++++++++++++++-- 6 files changed, 42 insertions(+), 16 deletions(-) diff --git a/css/app.css b/css/app.css index 656ae52d9..a70dfd136 100644 --- a/css/app.css +++ b/css/app.css @@ -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 { diff --git a/js/iD/Util.js b/js/iD/Util.js index 924e478a3..2aa1edfa1 100644 --- a/js/iD/Util.js +++ b/js/iD/Util.js @@ -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; } diff --git a/js/iD/actions/actions.js b/js/iD/actions/actions.js index 1d7b21e92..bf4cecaf3 100644 --- a/js/iD/actions/actions.js +++ b/js/iD/actions/actions.js @@ -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({ diff --git a/js/iD/id.js b/js/iD/id.js index 8ba4383b1..7ea88839a 100644 --- a/js/iD/id.js +++ b/js/iD/id.js @@ -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') diff --git a/js/iD/renderer/Map.js b/js/iD/renderer/Map.js index e9ce0ba37..3008d7844 100644 --- a/js/iD/renderer/Map.js +++ b/js/iD/renderer/Map.js @@ -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(); }); diff --git a/js/iD/ui/Inspector.js b/js/iD/ui/Inspector.js index e0ff790b1..4ea5f0a4c 100644 --- a/js/iD/ui/Inspector.js +++ b/js/iD/ui/Inspector.js @@ -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)