Merge pull request #8769 from schmidtk/ts-render-canvas

Fix type check errors in ol/render/canvas
This commit is contained in:
Andreas Hocevar
2018-10-03 10:17:54 +02:00
committed by GitHub
3 changed files with 19 additions and 17 deletions
+10 -10
View File
@@ -577,7 +577,7 @@ class CanvasImmediateRenderer extends VectorContext {
const context = this.context_; const context = this.context_;
const flatCoordinates = geometry.getFlatCoordinates(); const flatCoordinates = geometry.getFlatCoordinates();
let offset = 0; let offset = 0;
const ends = geometry.getEnds(); const ends = /** @type {Array<number>} */ (geometry.getEnds());
const stride = geometry.getStride(); const stride = geometry.getStride();
context.beginPath(); context.beginPath();
for (let i = 0, ii = ends.length; i < ii; ++i) { for (let i = 0, ii = ends.length; i < ii; ++i) {
@@ -612,7 +612,7 @@ class CanvasImmediateRenderer extends VectorContext {
const context = this.context_; const context = this.context_;
context.beginPath(); context.beginPath();
this.drawRings_(geometry.getOrientedFlatCoordinates(), this.drawRings_(geometry.getOrientedFlatCoordinates(),
0, geometry.getEnds(), geometry.getStride()); 0, /** @type {Array<number>} */ (geometry.getEnds()), geometry.getStride());
if (this.fillState_) { if (this.fillState_) {
context.fill(); context.fill();
} }
@@ -693,12 +693,12 @@ 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 = strokeState.lineCap; context.lineCap = /** @type {CanvasLineCap} */ (strokeState.lineCap);
if (CANVAS_LINE_DASH) { if (CANVAS_LINE_DASH) {
context.setLineDash(strokeState.lineDash); context.setLineDash(strokeState.lineDash);
context.lineDashOffset = strokeState.lineDashOffset; context.lineDashOffset = strokeState.lineDashOffset;
} }
context.lineJoin = strokeState.lineJoin; context.lineJoin = /** @type {CanvasLineJoin} */ (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;
@@ -713,7 +713,7 @@ class CanvasImmediateRenderer extends VectorContext {
}; };
} else { } else {
if (contextStrokeState.lineCap != strokeState.lineCap) { if (contextStrokeState.lineCap != strokeState.lineCap) {
contextStrokeState.lineCap = context.lineCap = strokeState.lineCap; contextStrokeState.lineCap = context.lineCap = /** @type {CanvasLineCap} */ (strokeState.lineCap);
} }
if (CANVAS_LINE_DASH) { if (CANVAS_LINE_DASH) {
if (!equals(contextStrokeState.lineDash, strokeState.lineDash)) { if (!equals(contextStrokeState.lineDash, strokeState.lineDash)) {
@@ -725,7 +725,7 @@ class CanvasImmediateRenderer extends VectorContext {
} }
} }
if (contextStrokeState.lineJoin != strokeState.lineJoin) { if (contextStrokeState.lineJoin != strokeState.lineJoin) {
contextStrokeState.lineJoin = context.lineJoin = strokeState.lineJoin; contextStrokeState.lineJoin = context.lineJoin = /** @type {CanvasLineJoin} */ (strokeState.lineJoin);
} }
if (contextStrokeState.lineWidth != strokeState.lineWidth) { if (contextStrokeState.lineWidth != strokeState.lineWidth) {
contextStrokeState.lineWidth = context.lineWidth = strokeState.lineWidth; contextStrokeState.lineWidth = context.lineWidth = strokeState.lineWidth;
@@ -752,8 +752,8 @@ class CanvasImmediateRenderer extends VectorContext {
textState.textAlign : defaultTextAlign; textState.textAlign : defaultTextAlign;
if (!contextTextState) { if (!contextTextState) {
context.font = textState.font; context.font = textState.font;
context.textAlign = textAlign; context.textAlign = /** @type {CanvasTextAlign} */ (textAlign);
context.textBaseline = textState.textBaseline; context.textBaseline = /** @type {CanvasTextBaseline} */ (textState.textBaseline);
this.contextTextState_ = { this.contextTextState_ = {
font: textState.font, font: textState.font,
textAlign: textAlign, textAlign: textAlign,
@@ -764,11 +764,11 @@ class CanvasImmediateRenderer extends VectorContext {
contextTextState.font = context.font = textState.font; contextTextState.font = context.font = textState.font;
} }
if (contextTextState.textAlign != textAlign) { if (contextTextState.textAlign != textAlign) {
contextTextState.textAlign = context.textAlign = textAlign; contextTextState.textAlign = context.textAlign = /** @type {CanvasTextAlign} */ (textAlign);
} }
if (contextTextState.textBaseline != textState.textBaseline) { if (contextTextState.textBaseline != textState.textBaseline) {
contextTextState.textBaseline = context.textBaseline = contextTextState.textBaseline = context.textBaseline =
textState.textBaseline; /** @type {CanvasTextBaseline} */ (textState.textBaseline);
} }
} }
} }
+7 -5
View File
@@ -485,8 +485,8 @@ class CanvasReplay extends VectorContext {
setStrokeStyle_(context, instruction) { setStrokeStyle_(context, instruction) {
context.strokeStyle = /** @type {import("../../colorlike.js").ColorLike} */ (instruction[1]); context.strokeStyle = /** @type {import("../../colorlike.js").ColorLike} */ (instruction[1]);
context.lineWidth = /** @type {number} */ (instruction[2]); context.lineWidth = /** @type {number} */ (instruction[2]);
context.lineCap = /** @type {string} */ (instruction[3]); context.lineCap = /** @type {CanvasLineCap} */ (instruction[3]);
context.lineJoin = /** @type {string} */ (instruction[4]); context.lineJoin = /** @type {CanvasLineJoin} */ (instruction[4]);
context.miterLimit = /** @type {number} */ (instruction[5]); context.miterLimit = /** @type {number} */ (instruction[5]);
if (CANVAS_LINE_DASH) { if (CANVAS_LINE_DASH) {
context.lineDashOffset = /** @type {number} */ (instruction[7]); context.lineDashOffset = /** @type {number} */ (instruction[7]);
@@ -723,7 +723,8 @@ class CanvasReplay extends VectorContext {
const pathLength = lineStringLength(pixelCoordinates, begin, end, 2); const pathLength = lineStringLength(pixelCoordinates, begin, end, 2);
const textLength = measure(text); const textLength = measure(text);
if (overflow || textLength <= pathLength) { if (overflow || textLength <= pathLength) {
const textAlign = /** @type {module:ol~render} */ (this).textStates[textKey].textAlign; const textReplay = /** @type {import("./TextReplay.js").default} */ (this);
const textAlign = textReplay.textStates[textKey].textAlign;
const startM = (pathLength - textLength) * TEXT_ALIGN[textAlign]; const startM = (pathLength - textLength) * TEXT_ALIGN[textAlign];
const parts = drawTextOnPath( const parts = drawTextOnPath(
pixelCoordinates, begin, end, 2, text, measure, startM, maxAngle); pixelCoordinates, begin, end, 2, text, measure, startM, maxAngle);
@@ -733,7 +734,7 @@ class CanvasReplay extends VectorContext {
for (c = 0, cc = parts.length; c < cc; ++c) { for (c = 0, cc = parts.length; c < cc; ++c) {
part = parts[c]; // x, y, anchorX, rotation, chunk part = parts[c]; // x, y, anchorX, rotation, chunk
chars = /** @type {string} */ (part[4]); chars = /** @type {string} */ (part[4]);
label = /** @type {module:ol~render} */ (this).getImage(chars, textKey, '', strokeKey); label = textReplay.getImage(chars, textKey, '', strokeKey);
anchorX = /** @type {number} */ (part[2]) + strokeWidth; anchorX = /** @type {number} */ (part[2]) + strokeWidth;
anchorY = baseline * label.height + (0.5 - baseline) * 2 * strokeWidth - offsetY; anchorY = baseline * label.height + (0.5 - baseline) * 2 * strokeWidth - offsetY;
this.replayImage_(context, this.replayImage_(context,
@@ -747,7 +748,7 @@ class CanvasReplay extends VectorContext {
for (c = 0, cc = parts.length; c < cc; ++c) { for (c = 0, cc = parts.length; c < cc; ++c) {
part = parts[c]; // x, y, anchorX, rotation, chunk part = parts[c]; // x, y, anchorX, rotation, chunk
chars = /** @type {string} */ (part[4]); chars = /** @type {string} */ (part[4]);
label = /** @type {module:ol~render} */ (this).getImage(chars, textKey, fillKey, ''); label = textReplay.getImage(chars, textKey, fillKey, '');
anchorX = /** @type {number} */ (part[2]); anchorX = /** @type {number} */ (part[2]);
anchorY = baseline * label.height - offsetY; anchorY = baseline * label.height - offsetY;
this.replayImage_(context, this.replayImage_(context,
@@ -976,6 +977,7 @@ class CanvasReplay extends VectorContext {
*/ */
createFill(state, geometry) { createFill(state, geometry) {
const fillStyle = state.fillStyle; const fillStyle = state.fillStyle;
/** @type {Array<*>} */
const fillInstruction = [CanvasInstruction.SET_FILL_STYLE, fillStyle]; const fillInstruction = [CanvasInstruction.SET_FILL_STYLE, fillStyle];
if (typeof fillStyle !== 'string') { if (typeof fillStyle !== 'string') {
// Fill is a pattern or gradient - align it! // Fill is a pattern or gradient - align it!
+2 -2
View File
@@ -288,8 +288,8 @@ class CanvasTextReplay extends CanvasReplay {
if (strokeKey) { if (strokeKey) {
context.strokeStyle = strokeState.strokeStyle; context.strokeStyle = strokeState.strokeStyle;
context.lineWidth = strokeWidth; context.lineWidth = strokeWidth;
context.lineCap = strokeState.lineCap; context.lineCap = /** @type {CanvasLineCap} */ (strokeState.lineCap);
context.lineJoin = strokeState.lineJoin; context.lineJoin = /** @type {CanvasLineJoin} */ (strokeState.lineJoin);
context.miterLimit = strokeState.miterLimit; context.miterLimit = strokeState.miterLimit;
if (CANVAS_LINE_DASH && strokeState.lineDash.length) { if (CANVAS_LINE_DASH && strokeState.lineDash.length) {
context.setLineDash(strokeState.lineDash); context.setLineDash(strokeState.lineDash);