Test & improve the getCentroid/centroid method of collections

This commit is contained in:
Marc Jansen
2012-06-22 18:23:40 +02:00
parent abb254a0fb
commit be9448457d
3 changed files with 73 additions and 2 deletions

View File

@@ -180,8 +180,12 @@ ol.geom.Collection.prototype.getCentroid = function() {
if (len > 0) {
goog.array.forEach(components, function(component){
var singleCentroid = component.getCentroid();
sum_x += singleCentroid.getX();
sum_y += singleCentroid.getX();
if (goog.isDefAndNotNull(singleCentroid)) {
sum_x += singleCentroid.getX();
sum_y += singleCentroid.getX();
} else {
len--;
}
});
centroid = new ol.geom.Point(sum_x / len, sum_y / len);
}