Cache the buffered extent value
Assuming that the maxExtent and resolution property are immutable
This commit is contained in:
@@ -62,10 +62,17 @@ ol.render.canvas.Replay = function(tolerance, maxExtent, resolution) {
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @const
|
||||
* @type {ol.Extent}
|
||||
*/
|
||||
this.maxExtent = maxExtent;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Extent}
|
||||
*/
|
||||
this.bufferedMaxExtent_ = null;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {number}
|
||||
@@ -74,6 +81,7 @@ ol.render.canvas.Replay = function(tolerance, maxExtent, resolution) {
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @const
|
||||
* @type {number}
|
||||
*/
|
||||
this.resolution = resolution;
|
||||
@@ -964,12 +972,14 @@ ol.render.canvas.LineStringReplay.prototype.drawFlatCoordinates_ =
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.render.canvas.LineStringReplay.prototype.getBufferedMaxExtent = function() {
|
||||
var extent = this.maxExtent;
|
||||
if (this.maxLineWidth) {
|
||||
extent = ol.extent.buffer(
|
||||
extent, this.resolution * (this.maxLineWidth + 1) / 2);
|
||||
if (goog.isNull(this.bufferedMaxExtent_)) {
|
||||
this.bufferedMaxExtent_ = ol.extent.clone(this.maxExtent);
|
||||
if (this.maxLineWidth > 0) {
|
||||
var width = this.resolution * (this.maxLineWidth + 1) / 2;
|
||||
ol.extent.buffer(this.bufferedMaxExtent_, width, this.bufferedMaxExtent_);
|
||||
}
|
||||
}
|
||||
return extent;
|
||||
return this.bufferedMaxExtent_;
|
||||
};
|
||||
|
||||
|
||||
@@ -1116,7 +1126,12 @@ ol.render.canvas.LineStringReplay.prototype.setFillStrokeStyle =
|
||||
var strokeStyleMiterLimit = strokeStyle.getMiterLimit();
|
||||
this.state_.miterLimit = goog.isDef(strokeStyleMiterLimit) ?
|
||||
strokeStyleMiterLimit : ol.render.canvas.defaultMiterLimit;
|
||||
this.maxLineWidth = Math.max(this.maxLineWidth, this.state_.lineWidth);
|
||||
|
||||
if (this.state_.lineWidth > this.maxLineWidth) {
|
||||
this.maxLineWidth = this.state_.lineWidth;
|
||||
// invalidate the buffered max extent cache
|
||||
this.bufferedMaxExtent_ = null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1369,12 +1384,14 @@ ol.render.canvas.PolygonReplay.prototype.finish = function() {
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.render.canvas.PolygonReplay.prototype.getBufferedMaxExtent = function() {
|
||||
var extent = this.maxExtent;
|
||||
if (this.maxLineWidth) {
|
||||
extent = ol.extent.buffer(
|
||||
extent, this.resolution * (this.maxLineWidth + 1) / 2);
|
||||
if (goog.isNull(this.bufferedMaxExtent_)) {
|
||||
this.bufferedMaxExtent_ = ol.extent.clone(this.maxExtent);
|
||||
if (this.maxLineWidth > 0) {
|
||||
var width = this.resolution * (this.maxLineWidth + 1) / 2;
|
||||
ol.extent.buffer(this.bufferedMaxExtent_, width, this.bufferedMaxExtent_);
|
||||
}
|
||||
}
|
||||
return extent;
|
||||
return this.bufferedMaxExtent_;
|
||||
};
|
||||
|
||||
|
||||
@@ -1412,7 +1429,12 @@ ol.render.canvas.PolygonReplay.prototype.setFillStrokeStyle =
|
||||
var strokeStyleMiterLimit = strokeStyle.getMiterLimit();
|
||||
state.miterLimit = goog.isDef(strokeStyleMiterLimit) ?
|
||||
strokeStyleMiterLimit : ol.render.canvas.defaultMiterLimit;
|
||||
this.maxLineWidth = Math.max(this.maxLineWidth, state.lineWidth);
|
||||
|
||||
if (state.lineWidth > this.maxLineWidth) {
|
||||
this.maxLineWidth = state.lineWidth;
|
||||
// invalidate the buffered max extent cache
|
||||
this.bufferedMaxExtent_ = null;
|
||||
}
|
||||
} else {
|
||||
state.strokeStyle = undefined;
|
||||
state.lineCap = undefined;
|
||||
|
||||
Reference in New Issue
Block a user