diff --git a/js/id/actions/delete_way.js b/js/id/actions/delete_way.js index 224537c81..1c6b6ff5f 100644 --- a/js/id/actions/delete_way.js +++ b/js/id/actions/delete_way.js @@ -22,7 +22,6 @@ iD.actions.DeleteWay = function(wayId) { if (!node.hasInterestingTags()) { graph = graph.remove(node); } else { - graph = graph.replace(node.update({_poi: true})); } } }); @@ -32,7 +31,7 @@ iD.actions.DeleteWay = function(wayId) { action.enabled = function(graph) { return true; - } + }; return action; }; diff --git a/js/id/connection.js b/js/id/connection.js index c276123de..80ed49c26 100644 --- a/js/id/connection.js +++ b/js/id/connection.js @@ -154,11 +154,19 @@ iD.Connection = function() { } var g = iD.Graph(entities); + var i; - for (var i in wparentsOf) { - if (entities[i]) g.transient(entities[i], - 'parentWays', d3.functor(wparentsOf[i])); - if (entities[i]) entities[i].update({ _poi: true }); + for (i in wparentsOf) { + if (entities[i]) { + g.transient(entities[i], 'parentWays', d3.functor(wparentsOf[i])); + g.transient(entities[i], 'poi', d3.functor(true)); + } + } + + for (i in g.entities) { + if (entities[i].type === 'node') { + g.transient(entities[i], 'poi', d3.functor(false)); + } } for (i in rparentsOf) { diff --git a/js/id/graph/graph.js b/js/id/graph/graph.js index 0d533d461..f44245385 100644 --- a/js/id/graph/graph.js +++ b/js/id/graph/graph.js @@ -31,7 +31,7 @@ iD.Graph.prototype = { transients = this.transients[id] || (this.transients[id] = {}); - if (transients[key]) { + if (transients[key] !== undefined) { return transients[key]; } @@ -60,6 +60,10 @@ iD.Graph.prototype = { return this._parentWays[entity.id] || []; }, + isPoi: function(entity) { + return this.parentWays(entity).length === 0; + }, + parentRelations: function(entity) { var ent, id, parents; @@ -141,7 +145,7 @@ iD.Graph.prototype = { oldentity && oldentity.type === 'way') { result = result .concat(_.difference(entity.nodes, oldentity.nodes)) - .concat(_.difference(oldentity.nodes, entity.nodes)) + .concat(_.difference(oldentity.nodes, entity.nodes)); } else if (entity && entity.type === 'way') { result = result.concat(entity.nodes); diff --git a/js/id/graph/node.js b/js/id/graph/node.js index df9c253a4..d9069d6fb 100644 --- a/js/id/graph/node.js +++ b/js/id/graph/node.js @@ -15,8 +15,8 @@ _.extend(iD.Node.prototype, { return iD.geo.Extent(this.loc); }, - geometry: function() { - return this._poi ? 'point' : 'vertex'; + geometry: function(graph) { + return graph.isPoi(this) ? 'point' : 'vertex'; }, move: function(loc) { diff --git a/js/id/graph/validate.js b/js/id/graph/validate.js index addb774ca..805b775c3 100644 --- a/js/id/graph/validate.js +++ b/js/id/graph/validate.js @@ -1,4 +1,4 @@ -iD.validate = function(changes) { +iD.validate = function(changes, graph) { var warnings = [], change; // https://github.com/openstreetmap/josm/blob/mirror/src/org/ @@ -19,22 +19,22 @@ iD.validate = function(changes) { for (var i = 0; i < changes.created.length; i++) { change = changes.created[i]; - if (change.geometry() === 'point' && _.isEmpty(change.tags)) { + if (change.geometry(graph) === 'point' && _.isEmpty(change.tags)) { warnings.push({ message: 'Untagged point which is not part of a line or area', entity: change }); } - if (change.geometry() === 'line' && _.isEmpty(change.tags)) { + if (change.geometry(graph) === 'line' && _.isEmpty(change.tags)) { warnings.push({ message: 'Untagged line', entity: change }); } - if (change.geometry() === 'area' && _.isEmpty(change.tags)) { + if (change.geometry(graph) === 'area' && _.isEmpty(change.tags)) { warnings.push({ message: 'Untagged area', entity: change }); } - if (change.geometry() === 'line' && tagSuggestsArea(change)) { + if (change.geometry(graph) === 'line' && tagSuggestsArea(change)) { warnings.push({ message: 'The tag ' + tagSuggestsArea(change) + ' suggests line should be area, but it is not and area', entity: change diff --git a/js/id/modes/add_line.js b/js/id/modes/add_line.js index 8baa8e30e..190bf7e16 100644 --- a/js/id/modes/add_line.js +++ b/js/id/modes/add_line.js @@ -10,6 +10,7 @@ iD.modes.AddLine = function() { mode.enter = function() { var map = mode.map, + graph = map.history().graph(), node, history = mode.history, controller = mode.controller; @@ -25,8 +26,8 @@ iD.modes.AddLine = function() { if (datum.type === 'node') { // continue an existing way var id = datum.id; - var parents = history.graph().parentWays(datum); - var isLine = parents.length && parents[0].geometry() === 'line'; + var parents = history.graph(graph).parentWays(datum); + var isLine = parents.length && parents[0].geometry(graph) === 'line'; if (isLine && parents[0].nodes[0] === id ) { way = parents[0]; direction = 'backward'; diff --git a/js/id/modes/add_point.js b/js/id/modes/add_point.js index 70275d050..bacdc1541 100644 --- a/js/id/modes/add_point.js +++ b/js/id/modes/add_point.js @@ -15,7 +15,7 @@ iD.modes.AddPoint = function() { map.tail('Click on the map to add a point.'); map.surface.on('click.addpoint', function() { - var node = iD.Node({loc: map.mouseCoordinates(), _poi: true}); + var node = iD.Node({loc: map.mouseCoordinates()}); history.perform( iD.actions.AddNode(node), diff --git a/js/id/modes/select.js b/js/id/modes/select.js index dc298e36a..8d892724d 100644 --- a/js/id/modes/select.js +++ b/js/id/modes/select.js @@ -32,7 +32,11 @@ iD.modes.Select = function(entity, initial) { } mode.enter = function() { - var surface = mode.map.surface; + var map = mode.map, + graph = map.history().graph(), + surface = mode.map.surface; + + inspector.graph(graph); behaviors = [ iD.behavior.Hover(), @@ -116,7 +120,7 @@ iD.modes.Select = function(entity, initial) { function dblclick() { var datum = d3.select(d3.event.target).datum(); if (datum instanceof iD.Entity && - (datum.geometry() === 'area' || datum.geometry() === 'line')) { + (datum.geometry(graph) === 'area' || datum.geometry(graph) === 'line')) { var choice = iD.geo.chooseIndex(datum, d3.mouse(mode.map.surface.node()), mode.map), node = iD.Node({ loc: choice.loc }); diff --git a/js/id/svg/areas.js b/js/id/svg/areas.js index 5a3c31288..0bc8049e9 100644 --- a/js/id/svg/areas.js +++ b/js/id/svg/areas.js @@ -31,7 +31,7 @@ iD.svg.Areas = function(projection) { for (var i = 0; i < entities.length; i++) { var entity = entities[i]; - if (entity.geometry() === 'area') { + if (entity.geometry(graph) === 'area') { areas.push(entity); } } diff --git a/js/id/svg/lines.js b/js/id/svg/lines.js index e3563bae9..21382aefd 100644 --- a/js/id/svg/lines.js +++ b/js/id/svg/lines.js @@ -66,7 +66,7 @@ iD.svg.Lines = function(projection) { for (var i = 0; i < entities.length; i++) { var entity = entities[i]; - if (entity.geometry() === 'line') { + if (entity.geometry(graph) === 'line') { lines.push(entity); } } diff --git a/js/id/svg/multipolygons.js b/js/id/svg/multipolygons.js index 6330cf685..b4f050ad5 100644 --- a/js/id/svg/multipolygons.js +++ b/js/id/svg/multipolygons.js @@ -4,7 +4,7 @@ iD.svg.Multipolygons = function(projection) { for (var i = 0; i < entities.length; i++) { var entity = entities[i]; - if (entity.geometry() === 'relation' && entity.tags.type === 'multipolygon') { + if (entity.geometry(graph) === 'relation' && entity.tags.type === 'multipolygon') { multipolygons.push(entity); } } @@ -17,7 +17,7 @@ iD.svg.Multipolygons = function(projection) { } var multipolygon = entity.multipolygon(graph); - if (entity.members.length == 0 || !multipolygon) { + if (entity.members.length === 0 || !multipolygon) { return (lineStrings[entity.id] = null); } diff --git a/js/id/svg/points.js b/js/id/svg/points.js index 5862a5cb9..3af99e0da 100644 --- a/js/id/svg/points.js +++ b/js/id/svg/points.js @@ -15,7 +15,7 @@ iD.svg.Points = function(projection) { for (var i = 0; i < entities.length; i++) { var entity = entities[i]; - if (entity.geometry() === 'point') { + if (entity.geometry(graph) === 'point') { points.push(entity); } } diff --git a/js/id/svg/vertices.js b/js/id/svg/vertices.js index 4a975d38b..06be536ec 100644 --- a/js/id/svg/vertices.js +++ b/js/id/svg/vertices.js @@ -4,7 +4,7 @@ iD.svg.Vertices = function(projection) { for (var i = 0; i < entities.length; i++) { var entity = entities[i]; - if (entity.geometry() === 'vertex') { + if (entity.geometry(graph) === 'vertex') { vertices.push(entity); } } diff --git a/js/id/ui/commit.js b/js/id/ui/commit.js index b63150ba3..b1977e756 100644 --- a/js/id/ui/commit.js +++ b/js/id/ui/commit.js @@ -1,4 +1,4 @@ -iD.ui.commit = function() { +iD.ui.commit = function(map) { var event = d3.dispatch('cancel', 'save', 'fix'); function zipSame(d) { @@ -89,7 +89,7 @@ iD.ui.commit = function() { cancelbutton.append('span').attr('class','label').text('Cancel'); var warnings = body.selectAll('div.warning-section') - .data(iD.validate(changes)) + .data(iD.validate(changes, map.history().graph())) .enter() .append('div').attr('class', 'modal-section warning-section fillL'); diff --git a/js/id/ui/inspector.js b/js/id/ui/inspector.js index 22fac522d..47d77e735 100644 --- a/js/id/ui/inspector.js +++ b/js/id/ui/inspector.js @@ -3,6 +3,7 @@ iD.ui.inspector = function() { 'update', 'remove', 'close', 'splitWay', 'unjoin'), taginfo = iD.taginfo(), initial = false, + graph, tagList; function inspector(selection) { @@ -50,7 +51,7 @@ iD.ui.inspector = function() { var h2 = selection.append('h2'); h2.append('span') - .attr('class', 'icon big icon-pre-text big-' + entity.geometry()); + .attr('class', 'icon big icon-pre-text big-' + entity.geometry(graph)); h2.append('span') .text(entity.friendlyName()); @@ -90,7 +91,7 @@ iD.ui.inspector = function() { .on('click', function() { event.reverseWay(entity); }); } - if (entity.geometry() === 'vertex') { + if (entity.geometry(graph) === 'vertex') { minorButtons.append('a') .attr('href', '#') .text('Split Way') @@ -155,7 +156,7 @@ iD.ui.inspector = function() { .attr('class', 'tag-help minor') .on('click', function(d) { var params = _.extend({}, d, { - geometry: entity.geometry() + geometry: entity.geometry(graph) }); if (d.key && d.value) { taginfo.docs(params, function(err, docs) { @@ -223,7 +224,7 @@ iD.ui.inspector = function() { function bindTypeahead() { var entity = tagList.datum(), - geometry = entity.geometry(), + geometry = entity.geometry(graph), row = d3.select(this), key = row.selectAll('.key'), value = row.selectAll('.value'); @@ -304,5 +305,10 @@ iD.ui.inspector = function() { return inspector; }; + inspector.graph = function(_) { + graph = _; + return inspector; + }; + return d3.rebind(inspector, event, 'on'); }; diff --git a/js/id/ui/save.js b/js/id/ui/save.js index c0036d334..af65b075a 100644 --- a/js/id/ui/save.js +++ b/js/id/ui/save.js @@ -51,7 +51,7 @@ iD.ui.save = function() { modal.select('.content') .classed('commit-modal', true) .datum(changes) - .call(iD.ui.commit() + .call(iD.ui.commit(map) .on('cancel', function() { modal.remove(); })