Add miterLimit property to ol.style.Stroke

This commit is contained in:
Frederic Junod
2013-11-28 11:49:56 +01:00
parent 0bd77d3caf
commit bf9cd0a675
5 changed files with 54 additions and 8 deletions

View File

@@ -648,6 +648,7 @@
* @property {ol.Color|string|undefined} color Color. * @property {ol.Color|string|undefined} color Color.
* @property {string|undefined} lineCap Line cap style: `butt`, `round`, or `square`. Default is `butt`. * @property {string|undefined} lineCap Line cap style: `butt`, `round`, or `square`. Default is `butt`.
* @property {string|undefined} lineJoin Line join style: `bevel`, `round`, or `miter`. Default is `miter`. * @property {string|undefined} lineJoin Line join style: `bevel`, `round`, or `miter`. Default is `miter`.
* @property {number|undefined} miterLimit Miter limit. Default is `10`.
* @property {number|undefined} width Width. * @property {number|undefined} width Width.
* @todo stability experimental * @todo stability experimental
*/ */

View File

@@ -21,6 +21,12 @@ ol.render.canvas.defaultLineCap = 'butt';
ol.render.canvas.defaultLineJoin = 'miter'; ol.render.canvas.defaultLineJoin = 'miter';
/**
* @const {number}
*/
ol.render.canvas.defaultMiterLimit = 10;
/** /**
* @const {ol.Color} * @const {ol.Color}
*/ */

View File

