diff --git a/js/id/core/way.js b/js/id/core/way.js index a8fde5f8d..3cb7bfa77 100644 --- a/js/id/core/way.js +++ b/js/id/core/way.js @@ -136,22 +136,20 @@ _.extend(iD.Way.prototype, { return r; }, - asGeoJSON: function(resolver, close) { + asGeoJSON: function(resolver, polygon) { + var nodes = resolver.childNodes(this); - var childnodes = resolver.childNodes(this); + if (this.isArea() && polygon && nodes.length >= 4) { + if (!this.isClosed()) { + nodes = nodes.concat([nodes[0]]); + } - // Close unclosed way - if (close && !this.isClosed() && childnodes.length) { - childnodes = childnodes.concat([childnodes[0]]); - } - - if (this.isArea() && childnodes.length >= 4 && (close || this.isClosed())) { return { type: 'Feature', properties: this.tags, geometry: { type: 'Polygon', - coordinates: [_.pluck(childnodes, 'loc')] + coordinates: [_.pluck(nodes, 'loc')] } }; } else { @@ -160,7 +158,7 @@ _.extend(iD.Way.prototype, { properties: this.tags, geometry: { type: 'LineString', - coordinates: _.pluck(childnodes, 'loc') + coordinates: _.pluck(nodes, 'loc') } }; } diff --git a/js/id/svg.js b/js/id/svg.js index 013d5cf98..5394951a4 100644 --- a/js/id/svg.js +++ b/js/id/svg.js @@ -13,7 +13,7 @@ iD.svg = { }; }, - Path: function(projection, graph) { + Path: function(projection, graph, polygon) { var cache = {}, path = d3.geo.path().projection(projection); @@ -30,15 +30,11 @@ iD.svg = { closePath: function() { buffer += 'Z'; } }); - path(entity.asGeoJSON(graph)); + path(entity.asGeoJSON(graph, polygon)); return cache[entity.id] = buffer; } - result.area = function(entity) { - return path.area(entity.asGeoJSON(graph, true)); - }; - return result; }, diff --git a/js/id/svg/areas.js b/js/id/svg/areas.js index b051c7b04..1f02a05ee 100644 --- a/js/id/svg/areas.js +++ b/js/id/svg/areas.js @@ -26,7 +26,7 @@ iD.svg.Areas = function(projection) { } return function drawAreas(surface, graph, entities, filter) { - var path = iD.svg.Path(projection, graph), + var path = iD.svg.Path(projection, graph, true), areas = {}, multipolygon; diff --git a/test/spec/core/way.js b/test/spec/core/way.js index 6db0f6b5c..d836fc975 100644 --- a/test/spec/core/way.js +++ b/test/spec/core/way.js @@ -267,7 +267,7 @@ describe('iD.Way', function() { }); describe("#asGeoJSON", function () { - it("converts a line to a GeoJSON LineString features", function () { + it("converts a line to a GeoJSON LineString feature", 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]}), @@ -280,13 +280,13 @@ describe('iD.Way', function() { expect(json.geometry.coordinates).to.eql([[1, 2], [3, 4]]); }); - it("converts an area to a GeoJSON Polygon features", function () { + it("converts an area to a GeoJSON Polygon feature", 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); + json = w.asGeoJSON(graph, true); expect(json.type).to.equal('Feature'); expect(json.properties).to.eql({area: 'yes'});