Store raw style values for PolygonReplay

This commit is contained in:
Éric Lemoine
2013-11-21 10:39:15 +01:00
parent 0ccd1ef217
commit 5493543c1f
+56 -30
View File
@@ -12,8 +12,6 @@ goog.require('ol.extent');
goog.require('ol.geom.flat'); goog.require('ol.geom.flat');
goog.require('ol.render.IRender'); goog.require('ol.render.IRender');
goog.require('ol.render.IReplayGroup'); goog.require('ol.render.IReplayGroup');
goog.require('ol.style.Fill');
goog.require('ol.style.Stroke');
goog.require('ol.vec.Mat4'); goog.require('ol.vec.Mat4');
@@ -152,9 +150,8 @@ ol.render.canvas.Replay.prototype.draw = function(context, transform) {
} }
++i; ++i;
} else if (type == ol.render.canvas.Instruction.SET_FILL_STYLE) { } else if (type == ol.render.canvas.Instruction.SET_FILL_STYLE) {
goog.asserts.assert(goog.isObject(instruction[1])); goog.asserts.assert(goog.isString(instruction[1]));
var fillStyle = /** @type {ol.style.Fill} */ (instruction[1]); context.fillStyle = /** @type {string} */ (instruction[1]);
context.fillStyle = ol.color.asString(fillStyle.color);
++i; ++i;
} else if (type == ol.render.canvas.Instruction.SET_STROKE_STYLE) { } else if (type == ol.render.canvas.Instruction.SET_STROKE_STYLE) {
goog.asserts.assert(goog.isString(instruction[1])); goog.asserts.assert(goog.isString(instruction[1]));
@@ -491,16 +488,20 @@ ol.render.canvas.PolygonReplay = function() {
/** /**
* @private * @private
* @type {{currentFillStyle: ol.style.Fill, * @type {{currentFillColor: (string|undefined),
* currentStrokeStyle: ol.style.Stroke, * currentStrokeStyle: (string|undefined),
* fillStyle: ol.style.Fill, * currentLineWidth: (number|undefined),
* strokeStyle: ol.style.Stroke}|null} * fillStyle: (string|undefined),
* strokeStyle: (string|undefined),
* lineWidth: (number|undefined)}|null}
*/ */
this.state_ = { this.state_ = {
currentFillStyle: null, currentFillColor: undefined,
currentStrokeStyle: null, currentStrokeStyle: undefined,
fillStyle: null, currentLineWidth: undefined,
strokeStyle: null fillStyle: undefined,
strokeStyle: undefined,
lineWidth: undefined
}; };
}; };
@@ -531,10 +532,11 @@ ol.render.canvas.PolygonReplay.prototype.drawFlatCoordinatess_ =
} }
// FIXME is it quicker to fill and stroke each polygon individually, // FIXME is it quicker to fill and stroke each polygon individually,
// FIXME or all polygons together? // FIXME or all polygons together?
if (goog.isDefAndNotNull(state.fillStyle)) { if (goog.isDef(state.fillStyle)) {
this.instructions.push([ol.render.canvas.Instruction.FILL]); this.instructions.push([ol.render.canvas.Instruction.FILL]);
} }
if (goog.isDefAndNotNull(state.strokeStyle)) { if (goog.isDef(state.strokeStyle)) {
goog.asserts.assert(goog.isDef(state.lineWidth));
this.instructions.push([ol.render.canvas.Instruction.STROKE]); this.instructions.push([ol.render.canvas.Instruction.STROKE]);
} }
return offset; return offset;
@@ -548,10 +550,14 @@ ol.render.canvas.PolygonReplay.prototype.drawPolygonGeometry =
function(polygonGeometry) { function(polygonGeometry) {
var state = this.state_; var state = this.state_;
goog.asserts.assert(!goog.isNull(state)); goog.asserts.assert(!goog.isNull(state));
if (!goog.isDefAndNotNull(state.fillStyle) && var fillStyle = state.fillStyle;
!goog.isDefAndNotNull(state.strokeStyle)) { var strokeStyle = state.strokeStyle;
if (!goog.isDef(fillStyle) && !goog.isDef(strokeStyle)) {
return; return;
} }
if (goog.isDef(strokeStyle)) {
goog.asserts.assert(goog.isDef(state.lineWidth));
}
ol.extent.extend(this.extent_, polygonGeometry.getExtent()); ol.extent.extend(this.extent_, polygonGeometry.getExtent());
this.setFillStrokeStyles_(); this.setFillStrokeStyles_();
var ends = polygonGeometry.getEnds(); var ends = polygonGeometry.getEnds();
@@ -568,10 +574,14 @@ ol.render.canvas.PolygonReplay.prototype.drawMultiPolygonGeometry =
function(multiPolygonGeometry) { function(multiPolygonGeometry) {
var state = this.state_; var state = this.state_;
goog.asserts.assert(!goog.isNull(state)); goog.asserts.assert(!goog.isNull(state));
if (!goog.isDefAndNotNull(state.fillStyle) && var fillStyle = state.fillStyle;
!goog.isDefAndNotNull(state.strokeStyle)) { var strokeStyle = state.strokeStyle;
if (!goog.isDef(fillStyle) && !goog.isDef(strokeStyle)) {
return; return;
} }
if (goog.isDef(strokeStyle)) {
goog.asserts.assert(goog.isDef(state.lineWidth));
}
ol.extent.extend(this.extent_, multiPolygonGeometry.getExtent()); ol.extent.extend(this.extent_, multiPolygonGeometry.getExtent());
this.setFillStrokeStyles_(); this.setFillStrokeStyles_();
var endss = multiPolygonGeometry.getEndss(); var endss = multiPolygonGeometry.getEndss();
@@ -601,8 +611,17 @@ ol.render.canvas.PolygonReplay.prototype.finish = function() {
ol.render.canvas.PolygonReplay.prototype.setFillStrokeStyle = ol.render.canvas.PolygonReplay.prototype.setFillStrokeStyle =
function(fillStyle, strokeStyle) { function(fillStyle, strokeStyle) {
goog.asserts.assert(!goog.isNull(this.state_)); goog.asserts.assert(!goog.isNull(this.state_));
this.state_.fillStyle = fillStyle; goog.asserts.assert(!goog.isNull(fillStyle) || !goog.isNull(strokeStyle));
this.state_.strokeStyle = strokeStyle; if (!goog.isNull(fillStyle)) {
goog.asserts.assert(goog.isDefAndNotNull(fillStyle.color));
this.state_.fillStyle = ol.color.asString(fillStyle.color);
}
if (!goog.isNull(strokeStyle)) {
goog.asserts.assert(goog.isDefAndNotNull(strokeStyle.color));
goog.asserts.assert(goog.isDef(strokeStyle.width));
this.state_.strokeStyle = ol.color.asString(strokeStyle.color);
this.state_.lineWidth = strokeStyle.width;
}
}; };
@@ -611,17 +630,24 @@ ol.render.canvas.PolygonReplay.prototype.setFillStrokeStyle =
*/ */
ol.render.canvas.PolygonReplay.prototype.setFillStrokeStyles_ = function() { ol.render.canvas.PolygonReplay.prototype.setFillStrokeStyles_ = function() {
var state = this.state_; var state = this.state_;
if (goog.isDefAndNotNull(state.fillStyle) && var fillStyle = state.fillStyle;
!ol.style.Fill.equals(state.currentFillStyle, state.fillStyle)) { var strokeStyle = state.strokeStyle;
var lineWidth = state.lineWidth;
if (goog.isDef(fillStyle) && state.currentFillColor != fillStyle) {
this.instructions.push( this.instructions.push(
[ol.render.canvas.Instruction.SET_FILL_STYLE, state.fillStyle]); [ol.render.canvas.Instruction.SET_FILL_STYLE, fillStyle]);
state.currentFillStyle = state.fillStyle; state.currentFillColor = state.fillStyle;
} }
if (goog.isDefAndNotNull(state.strokeStyle) && if (goog.isDef(strokeStyle)) {
!ol.style.Stroke.equals(state.currentStrokeStyle, state.strokeStyle)) { goog.asserts.assert(goog.isDef(lineWidth));
this.instructions.push( if (state.currentStrokeStyle != strokeStyle ||
[ol.render.canvas.Instruction.SET_STROKE_STYLE, state.strokeStyle]); state.currentLineWidth != lineWidth) {
state.currentStrokeStyle = state.strokeStyle; this.instructions.push(
[ol.render.canvas.Instruction.SET_STROKE_STYLE,
strokeStyle, lineWidth]);
state.currentStrokeStyle = strokeStyle;
state.currentLineWidth = lineWidth;
}
} }
}; };