Use CanvasLineJoin type instead of string

This commit is contained in:
Frederic Junod
2019-07-05 11:07:10 +02:00
parent 5cff84522a
commit 7a8a0c18ae
5 changed files with 14 additions and 14 deletions

View File

@@ -21,7 +21,7 @@ import LabelCache from './canvas/LabelCache.js';
* @property {string} [currentLineCap] * @property {string} [currentLineCap]
* @property {Array<number>} currentLineDash * @property {Array<number>} currentLineDash
* @property {number} [currentLineDashOffset] * @property {number} [currentLineDashOffset]
* @property {string} [currentLineJoin] * @property {CanvasLineJoin} [currentLineJoin]
* @property {number} [currentLineWidth] * @property {number} [currentLineWidth]
* @property {number} [currentMiterLimit] * @property {number} [currentMiterLimit]
* @property {number} [lastStroke] * @property {number} [lastStroke]
@@ -30,7 +30,7 @@ import LabelCache from './canvas/LabelCache.js';
* @property {string} [lineCap] * @property {string} [lineCap]
* @property {Array<number>} lineDash * @property {Array<number>} lineDash
* @property {number} [lineDashOffset] * @property {number} [lineDashOffset]
* @property {string} [lineJoin] * @property {CanvasLineJoin} [lineJoin]
* @property {number} [lineWidth] * @property {number} [lineWidth]
* @property {number} [miterLimit] * @property {number} [miterLimit]
*/ */
@@ -41,7 +41,7 @@ import LabelCache from './canvas/LabelCache.js';
* @property {string} lineCap * @property {string} lineCap
* @property {Array<number>} lineDash * @property {Array<number>} lineDash
* @property {number} lineDashOffset * @property {number} lineDashOffset
* @property {string} lineJoin * @property {CanvasLineJoin} lineJoin
* @property {number} lineWidth * @property {number} lineWidth
* @property {number} miterLimit * @property {number} miterLimit
* @property {import("../colorlike.js").ColorLike} strokeStyle * @property {import("../colorlike.js").ColorLike} strokeStyle
@@ -113,7 +113,7 @@ export const defaultLineDashOffset = 0;
/** /**
* @const * @const
* @type {string} * @type {CanvasLineJoin}
*/ */
export const defaultLineJoin = 'round'; export const defaultLineJoin = 'round';

View File

