Merge pull request #5752 from ahocevar/fix-rotated-replaycontext

Set proper replay canvas size and offset for rotated view
This commit is contained in:
Andreas Hocevar
2016-08-22 21:40:29 +02:00
committed by GitHub

View File

@@ -88,11 +88,21 @@ ol.renderer.canvas.VectorLayer.prototype.composeFrame = function(frameState, lay
var replayGroup = this.replayGroup_;
if (replayGroup && !replayGroup.isEmpty()) {
var layer = this.getLayer();
var drawOffsetX = 0;
var drawOffsetY = 0;
var replayContext;
if (layer.hasListener(ol.render.EventType.RENDER)) {
var drawWidth = context.canvas.width;
var drawHeight = context.canvas.height;
if (rotation) {
var drawSize = Math.round(Math.sqrt(drawWidth * drawWidth + drawHeight * drawHeight));
drawOffsetX = (drawSize - drawWidth) / 2;
drawOffsetY = (drawSize - drawHeight) / 2;
drawWidth = drawHeight = drawSize;
}
// resize and clear
this.context_.canvas.width = context.canvas.width;
this.context_.canvas.height = context.canvas.height;
this.context_.canvas.width = drawWidth;
this.context_.canvas.height = drawHeight;
replayContext = this.context_;
} else {
replayContext = context;
@@ -102,6 +112,9 @@ ol.renderer.canvas.VectorLayer.prototype.composeFrame = function(frameState, lay
// see http://jsperf.com/context-save-restore-versus-variable
var alpha = replayContext.globalAlpha;
replayContext.globalAlpha = layerState.opacity;
if (replayContext != context) {
replayContext.translate(drawOffsetX, drawOffsetY);
}
var width = frameState.size[0] * pixelRatio;
var height = frameState.size[1] * pixelRatio;
@@ -141,7 +154,8 @@ ol.renderer.canvas.VectorLayer.prototype.composeFrame = function(frameState, lay
if (replayContext != context) {
this.dispatchRenderEvent(replayContext, frameState, transform);
context.drawImage(replayContext.canvas, 0, 0);
context.drawImage(replayContext.canvas, -drawOffsetX, -drawOffsetY);
replayContext.translate(-drawOffsetX, -drawOffsetY);
}
replayContext.globalAlpha = alpha;
}