From 719abf726500dcdfe521477d89d07f373b29b55e Mon Sep 17 00:00:00 2001 From: gkresic Date: Mon, 24 Jul 2017 12:34:53 +0200 Subject: [PATCH] Support for lineDashOffset --- src/ol/render/canvas/immediate.js | 6 ++++++ src/ol/style/regularshape.js | 6 ++++++ src/ol/typedefs.js | 1 + 3 files changed, 13 insertions(+) diff --git a/src/ol/render/canvas/immediate.js b/src/ol/render/canvas/immediate.js index bcf72367f7..a54503a9a6 100644 --- a/src/ol/render/canvas/immediate.js +++ b/src/ol/render/canvas/immediate.js @@ -735,6 +735,7 @@ ol.render.canvas.Immediate.prototype.setContextStrokeState_ = function(strokeSta context.lineCap = strokeState.lineCap; if (ol.has.CANVAS_LINE_DASH) { context.setLineDash(strokeState.lineDash); + context.lineDashOffset = strokeState.lineDashOffset; } context.lineJoin = strokeState.lineJoin; context.lineWidth = strokeState.lineWidth; @@ -743,6 +744,7 @@ ol.render.canvas.Immediate.prototype.setContextStrokeState_ = function(strokeSta this.contextStrokeState_ = { lineCap: strokeState.lineCap, lineDash: strokeState.lineDash, + lineDashOffset: strokeState.lineDashOffset, lineJoin: strokeState.lineJoin, lineWidth: strokeState.lineWidth, miterLimit: strokeState.miterLimit, @@ -757,6 +759,10 @@ ol.render.canvas.Immediate.prototype.setContextStrokeState_ = function(strokeSta contextStrokeState.lineDash, strokeState.lineDash)) { context.setLineDash(contextStrokeState.lineDash = strokeState.lineDash); } + if (contextStrokeState.lineDashOffset != strokeState.lineDashOffset) { + contextStrokeState.lineDashOffset = context.lineDashOffset = + strokeState.lineDashOffset; + } } if (contextStrokeState.lineJoin != strokeState.lineJoin) { contextStrokeState.lineJoin = context.lineJoin = strokeState.lineJoin; diff --git a/src/ol/style/regularshape.js b/src/ol/style/regularshape.js index 4a992a4daa..08f0a80e36 100644 --- a/src/ol/style/regularshape.js +++ b/src/ol/style/regularshape.js @@ -317,6 +317,7 @@ ol.style.RegularShape.prototype.render_ = function(atlasManager) { var lineJoin = ''; var miterLimit = 0; var lineDash = null; + var lineDashOffset = 0; var strokeStyle; var strokeWidth = 0; @@ -331,8 +332,10 @@ ol.style.RegularShape.prototype.render_ = function(atlasManager) { strokeWidth = ol.render.canvas.defaultLineWidth; } lineDash = this.stroke_.getLineDash(); + lineDashOffset = this.stroke_.getLineDashOffset(); if (!ol.has.CANVAS_LINE_DASH) { lineDash = null; + lineDashOffset = 0; } lineJoin = this.stroke_.getLineJoin(); if (lineJoin === undefined) { @@ -357,6 +360,7 @@ ol.style.RegularShape.prototype.render_ = function(atlasManager) { size: size, lineCap: lineCap, lineDash: lineDash, + lineDashOffset: lineDashOffset, lineJoin: lineJoin, miterLimit: miterLimit }; @@ -460,6 +464,7 @@ ol.style.RegularShape.prototype.draw_ = function(renderOptions, context, x, y) { context.lineWidth = renderOptions.strokeWidth; if (renderOptions.lineDash) { context.setLineDash(renderOptions.lineDash); + context.lineDashOffset = renderOptions.lineDashOffset; } context.lineCap = renderOptions.lineCap; context.lineJoin = renderOptions.lineJoin; @@ -533,6 +538,7 @@ ol.style.RegularShape.prototype.drawHitDetectionCanvas_ = function(renderOptions context.lineWidth = renderOptions.strokeWidth; if (renderOptions.lineDash) { context.setLineDash(renderOptions.lineDash); + context.lineDashOffset = renderOptions.lineDashOffset; } context.stroke(); } diff --git a/src/ol/typedefs.js b/src/ol/typedefs.js index 8581394c33..d9300c5912 100644 --- a/src/ol/typedefs.js +++ b/src/ol/typedefs.js @@ -79,6 +79,7 @@ ol.CanvasFunctionType; /** * @typedef {{lineCap: string, * lineDash: Array., + * lineDashOffset: number, * lineJoin: string, * lineWidth: number, * miterLimit: number,