-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support merging points into an area (#435)
- Loading branch information
1 parent
d7639ac
commit bd8c9d6
Showing
6 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
iD.actions.Merge = function(ids) { | ||
function groupEntitiesByGeometry(graph) { | ||
var entities = ids.map(function(id) { return graph.entity(id); }); | ||
return _.extend({point: [], area: []}, _.groupBy(entities, function(entity) { return entity.geometry(graph); })); | ||
} | ||
|
||
var action = function(graph) { | ||
var geometries = groupEntitiesByGeometry(graph), | ||
area = geometries['area'][0], | ||
points = geometries['point']; | ||
|
||
points.forEach(function (point) { | ||
area = area.mergeTags(point.tags); | ||
|
||
graph.parentRelations(point).forEach(function (parent) { | ||
graph = graph.replace(parent.replaceMember(point, area)); | ||
}); | ||
|
||
graph = graph.remove(point); | ||
}); | ||
|
||
graph = graph.replace(area); | ||
|
||
return graph; | ||
}; | ||
|
||
action.enabled = function(graph) { | ||
var geometries = groupEntitiesByGeometry(graph); | ||
return geometries['area'].length === 1 && | ||
geometries['point'].length > 0 && | ||
(geometries['area'].length + geometries['point'].length) === ids.length; | ||
}; | ||
|
||
return action; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
describe("iD.actions.Merge", function () { | ||
it("merges multiple points to an area", function () { | ||
var graph = iD.Graph({ | ||
'a': iD.Node({id: 'a', tags: {a: 'a'}}), | ||
'b': iD.Node({id: 'b', tags: {b: 'b'}}), | ||
'w': iD.Way({id: 'w', tags: {area: 'yes'}}), | ||
'r': iD.Relation({id: 'r', members: [{id: 'a', role: 'r', type: 'node'}]}) | ||
}), | ||
action = iD.actions.Merge(['a', 'b', 'w']); | ||
|
||
expect(action.enabled(graph)).to.be.true; | ||
|
||
graph = action(graph); | ||
|
||
expect(graph.entity('a')).to.be.undefined; | ||
expect(graph.entity('b')).to.be.undefined; | ||
expect(graph.entity('w').tags).to.eql({a: 'a', b: 'b', area: 'yes'}); | ||
expect(graph.entity('r').members).to.eql([{id: 'w', role: 'r', type: 'way'}]); | ||
}); | ||
}); |