@@ -47,6 +47,7 @@ ol.render.canvas.Immediate = function(context, extent, transform) {
* currentLineCap: (string|undefined), * currentLineCap: (string|undefined),
* currentLineJoin: (string|undefined), * currentLineJoin: (string|undefined),
* currentLineWidth: (number|undefined), * currentLineWidth: (number|undefined),
* currentMiterLimit: (number|undefined),
* fillStyle: (string|undefined), * fillStyle: (string|undefined),
* strokeStyle: (string|undefined), * strokeStyle: (string|undefined),
* lineWidth: (number|undefined), * lineWidth: (number|undefined),
@@ -57,6 +58,7 @@ ol.render.canvas.Immediate = function(context, extent, transform) {
* width: (number|undefined), * width: (number|undefined),
* lineCap: (string|undefined), * lineCap: (string|undefined),
* lineJoin: (string|undefined), * lineJoin: (string|undefined),
* miterLimit: (number|undefined),
* snapToPixel: (boolean|undefined), * snapToPixel: (boolean|undefined),
* textStyle: ol.style.Text}} * textStyle: ol.style.Text}}
*/ */
@@ -66,6 +68,7 @@ ol.render.canvas.Immediate = function(context, extent, transform) {
currentLineCap: undefined, currentLineCap: undefined,
currentLineJoin: undefined, currentLineJoin: undefined,
currentLineWidth: undefined, currentLineWidth: undefined,
currentMiterLimit: undefined,
fillStyle: undefined, fillStyle: undefined,
strokeStyle: undefined, strokeStyle: undefined,
lineWidth: undefined, lineWidth: undefined,
@@ -76,6 +79,7 @@ ol.render.canvas.Immediate = function(context, extent, transform) {
width: undefined, width: undefined,
lineCap: undefined, lineCap: undefined,
lineJoin: undefined, lineJoin: undefined,
miterLimit: undefined,
snapToPixel: undefined, snapToPixel: undefined,
textStyle: null textStyle: null
}; };
@@ -359,11 +363,14 @@ ol.render.canvas.Immediate.prototype.setFillStrokeStyle =
strokeStyle.lineJoin : ol.render.canvas.defaultLineJoin; strokeStyle.lineJoin : ol.render.canvas.defaultLineJoin;
state.lineWidth = goog.isDef(strokeStyle.width) ? state.lineWidth = goog.isDef(strokeStyle.width) ?
strokeStyle.width : ol.render.canvas.defaultLineWidth; strokeStyle.width : ol.render.canvas.defaultLineWidth;
state.miterLimit = goog.isDef(strokeStyle.miterLimit) ?
strokeStyle.miterLimit : ol.render.canvas.defaultMiterLimit;
} else { } else {
state.strokeStyle = undefined; state.strokeStyle = undefined;
state.lineCap = undefined; state.lineCap = undefined;
state.lineJoin = undefined; state.lineJoin = undefined;
state.lineWidth = undefined; state.lineWidth = undefined;
state.miterLimit = undefined;
} }
}; };
@@ -379,6 +386,7 @@ ol.render.canvas.Immediate.prototype.setFillStrokeStyles_ = function() {
var lineCap = state.lineCap; var lineCap = state.lineCap;
var lineJoin = state.lineJoin; var lineJoin = state.lineJoin;
var lineWidth = state.lineWidth; var lineWidth = state.lineWidth;
var miterLimit = state.miterLimit;
if (goog.isDef(fillStyle) && state.currentFillStyle != fillStyle) { if (goog.isDef(fillStyle) && state.currentFillStyle != fillStyle) {
context.fillStyle = fillStyle; context.fillStyle = fillStyle;
state.currentFillStyle = fillStyle; state.currentFillStyle = fillStyle;
@@ -387,13 +395,16 @@ ol.render.canvas.Immediate.prototype.setFillStrokeStyles_ = function() {
goog.asserts.assert(goog.isDef(lineWidth)); goog.asserts.assert(goog.isDef(lineWidth));
goog.asserts.assert(goog.isDef(lineCap)); goog.asserts.assert(goog.isDef(lineCap));
goog.asserts.assert(goog.isDef(lineJoin)); goog.asserts.assert(goog.isDef(lineJoin));
goog.asserts.assert(goog.isDef(miterLimit));
if (state.currentStrokeStyle != strokeStyle || if (state.currentStrokeStyle != strokeStyle ||
state.currentLineCap != lineCap || state.currentLineCap != lineCap ||
state.currentLineJoin != lineJoin || state.currentLineJoin != lineJoin ||
state.currentMiterLimit != miterLimit ||
state.currentLineWidth != lineWidth) { state.currentLineWidth != lineWidth) {
context.strokeStyle = strokeStyle; context.strokeStyle = strokeStyle;
context.lineCap = lineCap; context.lineCap = lineCap;
context.lineJoin = lineJoin; context.lineJoin = lineJoin;
context.miterLimit = miterLimit;
context.lineWidth = lineWidth; context.lineWidth = lineWidth;
} }
} }

View File

@@ -191,10 +191,12 @@ ol.render.canvas.Replay.prototype.replay =
goog.asserts.assert(goog.isNumber(instruction[2])); goog.asserts.assert(goog.isNumber(instruction[2]));
goog.asserts.assert(goog.isString(instruction[3])); goog.asserts.assert(goog.isString(instruction[3]));
goog.asserts.assert(goog.isString(instruction[4])); goog.asserts.assert(goog.isString(instruction[4]));
goog.asserts.assert(goog.isNumber(instruction[5]));
context.strokeStyle = /** @type {string} */ (instruction[1]); context.strokeStyle = /** @type {string} */ (instruction[1]);
context.lineWidth = /** @type {number} */ (instruction[2]); context.lineWidth = /** @type {number} */ (instruction[2]);
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]);
++i; ++i;
} else if (type == ol.render.canvas.Instruction.STROKE) { } else if (type == ol.render.canvas.Instruction.STROKE) {
context.stroke(); context.stroke();
@@ -463,22 +465,26 @@ ol.render.canvas.LineStringReplay = function() {
* currentLineCap: (string|undefined), * currentLineCap: (string|undefined),
* currentLineJoin: (string|undefined), * currentLineJoin: (string|undefined),
* currentLineWidth: (number|undefined), * currentLineWidth: (number|undefined),
* currentMiterLimit: (number|undefined),
* lastStroke: number, * lastStroke: number,
* strokeStyle: (string|undefined), * strokeStyle: (string|undefined),
* lineCap: (string|undefined), * lineCap: (string|undefined),
* lineJoin: (string|undefined), * lineJoin: (string|undefined),
* lineWidth: (number|undefined)}|null} * lineWidth: (number|undefined),
* miterLimit: (number|undefined)}|null}
*/ */
this.state_ = { this.state_ = {
currentStrokeStyle: undefined, currentStrokeStyle: undefined,
currentLineCap: undefined, currentLineCap: undefined,
currentLineJoin: undefined, currentLineJoin: undefined,
currentLineWidth: undefined, currentLineWidth: undefined,
currentMiterLimit: undefined,
lastStroke: 0, lastStroke: 0,
strokeStyle: undefined, strokeStyle: undefined,
lineCap: undefined, lineCap: undefined,
lineJoin: undefined, lineJoin: undefined,
lineWidth: undefined lineWidth: undefined,
miterLimit: undefined
}; };
}; };
@@ -511,26 +517,30 @@ ol.render.canvas.LineStringReplay.prototype.setStrokeStyle_ = function() {
var lineCap = state.lineCap; var lineCap = state.lineCap;
var lineJoin = state.lineJoin; var lineJoin = state.lineJoin;
var lineWidth = state.lineWidth; var lineWidth = state.lineWidth;
var miterLimit = state.miterLimit;
goog.asserts.assert(goog.isDef(strokeStyle)); goog.asserts.assert(goog.isDef(strokeStyle));
goog.asserts.assert(goog.isDef(lineCap)); goog.asserts.assert(goog.isDef(lineCap));
goog.asserts.assert(goog.isDef(lineJoin)); goog.asserts.assert(goog.isDef(lineJoin));
goog.asserts.assert(goog.isDef(lineWidth)); goog.asserts.assert(goog.isDef(lineWidth));
goog.asserts.assert(goog.isDef(miterLimit));
if (state.currentStrokeStyle != strokeStyle || if (state.currentStrokeStyle != strokeStyle ||
state.currentLineCap != lineCap || state.currentLineCap != lineCap ||
state.currentLineJoin != lineJoin || state.currentLineJoin != lineJoin ||
state.currentLineWidth != lineWidth) { state.currentLineWidth != lineWidth ||
state.currentMiterLimit != miterLimit) {
if (state.lastStroke != this.coordinates.length) { if (state.lastStroke != this.coordinates.length) {
this.instructions.push([ol.render.canvas.Instruction.STROKE]); this.instructions.push([ol.render.canvas.Instruction.STROKE]);
state.lastStroke = this.coordinates.length; state.lastStroke = this.coordinates.length;
} }
this.instructions.push( this.instructions.push(
[ol.render.canvas.Instruction.SET_STROKE_STYLE, [ol.render.canvas.Instruction.SET_STROKE_STYLE,
strokeStyle, lineWidth, lineCap, lineJoin], strokeStyle, lineWidth, lineCap, lineJoin, miterLimit],
[ol.render.canvas.Instruction.BEGIN_PATH]); [ol.render.canvas.Instruction.BEGIN_PATH]);
state.currentStrokeStyle = strokeStyle; state.currentStrokeStyle = strokeStyle;
state.currentLineCap = lineCap; state.currentLineCap = lineCap;
state.currentLineJoin = lineJoin; state.currentLineJoin = lineJoin;
state.currentLineWidth = lineWidth; state.currentLineWidth = lineWidth;
state.currentMiterLimit = miterLimit;
} }
}; };
@@ -615,6 +625,8 @@ ol.render.canvas.LineStringReplay.prototype.setFillStrokeStyle =
strokeStyle.lineJoin : ol.render.canvas.defaultLineJoin; strokeStyle.lineJoin : ol.render.canvas.defaultLineJoin;
this.state_.lineWidth = goog.isDef(strokeStyle.width) ? this.state_.lineWidth = goog.isDef(strokeStyle.width) ?
strokeStyle.width : ol.render.canvas.defaultLineWidth; strokeStyle.width : ol.render.canvas.defaultLineWidth;
this.state_.miterLimit = goog.isDef(strokeStyle.miterLimit) ?
strokeStyle.miterLimit : ol.render.canvas.defaultMiterLimit;
}; };
@@ -635,11 +647,13 @@ ol.render.canvas.PolygonReplay = function() {
* currentLineCap: (string|undefined), * currentLineCap: (string|undefined),
* currentLineJoin: (string|undefined), * currentLineJoin: (string|undefined),
* currentLineWidth: (number|undefined), * currentLineWidth: (number|undefined),
* currentMiterLimit: (number|undefined),
* fillStyle: (string|undefined), * fillStyle: (string|undefined),
* strokeStyle: (string|undefined), * strokeStyle: (string|undefined),
* lineCap: (string|undefined), * lineCap: (string|undefined),
* lineJoin: (string|undefined), * lineJoin: (string|undefined),
* lineWidth: (number|undefined)}|null} * lineWidth: (number|undefined),
* miterLimit: (number|undefined)}|null}
*/ */
this.state_ = { this.state_ = {
currentFillStyle: undefined, currentFillStyle: undefined,
@@ -647,11 +661,13 @@ ol.render.canvas.PolygonReplay = function() {
currentLineCap: undefined, currentLineCap: undefined,
currentLineJoin: undefined, currentLineJoin: undefined,
currentLineWidth: undefined, currentLineWidth: undefined,
currentMiterLimit: undefined,
fillStyle: undefined, fillStyle: undefined,
strokeStyle: undefined, strokeStyle: undefined,
lineCap: undefined, lineCap: undefined,
lineJoin: undefined, lineJoin: undefined,
lineWidth: undefined lineWidth: undefined,
miterLimit: undefined
}; };
}; };
@@ -782,11 +798,14 @@ ol.render.canvas.PolygonReplay.prototype.setFillStrokeStyle =
strokeStyle.lineJoin : ol.render.canvas.defaultLineJoin; strokeStyle.lineJoin : ol.render.canvas.defaultLineJoin;
state.lineWidth = goog.isDef(strokeStyle.width) ? state.lineWidth = goog.isDef(strokeStyle.width) ?
strokeStyle.width : ol.render.canvas.defaultLineWidth; strokeStyle.width : ol.render.canvas.defaultLineWidth;
state.miterLimit = goog.isDef(strokeStyle.miterLimit) ?
strokeStyle.miterLimit : ol.render.canvas.defaultMiterLimit;
} else { } else {
state.strokeStyle = undefined; state.strokeStyle = undefined;
state.lineCap = undefined; state.lineCap = undefined;
state.lineJoin = undefined; state.lineJoin = undefined;
state.lineWidth = undefined; state.lineWidth = undefined;
state.miterLimit = undefined;
} }
}; };
@@ -801,6 +820,7 @@ ol.render.canvas.PolygonReplay.prototype.setFillStrokeStyles_ = function() {
var lineCap = state.lineCap; var lineCap = state.lineCap;
var lineJoin = state.lineJoin; var lineJoin = state.lineJoin;
var lineWidth = state.lineWidth; var lineWidth = state.lineWidth;
var miterLimit = state.miterLimit;
if (goog.isDef(fillStyle) && state.currentFillStyle != fillStyle) { if (goog.isDef(fillStyle) && state.currentFillStyle != fillStyle) {
this.instructions.push( this.instructions.push(
[ol.render.canvas.Instruction.SET_FILL_STYLE, fillStyle]); [ol.render.canvas.Instruction.SET_FILL_STYLE, fillStyle]);
@@ -810,17 +830,20 @@ ol.render.canvas.PolygonReplay.prototype.setFillStrokeStyles_ = function() {
goog.asserts.assert(goog.isDef(lineCap)); goog.asserts.assert(goog.isDef(lineCap));
goog.asserts.assert(goog.isDef(lineJoin)); goog.asserts.assert(goog.isDef(lineJoin));
goog.asserts.assert(goog.isDef(lineWidth)); goog.asserts.assert(goog.isDef(lineWidth));
goog.asserts.assert(goog.isDef(miterLimit));
if (state.currentStrokeStyle != strokeStyle || if (state.currentStrokeStyle != strokeStyle ||
state.currentLineCap != lineCap || state.currentLineCap != lineCap ||
state.currentLineJoin != lineJoin || state.currentLineJoin != lineJoin ||
state.currentLineWidth != lineWidth) { state.currentLineWidth != lineWidth ||
state.currentMiterLimit != miterLimit) {
this.instructions.push( this.instructions.push(
[ol.render.canvas.Instruction.SET_STROKE_STYLE, [ol.render.canvas.Instruction.SET_STROKE_STYLE,
strokeStyle, lineWidth, lineCap, lineJoin]); strokeStyle, lineWidth, lineCap, lineJoin, miterLimit]);
state.currentStrokeStyle = strokeStyle; state.currentStrokeStyle = strokeStyle;
state.currentLineCap = lineCap; state.currentLineCap = lineCap;
state.currentLineJoin = lineJoin; state.currentLineJoin = lineJoin;
state.currentLineWidth = lineWidth; state.currentLineWidth = lineWidth;
state.currentMiterLimit = miterLimit;
} }
} }
}; };

View File

@@ -25,6 +25,11 @@ ol.style.Stroke = function(options) {
*/ */
this.lineJoin = options.lineJoin; this.lineJoin = options.lineJoin;
/**
* @type {number|undefined}
*/
this.miterLimit = options.miterLimit;
/** /**
* @type {number|undefined} * @type {number|undefined}
*/ */