LinearRing.getCentroid: return null if the geometry has no components. r=pgiraud (closes #2530)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@10116 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -190,7 +190,7 @@ OpenLayers.Geometry.LinearRing = OpenLayers.Class(
|
||||
* {<OpenLayers.Geometry.Point>} The centroid of the collection
|
||||
*/
|
||||
getCentroid: function() {
|
||||
if ( this.components && (this.components.length > 2)) {
|
||||
if (this.components && (this.components.length > 2)) {
|
||||
var sumX = 0.0;
|
||||
var sumY = 0.0;
|
||||
for (var i = 0; i < this.components.length - 1; i++) {
|
||||
@@ -202,8 +202,10 @@ OpenLayers.Geometry.LinearRing = OpenLayers.Class(
|
||||
var area = -1 * this.getArea();
|
||||
var x = sumX / (6 * area);
|
||||
var y = sumY / (6 * area);
|
||||
return new OpenLayers.Geometry.Point(x, y);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return new OpenLayers.Geometry.Point(x, y);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user