From dd1e0c616a99ebc8e7bf792f2a771a488a0296c7 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sun, 1 Dec 2013 18:30:07 +0100 Subject: [PATCH] Cache ol.geom.MultiPolygon interior points --- src/ol/geom/multipolygon.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/ol/geom/multipolygon.js b/src/ol/geom/multipolygon.js index eca4120f3c..186e5ac2c2 100644 --- a/src/ol/geom/multipolygon.js +++ b/src/ol/geom/multipolygon.js @@ -22,6 +22,18 @@ ol.geom.MultiPolygon = function(coordinates, opt_layout) { */ this.endss_ = []; + /** + * @private + * @type {number} + */ + this.interiorPointsRevision_ = -1; + + /** + * @private + * @type {Array.} + */ + this.interiorPoints_ = null; + this.setCoordinates(coordinates, opt_layout); }; @@ -58,10 +70,14 @@ ol.geom.MultiPolygon.prototype.getEndss = function() { * @return {Array.} Interior points. */ ol.geom.MultiPolygon.prototype.getInteriorPoints = function() { - var ys = ol.geom.flat.linearRingssMidYs( - this.flatCoordinates, 0, this.endss_, this.stride); - return ol.geom.flat.linearRingssGetInteriorPoints( - this.flatCoordinates, 0, this.endss_, this.stride, ys); + if (this.interiorPointsRevision_ != this.revision) { + var ys = ol.geom.flat.linearRingssMidYs( + this.flatCoordinates, 0, this.endss_, this.stride); + this.interiorPoints_ = ol.geom.flat.linearRingssGetInteriorPoints( + this.flatCoordinates, 0, this.endss_, this.stride, ys); + this.interiorPointsRevision_ = this.revision; + } + return this.interiorPoints_; };