mirror of
https://github.com/FoggedLens/iD.git
synced 2026-06-04 05:58:09 +02:00
+8
-10
@@ -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
@@ -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
@@ -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;
|
||||
|
||||
|
||||
@@ -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'});
|
||||
|
||||
Reference in New Issue
Block a user