diff --git a/js/id/core/way.js b/js/id/core/way.js index 51590350b..1e7b32efa 100644 --- a/js/id/core/way.js +++ b/js/id/core/way.js @@ -118,14 +118,22 @@ _.extend(iD.Way.prototype, { return r; }, - asGeoJSON: function(resolver) { - if (this.isArea()) { + asGeoJSON: function(resolver, close) { + + var childnodes = resolver.childNodes(this); + + // Close unclosed way + if (close && !this.isClosed()) { + childnodes = childnodes.concat([childnodes[0]]); + } + + if (this.isArea() && (close || this.isClosed())) { return { type: 'Feature', properties: this.tags, geometry: { type: 'Polygon', - coordinates: [_.pluck(resolver.childNodes(this), 'loc')] + coordinates: [_.pluck(childnodes, 'loc')] } }; } else { @@ -134,7 +142,7 @@ _.extend(iD.Way.prototype, { properties: this.tags, geometry: { type: 'LineString', - coordinates: _.pluck(resolver.childNodes(this), 'loc') + coordinates: _.pluck(childnodes, 'loc') } }; } diff --git a/js/id/svg/areas.js b/js/id/svg/areas.js index 46df5544c..adad6e03a 100644 --- a/js/id/svg/areas.js +++ b/js/id/svg/areas.js @@ -8,14 +8,14 @@ iD.svg.Areas = function(projection) { if (entity.geometry(graph) === 'area') { areas.push({ entity: entity, - area: Math.abs(path.area(entity.asGeoJSON(graph))) + area: Math.abs(path.area(entity.asGeoJSON(graph, true))) }); } } areas.sort(function(a, b) { return b.area - a.area; }); - function drawPaths(group, areas, filter, klass) { + function drawPaths(group, areas, filter, klass, closeWay) { var tagClasses = iD.svg.TagClasses(); if (klass === 'stroke') { @@ -32,7 +32,7 @@ iD.svg.Areas = function(projection) { paths .order() - .attr('d', function(entity) { return path(entity.asGeoJSON(graph)); }) + .attr('d', function(entity) { return path(entity.asGeoJSON(graph, closeWay)); }) .call(tagClasses) .call(iD.svg.MemberClasses(graph)); @@ -51,7 +51,7 @@ iD.svg.Areas = function(projection) { var fill = surface.select('.layer-fill'), stroke = surface.select('.layer-stroke'); - drawPaths(fill, areas, filter, 'fill'); + drawPaths(fill, areas, filter, 'fill', true); drawPaths(stroke, strokes, filter, 'stroke'); }; }; diff --git a/js/id/svg/labels.js b/js/id/svg/labels.js index 0636c49d6..fadbf1f56 100644 --- a/js/id/svg/labels.js +++ b/js/id/svg/labels.js @@ -359,7 +359,7 @@ iD.svg.Labels = function(projection) { function getAreaLabel(entity, width, height) { var path = d3.geo.path().projection(projection), - centroid = path.centroid(entity.asGeoJSON(graph)), + centroid = path.centroid(entity.asGeoJSON(graph, true)), extent = entity.extent(graph), entitywidth = projection(extent[1])[0] - projection(extent[0])[0];