Cache ol.geom.Polygon interior point
This commit is contained in:
+20
-4
@@ -22,6 +22,18 @@ ol.geom.Polygon = function(coordinates, opt_layout) {
|
|||||||
*/
|
*/
|
||||||
this.ends_ = [];
|
this.ends_ = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
this.interiorPointRevision_ = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {ol.Coordinate}
|
||||||
|
*/
|
||||||
|
this.interiorPoint_ = null;
|
||||||
|
|
||||||
this.setCoordinates(coordinates, opt_layout);
|
this.setCoordinates(coordinates, opt_layout);
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -58,10 +70,14 @@ ol.geom.Polygon.prototype.getEnds = function() {
|
|||||||
* @return {ol.Coordinate} Interior point.
|
* @return {ol.Coordinate} Interior point.
|
||||||
*/
|
*/
|
||||||
ol.geom.Polygon.prototype.getInteriorPoint = function() {
|
ol.geom.Polygon.prototype.getInteriorPoint = function() {
|
||||||
var extent = this.getExtent();
|
if (this.interiorPointRevision_ != this.revision) {
|
||||||
var y = (extent[1] + extent[3]) / 2;
|
var extent = this.getExtent();
|
||||||
return ol.geom.flat.linearRingsGetInteriorPoint(
|
var y = (extent[1] + extent[3]) / 2;
|
||||||
this.flatCoordinates, 0, this.ends_, this.stride, y);
|
this.interiorPoint_ = ol.geom.flat.linearRingsGetInteriorPoint(
|
||||||
|
this.flatCoordinates, 0, this.ends_, this.stride, y);
|
||||||
|
this.interiorPointRevision_ = this.revision;
|
||||||
|
}
|
||||||
|
return this.interiorPoint_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user