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
|
* @protected
|
||||||
|
* @const
|
||||||
* @type {ol.Extent}
|
* @type {ol.Extent}
|
||||||
*/
|
*/
|
||||||
this.maxExtent = maxExtent;
|
this.maxExtent = maxExtent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {ol.Extent}
|
||||||
|
*/
|
||||||
|
this.bufferedMaxExtent_ = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @protected
|
* @protected
|
||||||
* @type {number}
|
* @type {number}
|
||||||
@@ -74,6 +81,7 @@ ol.render.canvas.Replay = function(tolerance, maxExtent, resolution) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @protected
|
* @protected
|
||||||
|
* @const
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
this.resolution = resolution;
|
this.resolution = resolution;
|
||||||
@@ -964,12 +972,14 @@ ol.render.canvas.LineStringReplay.prototype.drawFlatCoordinates_ =
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.render.canvas.LineStringReplay.prototype.getBufferedMaxExtent = function() {
|
ol.render.canvas.LineStringReplay.prototype.getBufferedMaxExtent = function() {
|
||||||
var extent = this.maxExtent;
|
if (goog.isNull(this.bufferedMaxExtent_)) {
|
||||||
if (this.maxLineWidth) {
|
this.bufferedMaxExtent_ = ol.extent.clone(this.maxExtent);
|
||||||
extent = ol.extent.buffer(
|
if (this.maxLineWidth > 0) {
|
||||||
extent, this.resolution * (this.maxLineWidth + 1) / 2);
|
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();
|
var strokeStyleMiterLimit = strokeStyle.getMiterLimit();
|
||||||
this.state_.miterLimit = goog.isDef(strokeStyleMiterLimit) ?
|
this.state_.miterLimit = goog.isDef(strokeStyleMiterLimit) ?
|
||||||
strokeStyleMiterLimit : ol.render.canvas.defaultMiterLimit;
|
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
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.render.canvas.PolygonReplay.prototype.getBufferedMaxExtent = function() {
|
ol.render.canvas.PolygonReplay.prototype.getBufferedMaxExtent = function() {
|
||||||
var extent = this.maxExtent;
|
if (goog.isNull(this.bufferedMaxExtent_)) {
|
||||||
if (this.maxLineWidth) {
|
this.bufferedMaxExtent_ = ol.extent.clone(this.maxExtent);
|
||||||
extent = ol.extent.buffer(
|
if (this.maxLineWidth > 0) {
|
||||||
extent, this.resolution * (this.maxLineWidth + 1) / 2);
|
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();
|
var strokeStyleMiterLimit = strokeStyle.getMiterLimit();
|
||||||
state.miterLimit = goog.isDef(strokeStyleMiterLimit) ?
|
state.miterLimit = goog.isDef(strokeStyleMiterLimit) ?
|
||||||
strokeStyleMiterLimit : ol.render.canvas.defaultMiterLimit;
|
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 {
|
} else {
|
||||||
state.strokeStyle = undefined;
|
state.strokeStyle = undefined;
|
||||||
state.lineCap = undefined;
|
state.lineCap = undefined;
|
||||||
|
|||||||
Reference in New Issue
Block a user