Named exports from ol/render/canvas

This commit is contained in:
Tim Schaub
2018-02-14 09:27:33 -07:00
parent 18fa8ddc58
commit 0948d4002f
13 changed files with 154 additions and 167 deletions

View File

@@ -6,125 +6,123 @@ import {createCanvasContext2D} from '../dom.js';
import {clear} from '../obj.js';
import LRUCache from '../structs/LRUCache.js';
import _ol_transform_ from '../transform.js';
const _ol_render_canvas_ = {};
/**
* @const
* @type {string}
*/
_ol_render_canvas_.defaultFont = '10px sans-serif';
export const defaultFont = '10px sans-serif';
/**
* @const
* @type {ol.Color}
*/
_ol_render_canvas_.defaultFillStyle = [0, 0, 0, 1];
export const defaultFillStyle = [0, 0, 0, 1];
/**
* @const
* @type {string}
*/
_ol_render_canvas_.defaultLineCap = 'round';
export const defaultLineCap = 'round';
/**
* @const
* @type {Array.<number>}
*/
_ol_render_canvas_.defaultLineDash = [];
export const defaultLineDash = [];
/**
* @const
* @type {number}
*/
_ol_render_canvas_.defaultLineDashOffset = 0;
export const defaultLineDashOffset = 0;
/**
* @const
* @type {string}
*/
_ol_render_canvas_.defaultLineJoin = 'round';
export const defaultLineJoin = 'round';
/**
* @const
* @type {number}
*/
_ol_render_canvas_.defaultMiterLimit = 10;
export const defaultMiterLimit = 10;
/**
* @const
* @type {ol.Color}
*/
_ol_render_canvas_.defaultStrokeStyle = [0, 0, 0, 1];
export const defaultStrokeStyle = [0, 0, 0, 1];
/**
* @const
* @type {string}
*/
_ol_render_canvas_.defaultTextAlign = 'center';
export const defaultTextAlign = 'center';
/**
* @const
* @type {string}
*/
_ol_render_canvas_.defaultTextBaseline = 'middle';
export const defaultTextBaseline = 'middle';
/**
* @const
* @type {Array.<number>}
*/
_ol_render_canvas_.defaultPadding = [0, 0, 0, 0];
export const defaultPadding = [0, 0, 0, 0];
/**
* @const
* @type {number}
*/
_ol_render_canvas_.defaultLineWidth = 1;
export const defaultLineWidth = 1;
/**
* @type {ol.structs.LRUCache.<HTMLCanvasElement>}
*/
_ol_render_canvas_.labelCache = new LRUCache();
export const labelCache = new LRUCache();
/**
* @type {!Object.<string, number>}
*/
_ol_render_canvas_.checkedFonts_ = {};
export const checkedFonts = {};
/**
* @type {CanvasRenderingContext2D}
*/
_ol_render_canvas_.measureContext_ = null;
let measureContext = null;
/**
* @type {!Object.<string, number>}
*/
_ol_render_canvas_.textHeights_ = {};
export const textHeights = {};
/**
* Clears the label cache when a font becomes available.
* @param {string} fontSpec CSS font spec.
*/
_ol_render_canvas_.checkFont = (function() {
export const checkFont = (function() {
const retries = 60;
const checked = _ol_render_canvas_.checkedFonts_;
const labelCache = _ol_render_canvas_.labelCache;
const checked = checkedFonts;
const size = '32px ';
const referenceFonts = ['monospace', 'serif'];
const len = referenceFonts.length;
@@ -132,7 +130,7 @@ _ol_render_canvas_.checkFont = (function() {
let interval, referenceWidth;
function isAvailable(font) {
const context = _ol_render_canvas_.getMeasureContext();
const context = getMeasureContext();
let available = true;
for (let i = 0; i < len; ++i) {
const referenceFont = referenceFonts[i];
@@ -155,9 +153,9 @@ _ol_render_canvas_.checkFont = (function() {
if (checked[font] < retries) {
if (isAvailable(font)) {
checked[font] = retries;
clear(_ol_render_canvas_.textHeights_);
clear(textHeights);
// Make sure that loaded fonts are picked up by Safari
_ol_render_canvas_.measureContext_ = null;
measureContext = null;
labelCache.clear();
} else {
++checked[font];
@@ -195,22 +193,21 @@ _ol_render_canvas_.checkFont = (function() {
/**
* @return {CanvasRenderingContext2D} Measure context.
*/
_ol_render_canvas_.getMeasureContext = function() {
let context = _ol_render_canvas_.measureContext_;
if (!context) {
context = _ol_render_canvas_.measureContext_ = createCanvasContext2D(1, 1);
function getMeasureContext() {
if (!measureContext) {
measureContext = createCanvasContext2D(1, 1);
}
return context;
};
return measureContext;
}
/**
* @param {string} font Font to use for measuring.
* @return {ol.Size} Measurement.
*/
_ol_render_canvas_.measureTextHeight = (function() {
export const measureTextHeight = (function() {
let span;
const heights = _ol_render_canvas_.textHeights_;
const heights = textHeights;
return function(font) {
let height = heights[font];
if (height == undefined) {
@@ -236,13 +233,13 @@ _ol_render_canvas_.measureTextHeight = (function() {
* @param {string} text Text.
* @return {number} Width.
*/
_ol_render_canvas_.measureTextWidth = function(font, text) {
const measureContext = _ol_render_canvas_.getMeasureContext();
export function measureTextWidth(font, text) {
const measureContext = getMeasureContext();
if (font != measureContext.font) {
measureContext.font = font;
}
return measureContext.measureText(text).width;
};
}
/**
@@ -251,16 +248,16 @@ _ol_render_canvas_.measureTextWidth = function(font, text) {
* @param {number} offsetX X offset.
* @param {number} offsetY Y offset.
*/
_ol_render_canvas_.rotateAtOffset = function(context, rotation, offsetX, offsetY) {
export function rotateAtOffset(context, rotation, offsetX, offsetY) {
if (rotation !== 0) {
context.translate(offsetX, offsetY);
context.rotate(rotation);
context.translate(-offsetX, -offsetY);
}
};
}
_ol_render_canvas_.resetTransform_ = _ol_transform_.create();
export const resetTransform = _ol_transform_.create();
/**
@@ -276,7 +273,7 @@ _ol_render_canvas_.resetTransform_ = _ol_transform_.create();
* @param {number} y Y.
* @param {number} scale Scale.
*/
_ol_render_canvas_.drawImage = function(context,
export function drawImage(context,
transform, opacity, image, originX, originY, w, h, x, y, scale) {
let alpha;
if (opacity != 1) {
@@ -293,7 +290,6 @@ _ol_render_canvas_.drawImage = function(context,
context.globalAlpha = alpha;
}
if (transform) {
context.setTransform.apply(context, _ol_render_canvas_.resetTransform_);
context.setTransform.apply(context, resetTransform);
}
};
export default _ol_render_canvas_;
}

View File

@@ -14,7 +14,7 @@ import SimpleGeometry from '../../geom/SimpleGeometry.js';
import {transform2D} from '../../geom/flat/transform.js';
import {CANVAS_LINE_DASH} from '../../has.js';
import VectorContext from '../VectorContext.js';
import _ol_render_canvas_ from '../canvas.js';
import {defaultTextAlign, defaultFillStyle, defaultLineCap, defaultLineDash, defaultLineDashOffset, defaultLineJoin, defaultLineWidth, defaultMiterLimit, defaultStrokeStyle, defaultTextBaseline, defaultFont} from '../canvas.js';
import _ol_transform_ from '../../transform.js';
/**
@@ -784,7 +784,7 @@ CanvasImmediateRenderer.prototype.setContextTextState_ = function(textState) {
const context = this.context_;
const contextTextState = this.contextTextState_;
const textAlign = textState.textAlign ?
textState.textAlign : _ol_render_canvas_.defaultTextAlign;
textState.textAlign : defaultTextAlign;
if (!contextTextState) {
context.font = textState.font;
context.textAlign = textAlign;
@@ -824,7 +824,7 @@ CanvasImmediateRenderer.prototype.setFillStrokeStyle = function(fillStyle, strok
const fillStyleColor = fillStyle.getColor();
this.fillState_ = {
fillStyle: asColorLike(fillStyleColor ?
fillStyleColor : _ol_render_canvas_.defaultFillStyle)
fillStyleColor : defaultFillStyle)
};
}
if (!strokeStyle) {
@@ -839,19 +839,19 @@ CanvasImmediateRenderer.prototype.setFillStrokeStyle = function(fillStyle, strok
const strokeStyleMiterLimit = strokeStyle.getMiterLimit();
this.strokeState_ = {
lineCap: strokeStyleLineCap !== undefined ?
strokeStyleLineCap : _ol_render_canvas_.defaultLineCap,
strokeStyleLineCap : defaultLineCap,
lineDash: strokeStyleLineDash ?
strokeStyleLineDash : _ol_render_canvas_.defaultLineDash,
strokeStyleLineDash : defaultLineDash,
lineDashOffset: strokeStyleLineDashOffset ?
strokeStyleLineDashOffset : _ol_render_canvas_.defaultLineDashOffset,
strokeStyleLineDashOffset : defaultLineDashOffset,
lineJoin: strokeStyleLineJoin !== undefined ?
strokeStyleLineJoin : _ol_render_canvas_.defaultLineJoin,
strokeStyleLineJoin : defaultLineJoin,
lineWidth: this.pixelRatio_ * (strokeStyleWidth !== undefined ?
strokeStyleWidth : _ol_render_canvas_.defaultLineWidth),
strokeStyleWidth : defaultLineWidth),
miterLimit: strokeStyleMiterLimit !== undefined ?
strokeStyleMiterLimit : _ol_render_canvas_.defaultMiterLimit,
strokeStyleMiterLimit : defaultMiterLimit,
strokeStyle: asColorLike(strokeStyleColor ?
strokeStyleColor : _ol_render_canvas_.defaultStrokeStyle)
strokeStyleColor : defaultStrokeStyle)
};
}
};
@@ -907,7 +907,7 @@ CanvasImmediateRenderer.prototype.setTextStyle = function(textStyle) {
const textFillStyleColor = textFillStyle.getColor();
this.textFillState_ = {
fillStyle: asColorLike(textFillStyleColor ?
textFillStyleColor : _ol_render_canvas_.defaultFillStyle)
textFillStyleColor : defaultFillStyle)
};
}
const textStrokeStyle = textStyle.getStroke();
@@ -923,19 +923,19 @@ CanvasImmediateRenderer.prototype.setTextStyle = function(textStyle) {
const textStrokeStyleMiterLimit = textStrokeStyle.getMiterLimit();
this.textStrokeState_ = {
lineCap: textStrokeStyleLineCap !== undefined ?
textStrokeStyleLineCap : _ol_render_canvas_.defaultLineCap,
textStrokeStyleLineCap : defaultLineCap,
lineDash: textStrokeStyleLineDash ?
textStrokeStyleLineDash : _ol_render_canvas_.defaultLineDash,
textStrokeStyleLineDash : defaultLineDash,
lineDashOffset: textStrokeStyleLineDashOffset ?
textStrokeStyleLineDashOffset : _ol_render_canvas_.defaultLineDashOffset,
textStrokeStyleLineDashOffset : defaultLineDashOffset,
lineJoin: textStrokeStyleLineJoin !== undefined ?
textStrokeStyleLineJoin : _ol_render_canvas_.defaultLineJoin,
textStrokeStyleLineJoin : defaultLineJoin,
lineWidth: textStrokeStyleWidth !== undefined ?
textStrokeStyleWidth : _ol_render_canvas_.defaultLineWidth,
textStrokeStyleWidth : defaultLineWidth,
miterLimit: textStrokeStyleMiterLimit !== undefined ?
textStrokeStyleMiterLimit : _ol_render_canvas_.defaultMiterLimit,
textStrokeStyleMiterLimit : defaultMiterLimit,
strokeStyle: asColorLike(textStrokeStyleColor ?
textStrokeStyleColor : _ol_render_canvas_.defaultStrokeStyle)
textStrokeStyleColor : defaultStrokeStyle)
};
}
const textFont = textStyle.getFont();
@@ -949,11 +949,11 @@ CanvasImmediateRenderer.prototype.setTextStyle = function(textStyle) {
const textTextBaseline = textStyle.getTextBaseline();
this.textState_ = {
font: textFont !== undefined ?
textFont : _ol_render_canvas_.defaultFont,
textFont : defaultFont,
textAlign: textTextAlign !== undefined ?
textTextAlign : _ol_render_canvas_.defaultTextAlign,
textTextAlign : defaultTextAlign,
textBaseline: textTextBaseline !== undefined ?
textTextBaseline : _ol_render_canvas_.defaultTextBaseline
textTextBaseline : defaultTextBaseline
};
this.text_ = textText !== undefined ? textText : '';
this.textOffsetX_ =

View File

@@ -4,7 +4,7 @@
import {inherits} from '../../index.js';
import {asString} from '../../color.js';
import {snap} from '../../geom/flat/simplify.js';
import _ol_render_canvas_ from '../canvas.js';
import {defaultFillStyle} from '../canvas.js';
import CanvasInstruction, {
fillInstruction, strokeInstruction, beginPathInstruction, closePathInstruction
} from '../canvas/Instruction.js';
@@ -89,7 +89,7 @@ CanvasPolygonReplay.prototype.drawCircle = function(circleGeometry, feature) {
// always fill the circle for hit detection
this.hitDetectionInstructions.push([
CanvasInstruction.SET_FILL_STYLE,
asString(_ol_render_canvas_.defaultFillStyle)
asString(defaultFillStyle)
]);
if (state.strokeStyle !== undefined) {
this.hitDetectionInstructions.push([
@@ -128,7 +128,7 @@ CanvasPolygonReplay.prototype.drawPolygon = function(polygonGeometry, feature) {
// always fill the polygon for hit detection
this.hitDetectionInstructions.push([
CanvasInstruction.SET_FILL_STYLE,
asString(_ol_render_canvas_.defaultFillStyle)]
asString(defaultFillStyle)]
);
if (state.strokeStyle !== undefined) {
this.hitDetectionInstructions.push([
@@ -160,7 +160,7 @@ CanvasPolygonReplay.prototype.drawMultiPolygon = function(multiPolygonGeometry,
// always fill the multi-polygon for hit detection
this.hitDetectionInstructions.push([
CanvasInstruction.SET_FILL_STYLE,
asString(_ol_render_canvas_.defaultFillStyle)
asString(defaultFillStyle)
]);
if (state.strokeStyle !== undefined) {
this.hitDetectionInstructions.push([

View File

@@ -15,7 +15,7 @@ import {transform2D} from '../../geom/flat/transform.js';
import {CANVAS_LINE_DASH} from '../../has.js';
import {isEmpty} from '../../obj.js';
import VectorContext from '../VectorContext.js';
import _ol_render_canvas_ from '../canvas.js';
import {drawImage, resetTransform, defaultPadding, defaultFillStyle, defaultStrokeStyle, defaultMiterLimit, defaultLineWidth, defaultLineJoin, defaultLineDashOffset, defaultLineDash, defaultLineCap} from '../canvas.js';
import CanvasInstruction from '../canvas/Instruction.js';
import _ol_render_replay_ from '../replay.js';
import _ol_transform_ from '../../transform.js';
@@ -165,7 +165,7 @@ const CanvasReplay = function(tolerance, maxExtent, resolution, pixelRatio, over
* @private
* @type {!ol.Transform}
*/
this.resetTransform_ = _ol_transform_.create();
this.resetTransform = _ol_transform_.create();
};
inherits(CanvasReplay, VectorContext);
@@ -296,7 +296,7 @@ CanvasReplay.prototype.replayImage_ = function(context, x, y, image,
/** @type {Array.<*>} */ (fillInstruction),
/** @type {Array.<*>} */ (strokeInstruction));
}
_ol_render_canvas_.drawImage(context, transform, opacity, image, originX, originY, w, h, x, y, scale);
drawImage(context, transform, opacity, image, originX, originY, w, h, x, y, scale);
}
};
@@ -463,7 +463,7 @@ CanvasReplay.prototype.fill_ = function(context) {
}
context.fill();
if (this.fillOrigin_) {
context.setTransform.apply(context, _ol_render_canvas_.resetTransform_);
context.setTransform.apply(context, resetTransform);
}
};
@@ -504,7 +504,6 @@ CanvasReplay.prototype.renderDeclutter_ = function(declutterGroup, feature) {
};
if (!this.declutterTree.collides(box)) {
this.declutterTree.insert(box);
const drawImage = _ol_render_canvas_.drawImage;
for (let j = 5, jj = declutterGroup.length; j < jj; ++j) {
const declutterData = /** @type {Array} */ (declutterGroup[j]);
if (declutterData) {
@@ -676,7 +675,7 @@ CanvasReplay.prototype.replay_ = function(
backgroundFill = /** @type {boolean} */ (instruction[17]);
backgroundStroke = /** @type {boolean} */ (instruction[18]);
} else {
padding = _ol_render_canvas_.defaultPadding;
padding = defaultPadding;
backgroundFill = backgroundStroke = false;
}
@@ -730,7 +729,7 @@ CanvasReplay.prototype.replay_ = function(
/** @type {number} */ (part[0]), /** @type {number} */ (part[1]), label,
anchorX, anchorY, declutterGroup, label.height, 1, 0, 0,
/** @type {number} */ (part[3]), textScale, false, label.width,
_ol_render_canvas_.defaultPadding, null, null);
defaultPadding, null, null);
}
}
if (fillKey) {
@@ -744,7 +743,7 @@ CanvasReplay.prototype.replay_ = function(
/** @type {number} */ (part[0]), /** @type {number} */ (part[1]), label,
anchorX, anchorY, declutterGroup, label.height, 1, 0, 0,
/** @type {number} */ (part[3]), textScale, false, label.width,
_ol_render_canvas_.defaultPadding, null, null);
defaultPadding, null, null);
}
}
}
@@ -915,32 +914,32 @@ CanvasReplay.prototype.setFillStrokeStyle = function(fillStyle, strokeStyle) {
if (fillStyle) {
const fillStyleColor = fillStyle.getColor();
state.fillStyle = asColorLike(fillStyleColor ?
fillStyleColor : _ol_render_canvas_.defaultFillStyle);
fillStyleColor : defaultFillStyle);
} else {
state.fillStyle = undefined;
}
if (strokeStyle) {
const strokeStyleColor = strokeStyle.getColor();
state.strokeStyle = asColorLike(strokeStyleColor ?
strokeStyleColor : _ol_render_canvas_.defaultStrokeStyle);
strokeStyleColor : defaultStrokeStyle);
const strokeStyleLineCap = strokeStyle.getLineCap();
state.lineCap = strokeStyleLineCap !== undefined ?
strokeStyleLineCap : _ol_render_canvas_.defaultLineCap;
strokeStyleLineCap : defaultLineCap;
const strokeStyleLineDash = strokeStyle.getLineDash();
state.lineDash = strokeStyleLineDash ?
strokeStyleLineDash.slice() : _ol_render_canvas_.defaultLineDash;
strokeStyleLineDash.slice() : defaultLineDash;
const strokeStyleLineDashOffset = strokeStyle.getLineDashOffset();
state.lineDashOffset = strokeStyleLineDashOffset ?
strokeStyleLineDashOffset : _ol_render_canvas_.defaultLineDashOffset;
strokeStyleLineDashOffset : defaultLineDashOffset;
const strokeStyleLineJoin = strokeStyle.getLineJoin();
state.lineJoin = strokeStyleLineJoin !== undefined ?
strokeStyleLineJoin : _ol_render_canvas_.defaultLineJoin;
strokeStyleLineJoin : defaultLineJoin;
const strokeStyleWidth = strokeStyle.getWidth();
state.lineWidth = strokeStyleWidth !== undefined ?
strokeStyleWidth : _ol_render_canvas_.defaultLineWidth;
strokeStyleWidth : defaultLineWidth;
const strokeStyleMiterLimit = strokeStyle.getMiterLimit();
state.miterLimit = strokeStyleMiterLimit !== undefined ?
strokeStyleMiterLimit : _ol_render_canvas_.defaultMiterLimit;
strokeStyleMiterLimit : defaultMiterLimit;
if (state.lineWidth > this.maxLineWidth) {
this.maxLineWidth = state.lineWidth;

View File

@@ -8,7 +8,7 @@ import {intersects} from '../../extent.js';
import {matchingChunk} from '../../geom/flat/straightchunk.js';
import GeometryType from '../../geom/GeometryType.js';
import {CANVAS_LINE_DASH, SAFARI} from '../../has.js';
import _ol_render_canvas_ from '../canvas.js';
import {labelCache, measureTextWidth, defaultTextAlign, measureTextHeight, defaultPadding, defaultLineCap, defaultLineDashOffset, defaultLineDash, defaultLineJoin, defaultFillStyle, checkFont, defaultFont, defaultLineWidth, defaultMiterLimit, defaultStrokeStyle, defaultTextBaseline} from '../canvas.js';
import CanvasInstruction from '../canvas/Instruction.js';
import CanvasReplay from '../canvas/Replay.js';
import _ol_render_replay_ from '../replay.js';
@@ -129,7 +129,6 @@ const CanvasTextReplay = function(
*/
this.widths_ = {};
const labelCache = _ol_render_canvas_.labelCache;
labelCache.prune();
};
@@ -149,7 +148,7 @@ CanvasTextReplay.measureTextWidths = function(font, lines, widths) {
let width = 0;
let currentWidth, i;
for (i = 0; i < numLines; ++i) {
currentWidth = _ol_render_canvas_.measureTextWidth(font, lines[i]);
currentWidth = measureTextWidth(font, lines[i]);
width = Math.max(width, currentWidth);
widths.push(currentWidth);
}
@@ -286,21 +285,20 @@ CanvasTextReplay.prototype.getImage = function(text, textKey, fillKey, strokeKey
let label;
const key = strokeKey + textKey + text + fillKey + this.pixelRatio;
const labelCache = _ol_render_canvas_.labelCache;
if (!labelCache.containsKey(key)) {
const strokeState = strokeKey ? this.strokeStates[strokeKey] || this.textStrokeState_ : null;
const fillState = fillKey ? this.fillStates[fillKey] || this.textFillState_ : null;
const textState = this.textStates[textKey] || this.textState_;
const pixelRatio = this.pixelRatio;
const scale = textState.scale * pixelRatio;
const align = _ol_render_replay_.TEXT_ALIGN[textState.textAlign || _ol_render_canvas_.defaultTextAlign];
const align = _ol_render_replay_.TEXT_ALIGN[textState.textAlign || defaultTextAlign];
const strokeWidth = strokeKey && strokeState.lineWidth ? strokeState.lineWidth : 0;
const lines = text.split('\n');
const numLines = lines.length;
const widths = [];
const width = CanvasTextReplay.measureTextWidths(textState.font, lines, widths);
const lineHeight = _ol_render_canvas_.measureTextHeight(textState.font);
const lineHeight = measureTextHeight(textState.font);
const height = lineHeight * numLines;
const renderWidth = (width + strokeWidth);
const context = createCanvasContext2D(
@@ -356,7 +354,7 @@ CanvasTextReplay.prototype.drawTextImage_ = function(label, begin, end) {
const textState = this.textState_;
const strokeState = this.textStrokeState_;
const pixelRatio = this.pixelRatio;
const align = _ol_render_replay_.TEXT_ALIGN[textState.textAlign || _ol_render_canvas_.defaultTextAlign];
const align = _ol_render_replay_.TEXT_ALIGN[textState.textAlign || defaultTextAlign];
const baseline = _ol_render_replay_.TEXT_ALIGN[textState.textBaseline];
const strokeWidth = strokeState && strokeState.lineWidth ? strokeState.lineWidth : 0;
@@ -366,8 +364,8 @@ CanvasTextReplay.prototype.drawTextImage_ = function(label, begin, end) {
label, (anchorX - this.textOffsetX_) * pixelRatio, (anchorY - this.textOffsetY_) * pixelRatio,
this.declutterGroup_, label.height, 1, 0, 0, this.textRotateWithView_, this.textRotation_,
1, true, label.width,
textState.padding == _ol_render_canvas_.defaultPadding ?
_ol_render_canvas_.defaultPadding : textState.padding.map(function(p) {
textState.padding == defaultPadding ?
defaultPadding : textState.padding.map(function(p) {
return p * pixelRatio;
}),
!!textState.backgroundFill, !!textState.backgroundStroke
@@ -410,7 +408,7 @@ CanvasTextReplay.prototype.drawChars_ = function(begin, end, declutterGroup) {
if (!(this.textKey_ in this.textStates)) {
this.textStates[this.textKey_] = /** @type {ol.CanvasTextState} */ ({
font: textState.font,
textAlign: textState.textAlign || _ol_render_canvas_.defaultTextAlign,
textAlign: textState.textAlign || defaultTextAlign,
scale: textState.scale
});
}
@@ -441,7 +439,7 @@ CanvasTextReplay.prototype.drawChars_ = function(begin, end, declutterGroup) {
function(text) {
let width = widths[text];
if (!width) {
width = widths[text] = _ol_render_canvas_.measureTextWidth(font, text);
width = widths[text] = measureTextWidth(font, text);
}
return width * textScale * pixelRatio;
},
@@ -453,7 +451,7 @@ CanvasTextReplay.prototype.drawChars_ = function(begin, end, declutterGroup) {
function(text) {
let width = widths[text];
if (!width) {
width = widths[text] = _ol_render_canvas_.measureTextWidth(font, text);
width = widths[text] = measureTextWidth(font, text);
}
return width * textScale;
},
@@ -481,7 +479,7 @@ CanvasTextReplay.prototype.setTextStyle = function(textStyle, declutterGroup) {
fillState = this.textFillState_ = /** @type {ol.CanvasFillState} */ ({});
}
fillState.fillStyle = asColorLike(
textFillStyle.getColor() || _ol_render_canvas_.defaultFillStyle);
textFillStyle.getColor() || defaultFillStyle);
}
const textStrokeStyle = textStyle.getStroke();
@@ -496,32 +494,32 @@ CanvasTextReplay.prototype.setTextStyle = function(textStyle, declutterGroup) {
const lineDashOffset = textStrokeStyle.getLineDashOffset();
const lineWidth = textStrokeStyle.getWidth();
const miterLimit = textStrokeStyle.getMiterLimit();
strokeState.lineCap = textStrokeStyle.getLineCap() || _ol_render_canvas_.defaultLineCap;
strokeState.lineDash = lineDash ? lineDash.slice() : _ol_render_canvas_.defaultLineDash;
strokeState.lineCap = textStrokeStyle.getLineCap() || defaultLineCap;
strokeState.lineDash = lineDash ? lineDash.slice() : defaultLineDash;
strokeState.lineDashOffset =
lineDashOffset === undefined ? _ol_render_canvas_.defaultLineDashOffset : lineDashOffset;
strokeState.lineJoin = textStrokeStyle.getLineJoin() || _ol_render_canvas_.defaultLineJoin;
lineDashOffset === undefined ? defaultLineDashOffset : lineDashOffset;
strokeState.lineJoin = textStrokeStyle.getLineJoin() || defaultLineJoin;
strokeState.lineWidth =
lineWidth === undefined ? _ol_render_canvas_.defaultLineWidth : lineWidth;
lineWidth === undefined ? defaultLineWidth : lineWidth;
strokeState.miterLimit =
miterLimit === undefined ? _ol_render_canvas_.defaultMiterLimit : miterLimit;
miterLimit === undefined ? defaultMiterLimit : miterLimit;
strokeState.strokeStyle = asColorLike(
textStrokeStyle.getColor() || _ol_render_canvas_.defaultStrokeStyle);
textStrokeStyle.getColor() || defaultStrokeStyle);
}
textState = this.textState_;
const font = textStyle.getFont() || _ol_render_canvas_.defaultFont;
_ol_render_canvas_.checkFont(font);
const font = textStyle.getFont() || defaultFont;
checkFont(font);
const textScale = textStyle.getScale();
textState.overflow = textStyle.getOverflow();
textState.font = font;
textState.maxAngle = textStyle.getMaxAngle();
textState.placement = textStyle.getPlacement();
textState.textAlign = textStyle.getTextAlign();
textState.textBaseline = textStyle.getTextBaseline() || _ol_render_canvas_.defaultTextBaseline;
textState.textBaseline = textStyle.getTextBaseline() || defaultTextBaseline;
textState.backgroundFill = textStyle.getBackgroundFill();
textState.backgroundStroke = textStyle.getBackgroundStroke();
textState.padding = textStyle.getPadding() || _ol_render_canvas_.defaultPadding;
textState.padding = textStyle.getPadding() || defaultPadding;
textState.scale = textScale === undefined ? 1 : textScale;
const textOffsetX = textStyle.getOffsetX();