Render unclosed areas correctly

This commit is contained in:
Ansis Brammanis
2013-02-28 14:08:03 -05:00
parent e0bc3bf7e1
commit baa9dc6e5e
3 changed files with 17 additions and 9 deletions

View File

@@ -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')
}
};
}

View File

@@ -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');
};
};

View File

@@ -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];