mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-18 22:48:10 +02:00
expose relation.joinMemberWays
This commit is contained in:
@@ -26,15 +26,7 @@ iD.actions.MergePolygon = function(ids, newRelationId) {
|
||||
// ids - an array of ids of entities that are part of that polygon
|
||||
// locs - an array of the locations forming the polygon
|
||||
var polygons = entities.multipolygon.reduce(function(polygons, m) {
|
||||
m.multipolygon(graph).forEach(function(group) {
|
||||
group.forEach(function(ring) {
|
||||
polygons.push({
|
||||
ids: ring.ids,
|
||||
locs: ring
|
||||
});
|
||||
});
|
||||
});
|
||||
return polygons;
|
||||
return polygons.concat(m.joinMemberWays(null, graph));
|
||||
}, []).concat(entities.closedWay.map(function(d) {
|
||||
return {
|
||||
ids: [d.id],
|
||||
|
||||
+65
-55
@@ -168,59 +168,6 @@ _.extend(iD.Relation.prototype, {
|
||||
.filter(function(m) { return m.type === 'way' && resolver.entity(m.id); })
|
||||
.map(function(m) { return { role: m.role || 'outer', id: m.id, nodes: resolver.childNodes(resolver.entity(m.id)) }; });
|
||||
|
||||
function join(ways) {
|
||||
var joined = [], way, current, first, last, i, how, what;
|
||||
|
||||
while (ways.length) {
|
||||
way = ways.pop();
|
||||
current = way.nodes.slice();
|
||||
current.ids = [way.id];
|
||||
joined.push(current);
|
||||
|
||||
while (ways.length && _.first(current) !== _.last(current)) {
|
||||
first = _.first(current);
|
||||
last = _.last(current);
|
||||
|
||||
for (i = 0; i < ways.length; i++) {
|
||||
what = ways[i].nodes;
|
||||
|
||||
if (last === _.first(what)) {
|
||||
how = current.push;
|
||||
what = what.slice(1);
|
||||
break;
|
||||
} else if (last === _.last(what)) {
|
||||
how = current.push;
|
||||
what = what.slice(0, -1).reverse();
|
||||
break;
|
||||
} else if (first == _.last(what)) {
|
||||
how = current.unshift;
|
||||
what = what.slice(0, -1);
|
||||
break;
|
||||
} else if (first == _.first(what)) {
|
||||
how = current.unshift;
|
||||
what = what.slice(1).reverse();
|
||||
break;
|
||||
} else {
|
||||
what = how = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (!what)
|
||||
break; // Invalid geometry (unclosed ring)
|
||||
|
||||
current.ids.push(ways[i].id);
|
||||
ways.splice(i, 1);
|
||||
how.apply(current, what);
|
||||
}
|
||||
}
|
||||
|
||||
return joined.map(function(nodes) {
|
||||
var locs = _.pluck(nodes, 'loc');
|
||||
locs.ids = nodes.ids;
|
||||
return locs;
|
||||
});
|
||||
}
|
||||
|
||||
function findOuter(inner) {
|
||||
var o, outer;
|
||||
|
||||
@@ -237,8 +184,8 @@ _.extend(iD.Relation.prototype, {
|
||||
}
|
||||
}
|
||||
|
||||
var outers = join(members.filter(function(m) { return m.role === 'outer'; })),
|
||||
inners = join(members.filter(function(m) { return m.role === 'inner'; })),
|
||||
var outers = _.pluck(this.joinMemberWays(members.filter(function(m) { return m.role === 'outer'; })), 'locs'),
|
||||
inners = _.pluck(this.joinMemberWays(members.filter(function(m) { return m.role === 'inner'; })), 'locs'),
|
||||
result = outers.map(function(o) { return [o]; });
|
||||
|
||||
for (var i = 0; i < inners.length; i++) {
|
||||
@@ -250,5 +197,68 @@ _.extend(iD.Relation.prototype, {
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
joinMemberWays: function(ways, resolver) {
|
||||
var joined = [], way, current, first, last, i, how, what;
|
||||
|
||||
ways = ways || this.members.filter(function(m) {
|
||||
return m.type === 'way';
|
||||
}).map(function(m) {
|
||||
return {
|
||||
id: m.id,
|
||||
nodes: resolver.childNodes(resolver.entity(m.id))
|
||||
};
|
||||
});
|
||||
|
||||
while (ways.length) {
|
||||
way = ways.pop();
|
||||
current = way.nodes.slice();
|
||||
current.ids = [way.id];
|
||||
joined.push(current);
|
||||
|
||||
while (ways.length && _.first(current) !== _.last(current)) {
|
||||
first = _.first(current);
|
||||
last = _.last(current);
|
||||
|
||||
for (i = 0; i < ways.length; i++) {
|
||||
what = ways[i].nodes;
|
||||
|
||||
if (last === _.first(what)) {
|
||||
how = current.push;
|
||||
what = what.slice(1);
|
||||
break;
|
||||
} else if (last === _.last(what)) {
|
||||
how = current.push;
|
||||
what = what.slice(0, -1).reverse();
|
||||
break;
|
||||
} else if (first == _.last(what)) {
|
||||
how = current.unshift;
|
||||
what = what.slice(0, -1);
|
||||
break;
|
||||
} else if (first == _.first(what)) {
|
||||
how = current.unshift;
|
||||
what = what.slice(1).reverse();
|
||||
break;
|
||||
} else {
|
||||
what = how = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (!what)
|
||||
break; // Invalid geometry (unclosed ring)
|
||||
|
||||
current.ids.push(ways[i].id);
|
||||
ways.splice(i, 1);
|
||||
how.apply(current, what);
|
||||
}
|
||||
}
|
||||
return joined.map(function(nodes) {
|
||||
return {
|
||||
ids: nodes.ids,
|
||||
locs: _.pluck(nodes, 'loc')
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -193,6 +193,7 @@
|
||||
<script src='spec/actions/disconnect.js'></script>
|
||||
<script src="spec/actions/join.js"></script>
|
||||
<script src='spec/actions/merge.js'></script>
|
||||
<script src="spec/actions/merge_polygon.js"></script>
|
||||
<script src="spec/actions/move_node.js"></script>
|
||||
<script src="spec/actions/move.js"></script>
|
||||
<script src="spec/actions/noop.js"></script>
|
||||
|
||||
Reference in New Issue
Block a user