Overloading fill color (polygon or text) with CanvasPattern and CanvasGradient.

This commit is contained in:
Brett Johnson
2016-01-06 09:57:40 -08:00
parent aa508acde4
commit 7f02b63ccc
8 changed files with 77 additions and 21 deletions

View File

@@ -2,7 +2,7 @@ goog.provide('ol.render.canvas');
/**
* @typedef {{fillStyle: string}}
* @typedef {{fillStyle: ol.ColorLike}}
*/
ol.render.canvas.FillState;

View File

@@ -8,6 +8,7 @@ goog.require('goog.asserts');
goog.require('goog.vec.Mat4');
goog.require('ol.array');
goog.require('ol.color');
goog.require('ol.colorlike');
goog.require('ol.extent');
goog.require('ol.geom.flat.transform');
goog.require('ol.has');
@@ -835,7 +836,7 @@ ol.render.canvas.Immediate.prototype.setFillStrokeStyle = function(fillStyle, st
} else {
var fillStyleColor = fillStyle.getColor();
this.fillState_ = {
fillStyle: ol.color.asString(fillStyleColor ?
fillStyle: ol.colorlike.asColorLike(fillStyleColor ?
fillStyleColor : ol.render.canvas.defaultFillStyle)
};
}
@@ -919,7 +920,7 @@ ol.render.canvas.Immediate.prototype.setTextStyle = function(textStyle) {
} else {
var textFillStyleColor = textFillStyle.getColor();
this.textFillState_ = {
fillStyle: ol.color.asString(textFillStyleColor ?
fillStyle: ol.colorlike.asColorLike(textFillStyleColor ?
textFillStyleColor : ol.render.canvas.defaultFillStyle)
};
}

View File

@@ -13,6 +13,7 @@ goog.require('goog.vec.Mat4');
goog.require('ol');
goog.require('ol.array');
goog.require('ol.color');
goog.require('ol.colorlike');
goog.require('ol.dom');
goog.require('ol.extent');
goog.require('ol.extent.Relationship');
@@ -497,9 +498,11 @@ ol.render.canvas.Replay.prototype.replay_ = function(
++i;
break;
case ol.render.canvas.Instruction.SET_FILL_STYLE:
goog.asserts.assert(typeof instruction[1] === 'string',
'2nd instruction should be a string');
context.fillStyle = /** @type {string} */ (instruction[1]);
goog.asserts.assert(
ol.colorlike.isColorLike(instruction[1]),
'2nd instruction should be a string, ' +
'CanvasPattern, or CanvasGradient');
context.fillStyle = /** @type {ol.ColorLike} */ (instruction[1]);
++i;
break;
case ol.render.canvas.Instruction.SET_STROKE_STYLE:
@@ -1180,14 +1183,14 @@ ol.render.canvas.PolygonReplay = function(tolerance, maxExtent, resolution) {
/**
* @private
* @type {{currentFillStyle: (string|undefined),
* @type {{currentFillStyle: (ol.ColorLike|undefined),
* currentStrokeStyle: (string|undefined),
* currentLineCap: (string|undefined),
* currentLineDash: Array.<number>,
* currentLineJoin: (string|undefined),
* currentLineWidth: (number|undefined),
* currentMiterLimit: (number|undefined),
* fillStyle: (string|undefined),
* fillStyle: (ol.ColorLike|undefined),
* strokeStyle: (string|undefined),
* lineCap: (string|undefined),
* lineDash: Array.<number>,
@@ -1435,7 +1438,7 @@ ol.render.canvas.PolygonReplay.prototype.setFillStrokeStyle = function(fillStyle
var state = this.state_;
if (fillStyle) {
var fillStyleColor = fillStyle.getColor();
state.fillStyle = ol.color.asString(fillStyleColor ?
state.fillStyle = ol.colorlike.asColorLike(fillStyleColor ?
fillStyleColor : ol.render.canvas.defaultFillStyle);
} else {
state.fillStyle = undefined;
@@ -1742,7 +1745,7 @@ ol.render.canvas.TextReplay.prototype.setTextStyle = function(textStyle) {
this.textFillState_ = null;
} else {
var textFillStyleColor = textFillStyle.getColor();
var fillStyle = ol.color.asString(textFillStyleColor ?
var fillStyle = ol.colorlike.asColorLike(textFillStyleColor ?
textFillStyleColor : ol.render.canvas.defaultFillStyle);
if (!this.textFillState_) {
this.textFillState_ = {