From 396875c719bfe0ad191d9d347b30075088a82eba Mon Sep 17 00:00:00 2001 From: Marc Jansen Date: Fri, 22 Jun 2012 16:25:14 +0200 Subject: [PATCH] A centroid method for LineStrings --- src/ol/geom/LineString.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/ol/geom/LineString.js b/src/ol/geom/LineString.js index 1f449f0102..23f6e8eb0c 100644 --- a/src/ol/geom/LineString.js +++ b/src/ol/geom/LineString.js @@ -57,9 +57,20 @@ ol.geom.LineString.prototype.addVertex = function(vertex, index) { /** * Removes the given vertex from the list of vertices. - * + * * @param {ol.geom.Point} vertex A point to be removed. */ ol.geom.LineString.prototype.removeVertex = function(vertex) { goog.array.remove(this.vertices_, vertex); }; + +/** + * Compute the centroid for this linestring. + * + * @returns {ol.geom.Point} The centroid of the linestring. + */ +ol.geom.LineString.prototype.getCentroid = function() { + var vertices = this.getVertices(), + collection = new ol.geom.Collection(vertices); + return collection.getCentroid(); +}; \ No newline at end of file