Merge pull request #1681 from twpayne/line-dash
Fix management of line dash state
This commit is contained in:
@@ -73,6 +73,14 @@ ol.IS_LEGACY_IE = goog.userAgent.IE &&
|
|||||||
ol.BrowserFeature.DEVICE_PIXEL_RATIO = goog.global.devicePixelRatio || 1;
|
ol.BrowserFeature.DEVICE_PIXEL_RATIO = goog.global.devicePixelRatio || 1;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True if the browser's Canvas implementation implements {get,set}LineDash.
|
||||||
|
* @type {boolean}
|
||||||
|
* @todo stability experimental
|
||||||
|
*/
|
||||||
|
ol.BrowserFeature.HAS_CANVAS_LINE_DASH = false;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True if browser supports Canvas.
|
* True if browser supports Canvas.
|
||||||
* @const
|
* @const
|
||||||
@@ -90,7 +98,16 @@ ol.BrowserFeature.HAS_CANVAS = ol.ENABLE_CANVAS && (
|
|||||||
try {
|
try {
|
||||||
var canvas = /** @type {HTMLCanvasElement} */
|
var canvas = /** @type {HTMLCanvasElement} */
|
||||||
(goog.dom.createElement(goog.dom.TagName.CANVAS));
|
(goog.dom.createElement(goog.dom.TagName.CANVAS));
|
||||||
return !goog.isNull(canvas.getContext('2d'));
|
var context = /** @type {CanvasRenderingContext2D} */
|
||||||
|
(canvas.getContext('2d'));
|
||||||
|
if (goog.isNull(context)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
if (goog.isDef(context.setLineDash)) {
|
||||||
|
ol.BrowserFeature.HAS_CANVAS_LINE_DASH = true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ goog.require('goog.array');
|
|||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
goog.require('goog.object');
|
goog.require('goog.object');
|
||||||
goog.require('goog.vec.Mat4');
|
goog.require('goog.vec.Mat4');
|
||||||
|
goog.require('ol.BrowserFeature');
|
||||||
goog.require('ol.color');
|
goog.require('ol.color');
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.geom.flat');
|
goog.require('ol.geom.flat');
|
||||||
@@ -638,7 +639,9 @@ ol.render.canvas.Immediate.prototype.setContextStrokeState_ =
|
|||||||
var contextStrokeState = this.contextStrokeState_;
|
var contextStrokeState = this.contextStrokeState_;
|
||||||
if (goog.isNull(contextStrokeState)) {
|
if (goog.isNull(contextStrokeState)) {
|
||||||
context.lineCap = strokeState.lineCap;
|
context.lineCap = strokeState.lineCap;
|
||||||
context.lineDash = strokeState.lineDash;
|
if (ol.BrowserFeature.HAS_CANVAS_LINE_DASH) {
|
||||||
|
context.setLineDash(strokeState.lineDash);
|
||||||
|
}
|
||||||
context.lineJoin = strokeState.lineJoin;
|
context.lineJoin = strokeState.lineJoin;
|
||||||
context.lineWidth = strokeState.lineWidth;
|
context.lineWidth = strokeState.lineWidth;
|
||||||
context.miterLimit = strokeState.miterLimit;
|
context.miterLimit = strokeState.miterLimit;
|
||||||
@@ -655,8 +658,11 @@ ol.render.canvas.Immediate.prototype.setContextStrokeState_ =
|
|||||||
if (contextStrokeState.lineCap != strokeState.lineCap) {
|
if (contextStrokeState.lineCap != strokeState.lineCap) {
|
||||||
contextStrokeState.lineCap = context.lineCap = strokeState.lineCap;
|
contextStrokeState.lineCap = context.lineCap = strokeState.lineCap;
|
||||||
}
|
}
|
||||||
if (contextStrokeState.lineDash != strokeState.lineDash) {
|
if (ol.BrowserFeature.HAS_CANVAS_LINE_DASH) {
|
||||||
contextStrokeState.lineDash = context.lineDash = strokeState.lineDash;
|
if (!goog.array.equals(
|
||||||
|
contextStrokeState.lineDash, strokeState.lineDash)) {
|
||||||
|
context.setLineDash(contextStrokeState.lineDash = strokeState.lineDash);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (contextStrokeState.lineJoin != strokeState.lineJoin) {
|
if (contextStrokeState.lineJoin != strokeState.lineJoin) {
|
||||||
contextStrokeState.lineJoin = context.lineJoin = strokeState.lineJoin;
|
contextStrokeState.lineJoin = context.lineJoin = strokeState.lineJoin;
|
||||||
@@ -734,7 +740,7 @@ ol.render.canvas.Immediate.prototype.setFillStrokeStyle =
|
|||||||
this.strokeState_ = {
|
this.strokeState_ = {
|
||||||
lineCap: goog.isDef(strokeStyleLineCap) ?
|
lineCap: goog.isDef(strokeStyleLineCap) ?
|
||||||
strokeStyleLineCap : ol.render.canvas.defaultLineCap,
|
strokeStyleLineCap : ol.render.canvas.defaultLineCap,
|
||||||
lineDash: goog.isDef(strokeStyleLineDash) ?
|
lineDash: goog.isDefAndNotNull(strokeStyleLineDash) ?
|
||||||
strokeStyleLineDash : ol.render.canvas.defaultLineDash,
|
strokeStyleLineDash : ol.render.canvas.defaultLineDash,
|
||||||
lineJoin: goog.isDef(strokeStyleLineJoin) ?
|
lineJoin: goog.isDef(strokeStyleLineJoin) ?
|
||||||
strokeStyleLineJoin : ol.render.canvas.defaultLineJoin,
|
strokeStyleLineJoin : ol.render.canvas.defaultLineJoin,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ goog.require('goog.dom');
|
|||||||
goog.require('goog.dom.TagName');
|
goog.require('goog.dom.TagName');
|
||||||
goog.require('goog.object');
|
goog.require('goog.object');
|
||||||
goog.require('goog.vec.Mat4');
|
goog.require('goog.vec.Mat4');
|
||||||
|
goog.require('ol.BrowserFeature');
|
||||||
goog.require('ol.array');
|
goog.require('ol.array');
|
||||||
goog.require('ol.color');
|
goog.require('ol.color');
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
@@ -344,7 +345,7 @@ ol.render.canvas.Replay.prototype.replay_ =
|
|||||||
context.lineCap = /** @type {string} */ (instruction[3]);
|
context.lineCap = /** @type {string} */ (instruction[3]);
|
||||||
context.lineJoin = /** @type {string} */ (instruction[4]);
|
context.lineJoin = /** @type {string} */ (instruction[4]);
|
||||||
context.miterLimit = /** @type {number} */ (instruction[5]);
|
context.miterLimit = /** @type {number} */ (instruction[5]);
|
||||||
if (goog.isDef(context.setLineDash)) {
|
if (ol.BrowserFeature.HAS_CANVAS_LINE_DASH) {
|
||||||
context.setLineDash(/** @type {Array.<number>} */ (instruction[6]));
|
context.setLineDash(/** @type {Array.<number>} */ (instruction[6]));
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
@@ -850,7 +851,7 @@ ol.render.canvas.LineStringReplay.prototype.setStrokeStyle_ = function() {
|
|||||||
goog.asserts.assert(goog.isDef(miterLimit));
|
goog.asserts.assert(goog.isDef(miterLimit));
|
||||||
if (state.currentStrokeStyle != strokeStyle ||
|
if (state.currentStrokeStyle != strokeStyle ||
|
||||||
state.currentLineCap != lineCap ||
|
state.currentLineCap != lineCap ||
|
||||||
state.currentLineDash != lineDash ||
|
!goog.array.equals(state.currentLineDash, lineDash) ||
|
||||||
state.currentLineJoin != lineJoin ||
|
state.currentLineJoin != lineJoin ||
|
||||||
state.currentLineWidth != lineWidth ||
|
state.currentLineWidth != lineWidth ||
|
||||||
state.currentMiterLimit != miterLimit) {
|
state.currentMiterLimit != miterLimit) {
|
||||||
@@ -1248,7 +1249,7 @@ ol.render.canvas.PolygonReplay.prototype.setFillStrokeStyle =
|
|||||||
strokeStyleLineCap : ol.render.canvas.defaultLineCap;
|
strokeStyleLineCap : ol.render.canvas.defaultLineCap;
|
||||||
var strokeStyleLineDash = strokeStyle.getLineDash();
|
var strokeStyleLineDash = strokeStyle.getLineDash();
|
||||||
state.lineDash = !goog.isNull(strokeStyleLineDash) ?
|
state.lineDash = !goog.isNull(strokeStyleLineDash) ?
|
||||||
strokeStyleLineDash : ol.render.canvas.defaultLineDash;
|
strokeStyleLineDash.slice() : ol.render.canvas.defaultLineDash;
|
||||||
var strokeStyleLineJoin = strokeStyle.getLineJoin();
|
var strokeStyleLineJoin = strokeStyle.getLineJoin();
|
||||||
state.lineJoin = goog.isDef(strokeStyleLineJoin) ?
|
state.lineJoin = goog.isDef(strokeStyleLineJoin) ?
|
||||||
strokeStyleLineJoin : ol.render.canvas.defaultLineJoin;
|
strokeStyleLineJoin : ol.render.canvas.defaultLineJoin;
|
||||||
@@ -1552,7 +1553,7 @@ ol.render.canvas.TextReplay.prototype.setTextStyle = function(textStyle) {
|
|||||||
var lineCap = goog.isDef(textStrokeStyleLineCap) ?
|
var lineCap = goog.isDef(textStrokeStyleLineCap) ?
|
||||||
textStrokeStyleLineCap : ol.render.canvas.defaultLineCap;
|
textStrokeStyleLineCap : ol.render.canvas.defaultLineCap;
|
||||||
var lineDash = goog.isDefAndNotNull(textStrokeStyleLineDash) ?
|
var lineDash = goog.isDefAndNotNull(textStrokeStyleLineDash) ?
|
||||||
textStrokeStyleLineDash : ol.render.canvas.defaultLineDash;
|
textStrokeStyleLineDash.slice() : ol.render.canvas.defaultLineDash;
|
||||||
var lineJoin = goog.isDef(textStrokeStyleLineJoin) ?
|
var lineJoin = goog.isDef(textStrokeStyleLineJoin) ?
|
||||||
textStrokeStyleLineJoin : ol.render.canvas.defaultLineJoin;
|
textStrokeStyleLineJoin : ol.render.canvas.defaultLineJoin;
|
||||||
var lineWidth = goog.isDef(textStrokeStyleWidth) ?
|
var lineWidth = goog.isDef(textStrokeStyleWidth) ?
|
||||||
|
|||||||
Reference in New Issue
Block a user