Add osmNode#isConnected

This is used to draw vertices
* where multiple parent ways meet
* where a single way self intersects (but not the closing node of a loop)

We were using Graph#isShared or osmNode#isIntersection, but this is slightly
different to handle self-intersecting ways.
This commit is contained in:
Bryan Housel
2017-01-23 23:44:04 -05:00
parent e4f11f137d
commit 8ecff8b8bc
3 changed files with 60 additions and 2 deletions
+22
View File
@@ -55,6 +55,28 @@ _.extend(osmNode.prototype, {
},
isConnected: function(resolver) {
return resolver.transient(this, 'isConnected', function() {
var parents = resolver.parentWays(this);
// vertex is connected to multiple parent ways
if (parents.length > 1) {
return true;
} else if (parents.length === 1) {
var way = parents[0],
nodes = way.nodes.slice();
if (way.isClosed()) { nodes.pop(); } // ignore connecting node if closed
// return true if vertex appears multiple times (way is self intersecting)
return nodes.indexOf(this.id) !== nodes.lastIndexOf(this.id);
}
return false;
});
},
isIntersection: function(resolver) {
return resolver.transient(this, 'isIntersection', function() {
return resolver.parentWays(this).filter(function(parent) {
+3 -2
View File
@@ -13,6 +13,7 @@ export function svgVertices(projection, context) {
var hover;
function siblingAndChildVertices(ids, graph, extent) {
var vertices = {};
@@ -78,7 +79,7 @@ export function svgVertices(projection, context) {
r = rads[i ? 3 : z];
// slightly increase the size of unconnected endpoints #3775
if (entity.isEndpoint(graph) && !graph.isShared(entity)) {
if (entity.isEndpoint(graph) && !entity.isConnected(graph)) {
r += 1.5;
}
@@ -166,7 +167,7 @@ export function svgVertices(projection, context) {
if (entity.id in selected ||
entity.hasInterestingTags() ||
entity.isEndpoint(graph) ||
entity.isIntersection(graph)) {
entity.isConnected(graph)) {
vertices.push(entity);
}
}
+35
View File
@@ -67,6 +67,41 @@ describe('iD.osmNode', function () {
});
});
describe('#isConnected', function () {
it('returns true for a node with more than one parent way', function () {
var node = iD.Node(),
w1 = iD.Way({nodes: [node.id]}),
w2 = iD.Way({nodes: [node.id]}),
graph = iD.Graph([node, w1, w2]);
expect(node.isConnected(graph)).to.equal(true);
});
it('returns false for a standalone node on a single parent way', function () {
var node = iD.Node(),
way = iD.Way({nodes: [node.id]}),
graph = iD.Graph([node, way]);
expect(node.isConnected(graph)).to.equal(false);
});
it('returns true for a self-intersecting node on a single parent way', function () {
var a = iD.Node({id: 'a'}),
b = iD.Node({id: 'b'}),
c = iD.Node({id: 'c'}),
w = iD.Way({nodes: ['a', 'b', 'c', 'b']}),
graph = iD.Graph([a, b, c, w]);
expect(b.isConnected(graph)).to.equal(true);
});
it('returns false for the connecting node of a closed way', function () {
var a = iD.Node({id: 'a'}),
b = iD.Node({id: 'b'}),
c = iD.Node({id: 'c'}),
w = iD.Way({nodes: ['a', 'b', 'c', 'a']}),
graph = iD.Graph([a, b, c, w]);
expect(a.isConnected(graph)).to.equal(false);
});
});
describe('#isIntersection', function () {
it('returns true for a node shared by more than one highway', function () {
var node = iD.Node(),