Move gradient and pattern fills with the view

This commit is contained in:
Andreas Hocevar
2016-10-13 09:27:55 +02:00
parent 043a8ab1db
commit f655f6740e
4 changed files with 67 additions and 49 deletions

View File

@@ -58,6 +58,12 @@ ol.render.canvas.Replay = function(tolerance, maxExtent, resolution, overlaps) {
*/
this.resolution = resolution;
/**
* @private
* @type {boolean}
*/
this.alignFill_ = false;
/**
* @private
* @type {Array.<*>}
@@ -185,6 +191,19 @@ ol.render.canvas.Replay.prototype.beginGeometry = function(geometry, feature) {
};
ol.render.canvas.Replay.prototype.fill_ = function(context, transform, rotation) {
if (this.alignFill_) {
context.translate(transform[4], transform[5]);
context.rotate(rotation);
}
context.fill();
if (this.alignFill_) {
context.rotate(-rotation);
context.translate(-transform[4], -transform[5]);
}
};
/**
* @private
* @param {CanvasRenderingContext2D} context Context.
@@ -250,7 +269,7 @@ ol.render.canvas.Replay.prototype.replay_ = function(
break;
case ol.render.canvas.Instruction.BEGIN_PATH:
if (pendingFill > batchSize) {
context.fill();
this.fill_(context, transform, viewRotation);
pendingFill = 0;
}
if (pendingStroke > batchSize) {
@@ -429,7 +448,7 @@ ol.render.canvas.Replay.prototype.replay_ = function(
if (batchSize) {
pendingFill++;
} else {
context.fill();
this.fill_(context, transform, viewRotation);
}
++i;
break;
@@ -467,8 +486,10 @@ ol.render.canvas.Replay.prototype.replay_ = function(
ol.colorlike.isColorLike(instruction[1]),
'2nd instruction should be a string, ' +
'CanvasPattern, or CanvasGradient');
this.alignFill_ = instruction[2];
if (pendingFill) {
context.fill();
this.fill_(context, transform, viewRotation);
pendingFill = 0;
}
@@ -534,7 +555,7 @@ ol.render.canvas.Replay.prototype.replay_ = function(
}
}
if (pendingFill) {
context.fill();
this.fill_(context, transform, viewRotation);
}
if (pendingStroke) {
context.stroke();