diff --git a/js/id/format/geojson.js b/js/id/format/geojson.js
deleted file mode 100644
index 35105b5f6..000000000
--- a/js/id/format/geojson.js
+++ /dev/null
@@ -1,29 +0,0 @@
-iD.format.GeoJSON = {
- mapping: function(entity, graph) {
- if (this.mappings[entity.type]) {
- return this.mappings[entity.type](entity, graph);
- }
- },
- mappings: {
- node: function(entity) {
- return {
- type: 'Feature',
- properties: entity.tags,
- geometry: {
- type: 'Point',
- coordinates: entity.loc
- }
- };
- },
- way: function(entity, graph) {
- return {
- type: 'Feature',
- properties: entity.tags,
- geometry: {
- 'type': 'LineString',
- 'coordinates': _.pluck(graph.childNodes(entity), 'loc')
- }
- };
- }
- }
-};
diff --git a/js/id/graph/node.js b/js/id/graph/node.js
index d9069d6fb..d3bd48638 100644
--- a/js/id/graph/node.js
+++ b/js/id/graph/node.js
@@ -21,5 +21,16 @@ _.extend(iD.Node.prototype, {
move: function(loc) {
return this.update({loc: loc});
+ },
+
+ asGeoJSON: function() {
+ return {
+ type: 'Feature',
+ properties: this.tags,
+ geometry: {
+ type: 'Point',
+ coordinates: this.loc
+ }
+ }
}
});
diff --git a/js/id/graph/way.js b/js/id/graph/way.js
index 19cd0fd7e..b0cffa058 100644
--- a/js/id/graph/way.js
+++ b/js/id/graph/way.js
@@ -83,5 +83,16 @@ _.extend(iD.Way.prototype, {
}
return this.update({nodes: nodes});
+ },
+
+ asGeoJSON: function(resolver) {
+ return {
+ type: 'Feature',
+ properties: this.tags,
+ geometry: {
+ type: 'LineString',
+ coordinates: _.pluck(resolver.childNodes(this), 'loc')
+ }
+ };
}
});
diff --git a/test/index.html b/test/index.html
index b3505f903..a14bade99 100644
--- a/test/index.html
+++ b/test/index.html
@@ -103,7 +103,6 @@
-
diff --git a/test/index_packaged.html b/test/index_packaged.html
index 5a013b45c..c86734083 100644
--- a/test/index_packaged.html
+++ b/test/index_packaged.html
@@ -47,7 +47,6 @@
-
diff --git a/test/spec/format/geojson.js b/test/spec/format/geojson.js
deleted file mode 100644
index 4071f051c..000000000
--- a/test/spec/format/geojson.js
+++ /dev/null
@@ -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');
- });
- });
-});
diff --git a/test/spec/graph/node.js b/test/spec/graph/node.js
index 1f02c1302..75696533f 100644
--- a/test/spec/graph/node.js
+++ b/test/spec/graph/node.js
@@ -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]);
+ });
+ });
});
diff --git a/test/spec/graph/way.js b/test/spec/graph/way.js
index 87d7d0029..d59185a17 100644
--- a/test/spec/graph/way.js
+++ b/test/spec/graph/way.js
@@ -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]]);
+ });
+ });
});