Convert iD.format.GeoJSON to member functions

This commit is contained in:
John Firebaugh
2013-01-26 21:01:44 -05:00
parent 50b997599d
commit 646c746991
8 changed files with 49 additions and 48 deletions
-1
View File
@@ -103,7 +103,6 @@
<script src='../js/id/controller/controller.js'></script>
<script src='../js/id/format/format.js'></script>
<script src='../js/id/format/geojson.js'></script>
<script src='../js/id/format/xml.js'></script>
<script src='../js/id/graph/entity.js'></script>
-1
View File
@@ -47,7 +47,6 @@
<script src="spec/behavior/hover.js"></script>
<script src="spec/format/geojson.js"></script>
<script src="spec/format/xml.js"></script>
<script src="spec/geo/extent.js"></script>
-17
View File
@@ -1,17 +0,0 @@
describe('iD.format.GeoJSON', function() {
describe('#mapping', function() {
it('converts a node to GeoJSON', function() {
var node = iD.Node({loc: [-77, 38]}),
graph = iD.Graph([node]);
expect(iD.format.GeoJSON.mapping(node, graph).geometry.type).to.equal('Point');
});
it('converts a way to GeoJSON', function() {
var way = iD.Way(),
graph = iD.Graph([way]),
json = iD.format.GeoJSON.mapping(way, graph);
expect(json.type).to.equal('Feature');
expect(json.geometry.type).to.equal('LineString');
});
});
});
+12
View File
@@ -51,4 +51,16 @@ describe('iD.Node', function () {
expect(node.geometry(graph)).to.equal('point');
});
});
describe("#asGeoJSON", function () {
it("converts to a GeoJSON Point features", function () {
var node = iD.Node({tags: {amenity: 'cafe'}, loc: [1, 2]}),
json = node.asGeoJSON();
expect(json.type).to.equal('Feature');
expect(json.properties).to.eql({amenity: 'cafe'});
expect(json.geometry.type).to.equal('Point');
expect(json.geometry.coordinates).to.eql([1, 2]);
});
});
});
+15
View File
@@ -199,4 +199,19 @@ describe('iD.Way', function() {
expect(w.removeNode('a').nodes).to.eql(['b', 'c', 'd', 'b']);
});
});
describe("#asGeoJSON", function () {
it("converts 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]}),
graph = iD.Graph([a, b, w]),
json = w.asGeoJSON(graph);
expect(json.type).to.equal('Feature');
expect(json.properties).to.eql({highway: 'residential'});
expect(json.geometry.type).to.equal('LineString');
expect(json.geometry.coordinates).to.eql([[1, 2], [3, 4]]);
});
});
});