Fix strokes sometimes being clipped as polygons

Fixes #1527.
This commit is contained in:
John Firebaugh
2013-05-28 20:30:31 -07:00
parent 27a585b7f7
commit c14e2e600e
4 changed files with 14 additions and 20 deletions
+8 -10
View File
@@ -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')
}
};
}
+2 -6
View File
@@ -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;
},
+1 -1
View File
@@ -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;
+3 -3
View File
@@ -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'});