diff --git a/js/id/core/relation.js b/js/id/core/relation.js index f233ac470..049c4ddd9 100644 --- a/js/id/core/relation.js +++ b/js/id/core/relation.js @@ -134,24 +134,26 @@ _.extend(iD.Relation.prototype, { }, asGeoJSON: function(resolver) { - if (this.isMultipolygon()) { - return { - type: 'Feature', - properties: this.tags, - geometry: { - type: 'MultiPolygon', - coordinates: this.multipolygon(resolver) - } - }; - } else { - return { - type: 'FeatureCollection', - properties: this.tags, - features: this.members.map(function(member) { - return _.extend({role: member.role}, resolver.entity(member.id).asGeoJSON(resolver)); - }) - }; - } + return resolver.transient(this, 'GeoJSON', function () { + if (this.isMultipolygon()) { + return { + type: 'Feature', + properties: this.tags, + geometry: { + type: 'MultiPolygon', + coordinates: this.multipolygon(resolver) + } + }; + } else { + return { + type: 'FeatureCollection', + properties: this.tags, + features: this.members.map(function (member) { + return _.extend({role: member.role}, resolver.entity(member.id).asGeoJSON(resolver)); + }) + }; + } + }); }, isMultipolygon: function() { diff --git a/js/id/core/way.js b/js/id/core/way.js index f62d58dd7..c0b5fb058 100644 --- a/js/id/core/way.js +++ b/js/id/core/way.js @@ -137,39 +137,41 @@ _.extend(iD.Way.prototype, { }, asGeoJSON: function(resolver, polygon) { - var nodes = resolver.childNodes(this); + return resolver.transient(this, 'GeoJSON', function() { + var nodes = resolver.childNodes(this); - if (this.isArea() && polygon && nodes.length >= 4) { - if (!this.isClosed()) { - nodes = nodes.concat([nodes[0]]); - } - - var json = { - type: 'Feature', - properties: this.tags, - geometry: { - type: 'Polygon', - coordinates: [_.pluck(nodes, 'loc')] + if (this.isArea() && polygon && nodes.length >= 4) { + if (!this.isClosed()) { + nodes = nodes.concat([nodes[0]]); } - }; - // Heuristic for detecting counterclockwise winding order. Assumes - // that OpenStreetMap polygons are not hemisphere-spanning. - if (d3.geo.area(json) > 2 * Math.PI) { - json.geometry.coordinates[0] = json.geometry.coordinates[0].reverse(); - } + var json = { + type: 'Feature', + properties: this.tags, + geometry: { + type: 'Polygon', + coordinates: [_.pluck(nodes, 'loc')] + } + }; - return json; - } else { - return { - type: 'Feature', - properties: this.tags, - geometry: { - type: 'LineString', - coordinates: _.pluck(nodes, 'loc') + // Heuristic for detecting counterclockwise winding order. Assumes + // that OpenStreetMap polygons are not hemisphere-spanning. + if (d3.geo.area(json) > 2 * Math.PI) { + json.geometry.coordinates[0] = json.geometry.coordinates[0].reverse(); } - }; - } + + return json; + } else { + return { + type: 'Feature', + properties: this.tags, + geometry: { + type: 'LineString', + coordinates: _.pluck(nodes, 'loc') + } + }; + } + }); } });