mirror of
https://github.com/FoggedLens/iD.git
synced 2026-03-04 02:13:44 +00:00
Better Way#asGeoJSON
This commit is contained in:
@@ -103,13 +103,24 @@ _.extend(iD.Way.prototype, {
|
||||
},
|
||||
|
||||
asGeoJSON: function(resolver) {
|
||||
return {
|
||||
type: 'Feature',
|
||||
properties: this.tags,
|
||||
geometry: {
|
||||
type: 'LineString',
|
||||
coordinates: _.pluck(resolver.childNodes(this), 'loc')
|
||||
}
|
||||
};
|
||||
if (this.isArea()) {
|
||||
return {
|
||||
type: 'Feature',
|
||||
properties: this.tags,
|
||||
geometry: {
|
||||
type: 'Polygon',
|
||||
coordinates: [_.pluck(resolver.childNodes(this), 'loc')]
|
||||
}
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
type: 'Feature',
|
||||
properties: this.tags,
|
||||
geometry: {
|
||||
type: 'LineString',
|
||||
coordinates: _.pluck(resolver.childNodes(this), 'loc')
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -207,7 +207,7 @@ describe('iD.Way', function() {
|
||||
});
|
||||
|
||||
describe("#asGeoJSON", function () {
|
||||
it("converts to a GeoJSON LineString features", function () {
|
||||
it("converts a line to a GeoJSON LineString features", function () {
|
||||
var a = iD.Node({loc: [1, 2]}),
|
||||
b = iD.Node({loc: [3, 4]}),
|
||||
w = iD.Way({tags: {highway: 'residential'}, nodes: [a.id, b.id]}),
|
||||
@@ -219,5 +219,19 @@ describe('iD.Way', function() {
|
||||
expect(json.geometry.type).to.equal('LineString');
|
||||
expect(json.geometry.coordinates).to.eql([[1, 2], [3, 4]]);
|
||||
});
|
||||
|
||||
it("converts an area to a GeoJSON Polygon features", function () {
|
||||
var a = iD.Node({loc: [1, 2]}),
|
||||
b = iD.Node({loc: [3, 4]}),
|
||||
c = iD.Node({loc: [5, 6]}),
|
||||
w = iD.Way({tags: {area: 'yes'}, nodes: [a.id, b.id, c.id, a.id]}),
|
||||
graph = iD.Graph([a, b, c, w]),
|
||||
json = w.asGeoJSON(graph);
|
||||
|
||||
expect(json.type).to.equal('Feature');
|
||||
expect(json.properties).to.eql({area: 'yes'});
|
||||
expect(json.geometry.type).to.equal('Polygon');
|
||||
expect(json.geometry.coordinates).to.eql([[[1, 2], [3, 4], [5, 6], [1, 2]]]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user