Cache centroid

This commit is contained in:
John Firebaugh
2013-05-17 14:49:09 -07:00
parent 2e4207f99b
commit 5344bdea26
2 changed files with 9 additions and 2 deletions
+8
View File
@@ -108,6 +108,14 @@ iD.Entity.prototype = {
});
},
// Returns the centroid of the area, in unprojected coordinates.
centroid: function(resolver) {
return resolver.transient(this, 'centroid', function() {
return iD.Entity.areaPath.projection().invert(
iD.Entity.areaPath.centroid(this.asGeoJSON(resolver, true)));
});
},
hasInterestingTags: function() {
return _.keys(this.tags).some(function(key) {
return key != 'attribution' &&
+1 -2
View File
@@ -362,8 +362,7 @@ iD.svg.Labels = function(projection, context) {
}
function getAreaLabel(entity, width, height) {
var path = d3.geo.path().projection(projection),
centroid = path.centroid(entity.asGeoJSON(graph, true)),
var centroid = projection(entity.centroid(graph)),
extent = entity.extent(graph),
entitywidth = projection(extent[1])[0] - projection(extent[0])[0],
rect;