diff --git a/src/ol/render/canvas.js b/src/ol/render/canvas.js index 65b7453920..3fd49d7443 100644 --- a/src/ol/render/canvas.js +++ b/src/ol/render/canvas.js @@ -4,7 +4,6 @@ import {getFontParameters} from '../css.js'; import {createCanvasContext2D} from '../dom.js'; import {clear} from '../obj.js'; -import {executeLabelInstructions} from './canvas/Executor.js'; import BaseObject from '../Object.js'; import EventTarget from '../events/Target.js'; @@ -14,6 +13,12 @@ import EventTarget from '../events/Target.js'; * @property {import("../colorlike.js").ColorLike} fillStyle */ +/** + * @typedef Label + * @property {number} width + * @property {number} height + * @property {Array} contextInstructions + */ /** * @typedef {Object} FillStrokeState @@ -386,7 +391,7 @@ export function rotateAtOffset(context, rotation, offsetX, offsetY) { * @param {CanvasRenderingContext2D} context Context. * @param {import("../transform.js").Transform|null} transform Transform. * @param {number} opacity Opacity. - * @param {import("./canvas/Executor.js").Label|HTMLCanvasElement|HTMLImageElement|HTMLVideoElement} labelOrImage Label. + * @param {Label|HTMLCanvasElement|HTMLImageElement|HTMLVideoElement} labelOrImage Label. * @param {number} originX Origin X. * @param {number} originY Origin Y. * @param {number} w Width. @@ -407,7 +412,7 @@ export function drawImageOrLabel(context, // label context.translate(x, y); context.scale(scale, scale); - executeLabelInstructions(/** @type {import("./canvas/Executor.js").Label} */ (labelOrImage), context); + executeLabelInstructions(/** @type {Label} */ (labelOrImage), context); } else { // image context.drawImage(/** @type {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement} */ (labelOrImage), originX, originY, w, h, x, y, w * scale, h * scale); @@ -415,3 +420,18 @@ export function drawImageOrLabel(context, context.restore(); } + +/** + * @param {Label} label Label. + * @param {CanvasRenderingContext2D} context Context. + */ +function executeLabelInstructions(label, context) { + const contextInstructions = label.contextInstructions; + for (let i = 0, ii = contextInstructions.length; i < ii; i += 2) { + if (Array.isArray(contextInstructions[i + 1])) { + CanvasRenderingContext2D.prototype[contextInstructions[i]].apply(context, contextInstructions[i + 1]); + } else { + context[contextInstructions[i]] = contextInstructions[i + 1]; + } + } +} diff --git a/src/ol/render/canvas/Executor.js b/src/ol/render/canvas/Executor.js index c109c6d04b..dfb70e9bcc 100644 --- a/src/ol/render/canvas/Executor.js +++ b/src/ol/render/canvas/Executor.js @@ -30,28 +30,6 @@ import RBush from 'rbush/rbush.js'; * @property {!Object} strokeStates The stroke states (decluttering). */ -/** - * @typedef Label - * @property {number} width - * @property {number} height - * @property {Array} contextInstructions - */ - -/** - * @param {Label} label Label. - * @param {CanvasRenderingContext2D} context Context. - */ -export function executeLabelInstructions(label, context) { - const contextInstructions = label.contextInstructions; - for (let i = 0, ii = contextInstructions.length; i < ii; i += 2) { - if (Array.isArray(contextInstructions[i + 1])) { - CanvasRenderingContext2D.prototype[contextInstructions[i]].apply(context, contextInstructions[i + 1]); - } else { - context[contextInstructions[i]] = contextInstructions[i + 1]; - } - } -} - /** * @type {import("../../extent.js").Extent} */ @@ -176,7 +154,7 @@ class Executor { /** * @private - * @type {Object} + * @type {Object} */ this.labels_ = {}; } @@ -186,7 +164,7 @@ class Executor { * @param {string} textKey Text style key. * @param {string} fillKey Fill style key. * @param {string} strokeKey Stroke style key. - * @return {Label} Label. + * @return {import("../canvas.js").Label} Label. */ createLabel(text, textKey, fillKey, strokeKey) { const key = text + textKey + fillKey + strokeKey; @@ -209,7 +187,7 @@ class Executor { const height = lineHeight * numLines; const renderWidth = width + strokeWidth; const contextInstructions = []; - /** @type {Label} */ + /** @type {import("../canvas.js").Label} */ const label = { // make canvas 2 pixels wider to account for italic text width measurement errors width: Math.ceil((renderWidth + 2) * scale), @@ -283,7 +261,7 @@ class Executor { * @param {CanvasRenderingContext2D} context Context. * @param {number} x X. * @param {number} y Y. - * @param {Label|HTMLImageElement|HTMLCanvasElement|HTMLVideoElement} imageOrLabel Image. + * @param {import("../canvas.js").Label|HTMLImageElement|HTMLCanvasElement|HTMLVideoElement} imageOrLabel Image. * @param {number} anchorX Anchor X. * @param {number} anchorY Anchor Y. * @param {import("../canvas.js").DeclutterGroup} declutterGroup Declutter group. @@ -488,7 +466,7 @@ class Executor { * @param {string} textKey The key of the text state. * @param {string} strokeKey The key for the stroke state. * @param {string} fillKey The key for the fill state. - * @return {{label: Label, anchorX: number, anchorY: number}} The text image and its anchor. + * @return {{label: import("../canvas.js").Label, anchorX: number, anchorY: number}} The text image and its anchor. */ drawLabelWithPointPlacement_(text, textKey, strokeKey, fillKey) { const textState = this.textStates[textKey];