diff --git a/src/ol/render/canvas/PolygonReplay.js b/src/ol/render/canvas/PolygonReplay.js index 7029fddd81..a1ee906790 100644 --- a/src/ol/render/canvas/PolygonReplay.js +++ b/src/ol/render/canvas/PolygonReplay.js @@ -216,7 +216,7 @@ _ol_render_canvas_PolygonReplay_.prototype.setFillStrokeStyles_ = function(geome var state = this.state; var fillStyle = state.fillStyle; if (fillStyle !== undefined) { - this.updateFillStyle(state, this.applyFill, geometry); + this.updateFillStyle(state, this.createFill, geometry); } if (state.strokeStyle !== undefined) { this.updateStrokeStyle(state, this.applyStroke); diff --git a/src/ol/render/canvas/Replay.js b/src/ol/render/canvas/Replay.js index c83fe1fea3..9a3c595aae 100644 --- a/src/ol/render/canvas/Replay.js +++ b/src/ol/render/canvas/Replay.js @@ -960,15 +960,16 @@ _ol_render_canvas_Replay_.prototype.setFillStrokeStyle = function(fillStyle, str /** * @param {ol.CanvasFillStrokeState} state State. * @param {ol.geom.Geometry|ol.render.Feature} geometry Geometry. + * @return {Array.<*>} Fill instruction. */ -_ol_render_canvas_Replay_.prototype.applyFill = function(state, geometry) { +_ol_render_canvas_Replay_.prototype.createFill = function(state, geometry) { var fillStyle = state.fillStyle; var fillInstruction = [_ol_render_canvas_Instruction_.SET_FILL_STYLE, fillStyle]; if (typeof fillStyle !== 'string') { var fillExtent = geometry.getExtent(); fillInstruction.push([fillExtent[0], fillExtent[3]]); } - this.instructions.push(fillInstruction); + return fillInstruction; }; @@ -976,25 +977,34 @@ _ol_render_canvas_Replay_.prototype.applyFill = function(state, geometry) { * @param {ol.CanvasFillStrokeState} state State. */ _ol_render_canvas_Replay_.prototype.applyStroke = function(state) { - this.instructions.push([ - _ol_render_canvas_Instruction_.SET_STROKE_STYLE, - state.strokeStyle, state.lineWidth * this.pixelRatio, state.lineCap, - state.lineJoin, state.miterLimit, - this.applyPixelRatio(state.lineDash), state.lineDashOffset * this.pixelRatio - ]); + this.instructions.push(this.createStroke(state)); }; /** * @param {ol.CanvasFillStrokeState} state State. - * @param {function(this:ol.render.canvas.Replay, ol.CanvasFillStrokeState, (ol.geom.Geometry|ol.render.Feature))} applyFill Apply fill. + * @return {Array.<*>} Stroke instruction. + */ +_ol_render_canvas_Replay_.prototype.createStroke = function(state) { + return [ + _ol_render_canvas_Instruction_.SET_STROKE_STYLE, + state.strokeStyle, state.lineWidth * this.pixelRatio, state.lineCap, + state.lineJoin, state.miterLimit, + this.applyPixelRatio(state.lineDash), state.lineDashOffset * this.pixelRatio + ]; +}; + + +/** + * @param {ol.CanvasFillStrokeState} state State. + * @param {function(this:ol.render.canvas.Replay, ol.CanvasFillStrokeState, (ol.geom.Geometry|ol.render.Feature)):Array.<*>} createFill Create fill. * @param {ol.geom.Geometry|ol.render.Feature} geometry Geometry. */ -_ol_render_canvas_Replay_.prototype.updateFillStyle = function(state, applyFill, geometry) { +_ol_render_canvas_Replay_.prototype.updateFillStyle = function(state, createFill, geometry) { var fillStyle = state.fillStyle; if (typeof fillStyle !== 'string' || state.currentFillStyle != fillStyle) { if (fillStyle !== undefined) { - applyFill.call(this, state, geometry); + this.instructions.push(createFill.call(this, state, geometry)); } state.currentFillStyle = fillStyle; } diff --git a/src/ol/render/canvas/TextReplay.js b/src/ol/render/canvas/TextReplay.js index 75d2673114..ef4d2e286d 100644 --- a/src/ol/render/canvas/TextReplay.js +++ b/src/ol/render/canvas/TextReplay.js @@ -264,8 +264,10 @@ _ol_render_canvas_TextReplay_.prototype.drawText = function(geometry, feature) { this.beginGeometry(geometry, feature); if (textState.backgroundFill || textState.backgroundStroke) { this.setFillStrokeStyle(textState.backgroundFill, textState.backgroundStroke); - this.updateFillStyle(this.state, this.applyFill, geometry); + this.updateFillStyle(this.state, this.createFill, geometry); + this.hitDetectionInstructions.push(this.createFill(this.state, geometry)); this.updateStrokeStyle(this.state, this.applyStroke); + this.hitDetectionInstructions.push(this.createStroke(this.state)); } this.drawTextImage_(label, begin, end); this.endGeometry(geometry, feature);