Use CanvasLineCap type instead of string
This commit is contained in:
@@ -18,7 +18,7 @@ import LabelCache from './canvas/LabelCache.js';
|
|||||||
* @typedef {Object} FillStrokeState
|
* @typedef {Object} FillStrokeState
|
||||||
* @property {import("../colorlike.js").ColorLike} [currentFillStyle]
|
* @property {import("../colorlike.js").ColorLike} [currentFillStyle]
|
||||||
* @property {import("../colorlike.js").ColorLike} [currentStrokeStyle]
|
* @property {import("../colorlike.js").ColorLike} [currentStrokeStyle]
|
||||||
* @property {string} [currentLineCap]
|
* @property {CanvasLineCap} [currentLineCap]
|
||||||
* @property {Array<number>} currentLineDash
|
* @property {Array<number>} currentLineDash
|
||||||
* @property {number} [currentLineDashOffset]
|
* @property {number} [currentLineDashOffset]
|
||||||
* @property {CanvasLineJoin} [currentLineJoin]
|
* @property {CanvasLineJoin} [currentLineJoin]
|
||||||
@@ -27,7 +27,7 @@ import LabelCache from './canvas/LabelCache.js';
|
|||||||
* @property {number} [lastStroke]
|
* @property {number} [lastStroke]
|
||||||
* @property {import("../colorlike.js").ColorLike} [fillStyle]
|
* @property {import("../colorlike.js").ColorLike} [fillStyle]
|
||||||
* @property {import("../colorlike.js").ColorLike} [strokeStyle]
|
* @property {import("../colorlike.js").ColorLike} [strokeStyle]
|
||||||
* @property {string} [lineCap]
|
* @property {CanvasLineCap} [lineCap]
|
||||||
* @property {Array<number>} lineDash
|
* @property {Array<number>} lineDash
|
||||||
* @property {number} [lineDashOffset]
|
* @property {number} [lineDashOffset]
|
||||||
* @property {CanvasLineJoin} [lineJoin]
|
* @property {CanvasLineJoin} [lineJoin]
|
||||||
@@ -38,7 +38,7 @@ import LabelCache from './canvas/LabelCache.js';
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} StrokeState
|
* @typedef {Object} StrokeState
|
||||||
* @property {string} lineCap
|
* @property {CanvasLineCap} lineCap
|
||||||
* @property {Array<number>} lineDash
|
* @property {Array<number>} lineDash
|
||||||
* @property {number} lineDashOffset
|
* @property {number} lineDashOffset
|
||||||
* @property {CanvasLineJoin} lineJoin
|
* @property {CanvasLineJoin} lineJoin
|
||||||
@@ -92,7 +92,7 @@ export const defaultFillStyle = '#000';
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @const
|
* @const
|
||||||
* @type {string}
|
* @type {CanvasLineCap}
|
||||||
*/
|
*/
|
||||||
export const defaultLineCap = 'round';
|
export const defaultLineCap = 'round';
|
||||||
|
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ class Executor extends Disposable {
|
|||||||
if (strokeKey) {
|
if (strokeKey) {
|
||||||
context.strokeStyle = strokeState.strokeStyle;
|
context.strokeStyle = strokeState.strokeStyle;
|
||||||
context.lineWidth = strokeWidth;
|
context.lineWidth = strokeWidth;
|
||||||
context.lineCap = /** @type {CanvasLineCap} */ (strokeState.lineCap);
|
context.lineCap = strokeState.lineCap;
|
||||||
context.lineJoin = 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) {
|
||||||
|
|||||||
@@ -692,7 +692,7 @@ class CanvasImmediateRenderer extends VectorContext {
|
|||||||
const context = this.context_;
|
const context = this.context_;
|
||||||
const contextStrokeState = this.contextStrokeState_;
|
const contextStrokeState = this.contextStrokeState_;
|
||||||
if (!contextStrokeState) {
|
if (!contextStrokeState) {
|
||||||
context.lineCap = /** @type {CanvasLineCap} */ (strokeState.lineCap);
|
context.lineCap = strokeState.lineCap;
|
||||||
if (context.setLineDash) {
|
if (context.setLineDash) {
|
||||||
context.setLineDash(strokeState.lineDash);
|
context.setLineDash(strokeState.lineDash);
|
||||||
context.lineDashOffset = strokeState.lineDashOffset;
|
context.lineDashOffset = strokeState.lineDashOffset;
|
||||||
@@ -712,7 +712,7 @@ class CanvasImmediateRenderer extends VectorContext {
|
|||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
if (contextStrokeState.lineCap != strokeState.lineCap) {
|
if (contextStrokeState.lineCap != strokeState.lineCap) {
|
||||||
contextStrokeState.lineCap = context.lineCap = /** @type {CanvasLineCap} */ (strokeState.lineCap);
|
contextStrokeState.lineCap = context.lineCap = strokeState.lineCap;
|
||||||
}
|
}
|
||||||
if (context.setLineDash) {
|
if (context.setLineDash) {
|
||||||
if (!equals(contextStrokeState.lineDash, strokeState.lineDash)) {
|
if (!equals(contextStrokeState.lineDash, strokeState.lineDash)) {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import ImageStyle from './Image.js';
|
|||||||
* @property {import("../colorlike.js").ColorLike} [strokeStyle]
|
* @property {import("../colorlike.js").ColorLike} [strokeStyle]
|
||||||
* @property {number} strokeWidth
|
* @property {number} strokeWidth
|
||||||
* @property {number} size
|
* @property {number} size
|
||||||
* @property {string} lineCap
|
* @property {CanvasLineCap} lineCap
|
||||||
* @property {Array<number>} lineDash
|
* @property {Array<number>} lineDash
|
||||||
* @property {number} lineDashOffset
|
* @property {number} lineDashOffset
|
||||||
* @property {CanvasLineJoin} lineJoin
|
* @property {CanvasLineJoin} lineJoin
|
||||||
@@ -302,7 +302,7 @@ class RegularShape extends ImageStyle {
|
|||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
render() {
|
render() {
|
||||||
let lineCap = '';
|
let lineCap = defaultLineCap;
|
||||||
let lineJoin = defaultLineJoin;
|
let lineJoin = defaultLineJoin;
|
||||||
let miterLimit = 0;
|
let miterLimit = 0;
|
||||||
let lineDash = null;
|
let lineDash = null;
|
||||||
@@ -417,7 +417,7 @@ class RegularShape extends ImageStyle {
|
|||||||
context.setLineDash(renderOptions.lineDash);
|
context.setLineDash(renderOptions.lineDash);
|
||||||
context.lineDashOffset = renderOptions.lineDashOffset;
|
context.lineDashOffset = renderOptions.lineDashOffset;
|
||||||
}
|
}
|
||||||
context.lineCap = /** @type {CanvasLineCap} */ (renderOptions.lineCap);
|
context.lineCap = renderOptions.lineCap;
|
||||||
context.lineJoin = renderOptions.lineJoin;
|
context.lineJoin = renderOptions.lineJoin;
|
||||||
context.miterLimit = renderOptions.miterLimit;
|
context.miterLimit = renderOptions.miterLimit;
|
||||||
context.stroke();
|
context.stroke();
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
* @property {import("../color.js").Color|import("../colorlike.js").ColorLike} [color] A color, gradient or pattern.
|
* @property {import("../color.js").Color|import("../colorlike.js").ColorLike} [color] A color, gradient or pattern.
|
||||||
* 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 {CanvasLineCap} [lineCap='round'] Line cap style: `butt`, `round`, or `square`.
|
||||||
* @property {CanvasLineJoin} [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
|
||||||
@@ -43,7 +43,7 @@ class Stroke {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {string|undefined}
|
* @type {CanvasLineCap|undefined}
|
||||||
*/
|
*/
|
||||||
this.lineCap_ = options.lineCap;
|
this.lineCap_ = options.lineCap;
|
||||||
|
|
||||||
@@ -107,7 +107,7 @@ class Stroke {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the line cap type for the stroke.
|
* Get the line cap type for the stroke.
|
||||||
* @return {string|undefined} Line cap.
|
* @return {CanvasLineCap|undefined} Line cap.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
getLineCap() {
|
getLineCap() {
|
||||||
@@ -172,7 +172,7 @@ class Stroke {
|
|||||||
/**
|
/**
|
||||||
* Set the line cap.
|
* Set the line cap.
|
||||||
*
|
*
|
||||||
* @param {string|undefined} lineCap Line cap.
|
* @param {CanvasLineCap|undefined} lineCap Line cap.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
setLineCap(lineCap) {
|
setLineCap(lineCap) {
|
||||||
|
|||||||
Reference in New Issue
Block a user