Add ol.geom.Geometry#getSimplifiedGeometry

This commit is contained in:
Tom Payne
2013-12-06 15:00:45 +01:00
parent 7981d86bcd
commit 9612182f70
2 changed files with 49 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ goog.provide('ol.geom.Geometry');
goog.require('goog.asserts');
goog.require('goog.events.EventType');
goog.require('goog.functions');
goog.require('goog.object');
goog.require('ol.Observable');
goog.require('ol.extent');
goog.require('ol.geom.flat');
@@ -80,6 +81,18 @@ ol.geom.Geometry = function() {
*/
this.extentRevision = -1;
/**
* @private
* @type {Object.<string, ol.geom.Geometry>}
*/
this.simplifiedGeometryCache_ = {};
/**
* @private
* @type {number}
*/
this.simplifiedGeometryRevision_ = 0;
};
goog.inherits(ol.geom.Geometry, ol.Observable);
@@ -187,6 +200,41 @@ ol.geom.Geometry.prototype.getRevision = function() {
};
/**
* @param {number} squaredTolerance Squared tolerance.
* @return {ol.geom.Geometry} Simplified geometry.
*/
ol.geom.Geometry.prototype.getSimplifiedGeometry = function(squaredTolerance) {
if (this.simplifiedGeometryRevision_ != this.revision) {
goog.object.clear(this.simplifiedGeometryCache_);
this.simplifiedGeometryRevision_ = this.revision;
}
if (squaredTolerance < 0) {
return this;
}
var key = squaredTolerance.toString();
if (this.simplifiedGeometryCache_.hasOwnProperty(key)) {
return this.simplifiedGeometryCache_[key];
} else {
var simplifiedGeometry =
this.getSimplifiedGeometryInternal(squaredTolerance);
this.simplifiedGeometryCache_[key] = simplifiedGeometry;
return simplifiedGeometry;
}
};
/**
* @param {number} squaredTolerance Squared tolerance.
* @return {ol.geom.Geometry} Simplified geometry.
* @protected
*/
ol.geom.Geometry.prototype.getSimplifiedGeometryInternal =
function(squaredTolerance) {
return this;
};
/**
* @return {number} Stride.
*/