@@ -208,7 +208,7 @@ class Executor extends Disposable {
context.strokeStyle = strokeState.strokeStyle; context.strokeStyle = strokeState.strokeStyle;
context.lineWidth = strokeWidth; context.lineWidth = strokeWidth;
context.lineCap = /** @type {CanvasLineCap} */ (strokeState.lineCap); context.lineCap = /** @type {CanvasLineCap} */ (strokeState.lineCap);
context.lineJoin = /** @type {CanvasLineJoin} */ (strokeState.lineJoin); context.lineJoin = strokeState.lineJoin;
context.miterLimit = strokeState.miterLimit; context.miterLimit = strokeState.miterLimit;
if (context.setLineDash && strokeState.lineDash.length) { if (context.setLineDash && strokeState.lineDash.length) {
context.setLineDash(strokeState.lineDash); context.setLineDash(strokeState.lineDash);

View File

@@ -697,7 +697,7 @@ class CanvasImmediateRenderer extends VectorContext {
context.setLineDash(strokeState.lineDash); context.setLineDash(strokeState.lineDash);
context.lineDashOffset = strokeState.lineDashOffset; context.lineDashOffset = strokeState.lineDashOffset;
} }
context.lineJoin = /** @type {CanvasLineJoin} */ (strokeState.lineJoin); context.lineJoin = strokeState.lineJoin;
context.lineWidth = strokeState.lineWidth; context.lineWidth = strokeState.lineWidth;
context.miterLimit = strokeState.miterLimit; context.miterLimit = strokeState.miterLimit;
context.strokeStyle = strokeState.strokeStyle; context.strokeStyle = strokeState.strokeStyle;
@@ -724,7 +724,7 @@ class CanvasImmediateRenderer extends VectorContext {
} }
} }
if (contextStrokeState.lineJoin != strokeState.lineJoin) { if (contextStrokeState.lineJoin != strokeState.lineJoin) {
contextStrokeState.lineJoin = context.lineJoin = /** @type {CanvasLineJoin} */ (strokeState.lineJoin); contextStrokeState.lineJoin = context.lineJoin = strokeState.lineJoin;
} }
if (contextStrokeState.lineWidth != strokeState.lineWidth) { if (contextStrokeState.lineWidth != strokeState.lineWidth) {
contextStrokeState.lineWidth = context.lineWidth = strokeState.lineWidth; contextStrokeState.lineWidth = context.lineWidth = strokeState.lineWidth;

View File

@@ -33,7 +33,7 @@ import ImageStyle from './Image.js';
* @property {string} lineCap * @property {string} lineCap
* @property {Array<number>} lineDash * @property {Array<number>} lineDash
* @property {number} lineDashOffset * @property {number} lineDashOffset
* @property {string} lineJoin * @property {CanvasLineJoin} lineJoin
* @property {number} miterLimit * @property {number} miterLimit
*/ */
@@ -303,7 +303,7 @@ class RegularShape extends ImageStyle {
*/ */
render() { render() {
let lineCap = ''; let lineCap = '';
let lineJoin = ''; let lineJoin = defaultLineJoin;
let miterLimit = 0; let miterLimit = 0;
let lineDash = null; let lineDash = null;
let lineDashOffset = 0; let lineDashOffset = 0;
@@ -418,7 +418,7 @@ class RegularShape extends ImageStyle {
context.lineDashOffset = renderOptions.lineDashOffset; context.lineDashOffset = renderOptions.lineDashOffset;
} }
context.lineCap = /** @type {CanvasLineCap} */ (renderOptions.lineCap); context.lineCap = /** @type {CanvasLineCap} */ (renderOptions.lineCap);
context.lineJoin = /** @type {CanvasLineJoin} */ (renderOptions.lineJoin); context.lineJoin = renderOptions.lineJoin;
context.miterLimit = renderOptions.miterLimit; context.miterLimit = renderOptions.miterLimit;
context.stroke(); context.stroke();
} }

View File

@@ -9,7 +9,7 @@
* See {@link module:ol/color~Color} and {@link module:ol/colorlike~ColorLike} for possible formats. * See {@link module:ol/color~Color} and {@link module:ol/colorlike~ColorLike} for possible formats.
* Default null; if null, the Canvas/renderer default black will be used. * Default null; if null, the Canvas/renderer default black will be used.
* @property {string} [lineCap='round'] Line cap style: `butt`, `round`, or `square`. * @property {string} [lineCap='round'] Line cap style: `butt`, `round`, or `square`.
* @property {string} [lineJoin='round'] Line join style: `bevel`, `round`, or `miter`. * @property {CanvasLineJoin} [lineJoin='round'] Line join style: `bevel`, `round`, or `miter`.
* @property {Array<number>} [lineDash] Line dash pattern. Default is `undefined` (no dash). * @property {Array<number>} [lineDash] Line dash pattern. Default is `undefined` (no dash).
* Please note that Internet Explorer 10 and lower do not support the `setLineDash` method on * Please note that Internet Explorer 10 and lower do not support the `setLineDash` method on
* the `CanvasRenderingContext2D` and therefore this option will have no visual effect in these browsers. * the `CanvasRenderingContext2D` and therefore this option will have no visual effect in these browsers.
@@ -61,7 +61,7 @@ class Stroke {
/** /**
* @private * @private
* @type {string|undefined} * @type {CanvasLineJoin|undefined}
*/ */
this.lineJoin_ = options.lineJoin; this.lineJoin_ = options.lineJoin;
@@ -134,7 +134,7 @@ class Stroke {
/** /**
* Get the line join type for the stroke. * Get the line join type for the stroke.
* @return {string|undefined} Line join. * @return {CanvasLineJoin|undefined} Line join.
* @api * @api
*/ */
getLineJoin() { getLineJoin() {
@@ -208,7 +208,7 @@ class Stroke {
/** /**
* Set the line join. * Set the line join.
* *
* @param {string|undefined} lineJoin Line join. * @param {CanvasLineJoin|undefined} lineJoin Line join.
* @api * @api
*/ */
setLineJoin(lineJoin) { setLineJoin(lineJoin) {