From f9282c90e47c2060d3823af2d31ffd5b70075b22 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Tue, 12 Nov 2013 22:40:57 +0100 Subject: [PATCH] Make instructions responsible for incrementing the instruction index This paves the way for skipping features (where both the instruction and data indexes will need to be advanced). --- src/ol/render/canvas/canvasreplay.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/ol/render/canvas/canvasreplay.js b/src/ol/render/canvas/canvasreplay.js index 381cf1397a..53a756ecf3 100644 --- a/src/ol/render/canvas/canvasreplay.js +++ b/src/ol/render/canvas/canvasreplay.js @@ -102,13 +102,15 @@ ol.render.canvas.Replay.prototype.draw = function(context, transform) { var ii = instructions.length; // end of instructions var d = 0; // data index var dd; // end of per-instruction data - for (; i < ii; ++i) { + while (i < ii) { var instruction = instructions[i]; var type = /** @type {ol.render.canvas.Instruction} */ (instruction[0]); if (type == ol.render.canvas.Instruction.BEGIN_PATH) { context.beginPath(); + ++i; } else if (type == ol.render.canvas.Instruction.CLOSE_PATH) { context.closePath(); + ++i; } else if (type == ol.render.canvas.Instruction.DRAW_IMAGE) { dd = /** @type {number} */ (instruction[1]); var imageStyle = /** @type {ol.style.Image} */ (instruction[2]); @@ -121,8 +123,10 @@ ol.render.canvas.Replay.prototype.draw = function(context, transform) { } context.drawImage(imageStyle.image, x, y); } + ++i; } else if (type == ol.render.canvas.Instruction.FILL) { context.fill(); + ++i; } else if (type == ol.render.canvas.Instruction.MOVE_TO_LINE_TO) { context.moveTo(pixelCoordinates[d], pixelCoordinates[d + 1]); goog.asserts.assert(goog.isNumber(instruction[1])); @@ -130,17 +134,24 @@ ol.render.canvas.Replay.prototype.draw = function(context, transform) { for (d += 2; d < dd; d += 2) { context.lineTo(pixelCoordinates[d], pixelCoordinates[d + 1]); } + ++i; } else if (type == ol.render.canvas.Instruction.SET_FILL_STYLE) { goog.asserts.assert(goog.isObject(instruction[1])); var fillStyle = /** @type {ol.style.Fill} */ (instruction[1]); context.fillStyle = fillStyle.color; + ++i; } else if (type == ol.render.canvas.Instruction.SET_STROKE_STYLE) { goog.asserts.assert(goog.isObject(instruction[1])); var strokeStyle = /** @type {ol.style.Stroke} */ (instruction[1]); context.strokeStyle = strokeStyle.color; context.lineWidth = strokeStyle.width; + ++i; } else if (type == ol.render.canvas.Instruction.STROKE) { context.stroke(); + ++i; + } else { + goog.asserts.fail(); + ++i; // consume the instruction anyway, to avoid an infite loop } } // assert that all data were consumed