Use blocked scoped variables
In addition to using const and let, this also upgrades our linter config and removes lint (mostly whitespace).
This commit is contained in:
@@ -25,10 +25,10 @@ import TextPlacement from '../../style/TextPlacement.js';
|
||||
* @param {?} declutterTree Declutter tree.
|
||||
* @struct
|
||||
*/
|
||||
var _ol_render_canvas_TextReplay_ = function(
|
||||
tolerance, maxExtent, resolution, pixelRatio, overlaps, declutterTree) {
|
||||
const _ol_render_canvas_TextReplay_ = function(
|
||||
tolerance, maxExtent, resolution, pixelRatio, overlaps, declutterTree) {
|
||||
_ol_render_canvas_Replay_.call(this,
|
||||
tolerance, maxExtent, resolution, pixelRatio, overlaps, declutterTree);
|
||||
tolerance, maxExtent, resolution, pixelRatio, overlaps, declutterTree);
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -129,7 +129,7 @@ var _ol_render_canvas_TextReplay_ = function(
|
||||
*/
|
||||
this.widths_ = {};
|
||||
|
||||
var labelCache = _ol_render_canvas_.labelCache;
|
||||
const labelCache = _ol_render_canvas_.labelCache;
|
||||
labelCache.prune();
|
||||
|
||||
};
|
||||
@@ -145,9 +145,9 @@ inherits(_ol_render_canvas_TextReplay_, _ol_render_canvas_Replay_);
|
||||
* @return {number} Width of the whole text.
|
||||
*/
|
||||
_ol_render_canvas_TextReplay_.measureTextWidths = function(font, lines, widths) {
|
||||
var numLines = lines.length;
|
||||
var width = 0;
|
||||
var currentWidth, i;
|
||||
const numLines = lines.length;
|
||||
let width = 0;
|
||||
let currentWidth, i;
|
||||
for (i = 0; i < numLines; ++i) {
|
||||
currentWidth = _ol_render_canvas_.measureTextWidth(font, lines[i]);
|
||||
width = Math.max(width, currentWidth);
|
||||
@@ -161,26 +161,26 @@ _ol_render_canvas_TextReplay_.measureTextWidths = function(font, lines, widths)
|
||||
* @inheritDoc
|
||||
*/
|
||||
_ol_render_canvas_TextReplay_.prototype.drawText = function(geometry, feature) {
|
||||
var fillState = this.textFillState_;
|
||||
var strokeState = this.textStrokeState_;
|
||||
var textState = this.textState_;
|
||||
const fillState = this.textFillState_;
|
||||
const strokeState = this.textStrokeState_;
|
||||
const textState = this.textState_;
|
||||
if (this.text_ === '' || !textState || (!fillState && !strokeState)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var begin = this.coordinates.length;
|
||||
let begin = this.coordinates.length;
|
||||
|
||||
var geometryType = geometry.getType();
|
||||
var flatCoordinates = null;
|
||||
var end = 2;
|
||||
var stride = 2;
|
||||
var i, ii;
|
||||
const geometryType = geometry.getType();
|
||||
let flatCoordinates = null;
|
||||
let end = 2;
|
||||
let stride = 2;
|
||||
let i, ii;
|
||||
|
||||
if (textState.placement === TextPlacement.LINE) {
|
||||
if (!intersects(this.getBufferedMaxExtent(), geometry.getExtent())) {
|
||||
return;
|
||||
}
|
||||
var ends;
|
||||
let ends;
|
||||
flatCoordinates = geometry.getFlatCoordinates();
|
||||
stride = geometry.getStride();
|
||||
if (geometryType == GeometryType.LINE_STRING) {
|
||||
@@ -190,20 +190,20 @@ _ol_render_canvas_TextReplay_.prototype.drawText = function(geometry, feature) {
|
||||
} else if (geometryType == GeometryType.POLYGON) {
|
||||
ends = geometry.getEnds().slice(0, 1);
|
||||
} else if (geometryType == GeometryType.MULTI_POLYGON) {
|
||||
var endss = geometry.getEndss();
|
||||
const endss = geometry.getEndss();
|
||||
ends = [];
|
||||
for (i = 0, ii = endss.length; i < ii; ++i) {
|
||||
ends.push(endss[i][0]);
|
||||
}
|
||||
}
|
||||
this.beginGeometry(geometry, feature);
|
||||
var textAlign = textState.textAlign;
|
||||
var flatOffset = 0;
|
||||
var flatEnd;
|
||||
for (var o = 0, oo = ends.length; o < oo; ++o) {
|
||||
const textAlign = textState.textAlign;
|
||||
let flatOffset = 0;
|
||||
let flatEnd;
|
||||
for (let o = 0, oo = ends.length; o < oo; ++o) {
|
||||
if (textAlign == undefined) {
|
||||
var range = _ol_geom_flat_straightchunk_.lineString(
|
||||
textState.maxAngle, flatCoordinates, flatOffset, ends[o], stride);
|
||||
const range = _ol_geom_flat_straightchunk_.lineString(
|
||||
textState.maxAngle, flatCoordinates, flatOffset, ends[o], stride);
|
||||
flatOffset = range[0];
|
||||
flatEnd = range[1];
|
||||
} else {
|
||||
@@ -220,8 +220,8 @@ _ol_render_canvas_TextReplay_.prototype.drawText = function(geometry, feature) {
|
||||
this.endGeometry(geometry, feature);
|
||||
|
||||
} else {
|
||||
var label = this.getImage(this.text_, this.textKey_, this.fillKey_, this.strokeKey_);
|
||||
var width = label.width / this.pixelRatio;
|
||||
const label = this.getImage(this.text_, this.textKey_, this.fillKey_, this.strokeKey_);
|
||||
const width = label.width / this.pixelRatio;
|
||||
switch (geometryType) {
|
||||
case GeometryType.POINT:
|
||||
case GeometryType.MULTI_POINT:
|
||||
@@ -246,7 +246,7 @@ _ol_render_canvas_TextReplay_.prototype.drawText = function(geometry, feature) {
|
||||
stride = 3;
|
||||
break;
|
||||
case GeometryType.MULTI_POLYGON:
|
||||
var interiorPoints = /** @type {ol.geom.MultiPolygon} */ (geometry).getFlatInteriorPoints();
|
||||
const interiorPoints = /** @type {ol.geom.MultiPolygon} */ (geometry).getFlatInteriorPoints();
|
||||
flatCoordinates = [];
|
||||
for (i = 0, ii = interiorPoints.length; i < ii; i += 3) {
|
||||
if (textState.overflow || interiorPoints[i + 2] / this.resolution >= width) {
|
||||
@@ -283,29 +283,29 @@ _ol_render_canvas_TextReplay_.prototype.drawText = function(geometry, feature) {
|
||||
* @return {HTMLCanvasElement} Image.
|
||||
*/
|
||||
_ol_render_canvas_TextReplay_.prototype.getImage = function(text, textKey, fillKey, strokeKey) {
|
||||
var label;
|
||||
var key = strokeKey + textKey + text + fillKey + this.pixelRatio;
|
||||
let label;
|
||||
const key = strokeKey + textKey + text + fillKey + this.pixelRatio;
|
||||
|
||||
var labelCache = _ol_render_canvas_.labelCache;
|
||||
const labelCache = _ol_render_canvas_.labelCache;
|
||||
if (!labelCache.containsKey(key)) {
|
||||
var strokeState = strokeKey ? this.strokeStates[strokeKey] || this.textStrokeState_ : null;
|
||||
var fillState = fillKey ? this.fillStates[fillKey] || this.textFillState_ : null;
|
||||
var textState = this.textStates[textKey] || this.textState_;
|
||||
var pixelRatio = this.pixelRatio;
|
||||
var scale = textState.scale * pixelRatio;
|
||||
var align = _ol_render_replay_.TEXT_ALIGN[textState.textAlign || _ol_render_canvas_.defaultTextAlign];
|
||||
var strokeWidth = strokeKey && strokeState.lineWidth ? strokeState.lineWidth : 0;
|
||||
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 strokeWidth = strokeKey && strokeState.lineWidth ? strokeState.lineWidth : 0;
|
||||
|
||||
var lines = text.split('\n');
|
||||
var numLines = lines.length;
|
||||
var widths = [];
|
||||
var width = _ol_render_canvas_TextReplay_.measureTextWidths(textState.font, lines, widths);
|
||||
var lineHeight = _ol_render_canvas_.measureTextHeight(textState.font);
|
||||
var height = lineHeight * numLines;
|
||||
var renderWidth = (width + strokeWidth);
|
||||
var context = createCanvasContext2D(
|
||||
Math.ceil(renderWidth * scale),
|
||||
Math.ceil((height + strokeWidth) * scale));
|
||||
const lines = text.split('\n');
|
||||
const numLines = lines.length;
|
||||
const widths = [];
|
||||
const width = _ol_render_canvas_TextReplay_.measureTextWidths(textState.font, lines, widths);
|
||||
const lineHeight = _ol_render_canvas_.measureTextHeight(textState.font);
|
||||
const height = lineHeight * numLines;
|
||||
const renderWidth = (width + strokeWidth);
|
||||
const context = createCanvasContext2D(
|
||||
Math.ceil(renderWidth * scale),
|
||||
Math.ceil((height + strokeWidth) * scale));
|
||||
label = context.canvas;
|
||||
labelCache.set(key, label);
|
||||
if (scale != 1) {
|
||||
@@ -328,9 +328,9 @@ _ol_render_canvas_TextReplay_.prototype.getImage = function(text, textKey, fillK
|
||||
}
|
||||
context.textBaseline = 'middle';
|
||||
context.textAlign = 'center';
|
||||
var leftRight = (0.5 - align);
|
||||
var x = align * label.width / scale + leftRight * strokeWidth;
|
||||
var i;
|
||||
const leftRight = (0.5 - align);
|
||||
const x = align * label.width / scale + leftRight * strokeWidth;
|
||||
let i;
|
||||
if (strokeKey) {
|
||||
for (i = 0; i < numLines; ++i) {
|
||||
context.strokeText(lines[i], x + leftRight * widths[i], 0.5 * (strokeWidth + lineHeight) + i * lineHeight);
|
||||
@@ -353,15 +353,15 @@ _ol_render_canvas_TextReplay_.prototype.getImage = function(text, textKey, fillK
|
||||
* @param {number} end End.
|
||||
*/
|
||||
_ol_render_canvas_TextReplay_.prototype.drawTextImage_ = function(label, begin, end) {
|
||||
var textState = this.textState_;
|
||||
var strokeState = this.textStrokeState_;
|
||||
var pixelRatio = this.pixelRatio;
|
||||
var align = _ol_render_replay_.TEXT_ALIGN[textState.textAlign || _ol_render_canvas_.defaultTextAlign];
|
||||
var baseline = _ol_render_replay_.TEXT_ALIGN[textState.textBaseline];
|
||||
var strokeWidth = strokeState && strokeState.lineWidth ? strokeState.lineWidth : 0;
|
||||
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 baseline = _ol_render_replay_.TEXT_ALIGN[textState.textBaseline];
|
||||
const strokeWidth = strokeState && strokeState.lineWidth ? strokeState.lineWidth : 0;
|
||||
|
||||
var anchorX = align * label.width / pixelRatio + 2 * (0.5 - align) * strokeWidth;
|
||||
var anchorY = baseline * label.height / pixelRatio + 2 * (0.5 - baseline) * strokeWidth;
|
||||
const anchorX = align * label.width / pixelRatio + 2 * (0.5 - align) * strokeWidth;
|
||||
const anchorY = baseline * label.height / pixelRatio + 2 * (0.5 - baseline) * strokeWidth;
|
||||
this.instructions.push([_ol_render_canvas_Instruction_.DRAW_IMAGE, begin, end,
|
||||
label, (anchorX - this.textOffsetX_) * pixelRatio, (anchorY - this.textOffsetY_) * pixelRatio,
|
||||
this.declutterGroup_, label.height, 1, 0, 0, this.textRotateWithView_, this.textRotation_,
|
||||
@@ -388,11 +388,11 @@ _ol_render_canvas_TextReplay_.prototype.drawTextImage_ = function(label, begin,
|
||||
* @param {ol.DeclutterGroup} declutterGroup Declutter group.
|
||||
*/
|
||||
_ol_render_canvas_TextReplay_.prototype.drawChars_ = function(begin, end, declutterGroup) {
|
||||
var strokeState = this.textStrokeState_;
|
||||
var textState = this.textState_;
|
||||
var fillState = this.textFillState_;
|
||||
const strokeState = this.textStrokeState_;
|
||||
const textState = this.textState_;
|
||||
const fillState = this.textFillState_;
|
||||
|
||||
var strokeKey = this.strokeKey_;
|
||||
const strokeKey = this.strokeKey_;
|
||||
if (strokeState) {
|
||||
if (!(strokeKey in this.strokeStates)) {
|
||||
this.strokeStates[strokeKey] = /** @type {ol.CanvasStrokeState} */ ({
|
||||
@@ -406,7 +406,7 @@ _ol_render_canvas_TextReplay_.prototype.drawChars_ = function(begin, end, declut
|
||||
});
|
||||
}
|
||||
}
|
||||
var textKey = this.textKey_;
|
||||
const textKey = this.textKey_;
|
||||
if (!(this.textKey_ in this.textStates)) {
|
||||
this.textStates[this.textKey_] = /** @type {ol.CanvasTextState} */ ({
|
||||
font: textState.font,
|
||||
@@ -414,7 +414,7 @@ _ol_render_canvas_TextReplay_.prototype.drawChars_ = function(begin, end, declut
|
||||
scale: textState.scale
|
||||
});
|
||||
}
|
||||
var fillKey = this.fillKey_;
|
||||
const fillKey = this.fillKey_;
|
||||
if (fillState) {
|
||||
if (!(fillKey in this.fillStates)) {
|
||||
this.fillStates[fillKey] = /** @type {ol.CanvasFillState} */ ({
|
||||
@@ -423,15 +423,15 @@ _ol_render_canvas_TextReplay_.prototype.drawChars_ = function(begin, end, declut
|
||||
}
|
||||
}
|
||||
|
||||
var pixelRatio = this.pixelRatio;
|
||||
var baseline = _ol_render_replay_.TEXT_ALIGN[textState.textBaseline];
|
||||
const pixelRatio = this.pixelRatio;
|
||||
const baseline = _ol_render_replay_.TEXT_ALIGN[textState.textBaseline];
|
||||
|
||||
var offsetY = this.textOffsetY_ * pixelRatio;
|
||||
var text = this.text_;
|
||||
var font = textState.font;
|
||||
var textScale = textState.scale;
|
||||
var strokeWidth = strokeState ? strokeState.lineWidth * textScale / 2 : 0;
|
||||
var widths = this.widths_[font];
|
||||
const offsetY = this.textOffsetY_ * pixelRatio;
|
||||
const text = this.text_;
|
||||
const font = textState.font;
|
||||
const textScale = textState.scale;
|
||||
const strokeWidth = strokeState ? strokeState.lineWidth * textScale / 2 : 0;
|
||||
let widths = this.widths_[font];
|
||||
if (!widths) {
|
||||
this.widths_[font] = widths = {};
|
||||
}
|
||||
@@ -439,7 +439,7 @@ _ol_render_canvas_TextReplay_.prototype.drawChars_ = function(begin, end, declut
|
||||
begin, end, baseline, declutterGroup,
|
||||
textState.overflow, fillKey, textState.maxAngle,
|
||||
function(text) {
|
||||
var width = widths[text];
|
||||
let width = widths[text];
|
||||
if (!width) {
|
||||
width = widths[text] = _ol_render_canvas_.measureTextWidth(font, text);
|
||||
}
|
||||
@@ -451,7 +451,7 @@ _ol_render_canvas_TextReplay_.prototype.drawChars_ = function(begin, end, declut
|
||||
begin, end, baseline, declutterGroup,
|
||||
textState.overflow, fillKey, textState.maxAngle,
|
||||
function(text) {
|
||||
var width = widths[text];
|
||||
let width = widths[text];
|
||||
if (!width) {
|
||||
width = widths[text] = _ol_render_canvas_.measureTextWidth(font, text);
|
||||
}
|
||||
@@ -466,13 +466,13 @@ _ol_render_canvas_TextReplay_.prototype.drawChars_ = function(begin, end, declut
|
||||
* @inheritDoc
|
||||
*/
|
||||
_ol_render_canvas_TextReplay_.prototype.setTextStyle = function(textStyle, declutterGroup) {
|
||||
var textState, fillState, strokeState;
|
||||
let textState, fillState, strokeState;
|
||||
if (!textStyle) {
|
||||
this.text_ = '';
|
||||
} else {
|
||||
this.declutterGroup_ = /** @type {ol.DeclutterGroup} */ (declutterGroup);
|
||||
|
||||
var textFillStyle = textStyle.getFill();
|
||||
const textFillStyle = textStyle.getFill();
|
||||
if (!textFillStyle) {
|
||||
fillState = this.textFillState_ = null;
|
||||
} else {
|
||||
@@ -481,10 +481,10 @@ _ol_render_canvas_TextReplay_.prototype.setTextStyle = function(textStyle, declu
|
||||
fillState = this.textFillState_ = /** @type {ol.CanvasFillState} */ ({});
|
||||
}
|
||||
fillState.fillStyle = asColorLike(
|
||||
textFillStyle.getColor() || _ol_render_canvas_.defaultFillStyle);
|
||||
textFillStyle.getColor() || _ol_render_canvas_.defaultFillStyle);
|
||||
}
|
||||
|
||||
var textStrokeStyle = textStyle.getStroke();
|
||||
const textStrokeStyle = textStyle.getStroke();
|
||||
if (!textStrokeStyle) {
|
||||
strokeState = this.textStrokeState_ = null;
|
||||
} else {
|
||||
@@ -492,10 +492,10 @@ _ol_render_canvas_TextReplay_.prototype.setTextStyle = function(textStyle, declu
|
||||
if (!strokeState) {
|
||||
strokeState = this.textStrokeState_ = /** @type {ol.CanvasStrokeState} */ ({});
|
||||
}
|
||||
var lineDash = textStrokeStyle.getLineDash();
|
||||
var lineDashOffset = textStrokeStyle.getLineDashOffset();
|
||||
var lineWidth = textStrokeStyle.getWidth();
|
||||
var miterLimit = textStrokeStyle.getMiterLimit();
|
||||
const lineDash = textStrokeStyle.getLineDash();
|
||||
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.lineDashOffset =
|
||||
@@ -506,13 +506,13 @@ _ol_render_canvas_TextReplay_.prototype.setTextStyle = function(textStyle, declu
|
||||
strokeState.miterLimit =
|
||||
miterLimit === undefined ? _ol_render_canvas_.defaultMiterLimit : miterLimit;
|
||||
strokeState.strokeStyle = asColorLike(
|
||||
textStrokeStyle.getColor() || _ol_render_canvas_.defaultStrokeStyle);
|
||||
textStrokeStyle.getColor() || _ol_render_canvas_.defaultStrokeStyle);
|
||||
}
|
||||
|
||||
textState = this.textState_;
|
||||
var font = textStyle.getFont() || _ol_render_canvas_.defaultFont;
|
||||
const font = textStyle.getFont() || _ol_render_canvas_.defaultFont;
|
||||
_ol_render_canvas_.checkFont(font);
|
||||
var textScale = textStyle.getScale();
|
||||
const textScale = textStyle.getScale();
|
||||
textState.overflow = textStyle.getOverflow();
|
||||
textState.font = font;
|
||||
textState.maxAngle = textStyle.getMaxAngle();
|
||||
@@ -524,10 +524,10 @@ _ol_render_canvas_TextReplay_.prototype.setTextStyle = function(textStyle, declu
|
||||
textState.padding = textStyle.getPadding() || _ol_render_canvas_.defaultPadding;
|
||||
textState.scale = textScale === undefined ? 1 : textScale;
|
||||
|
||||
var textOffsetX = textStyle.getOffsetX();
|
||||
var textOffsetY = textStyle.getOffsetY();
|
||||
var textRotateWithView = textStyle.getRotateWithView();
|
||||
var textRotation = textStyle.getRotation();
|
||||
const textOffsetX = textStyle.getOffsetX();
|
||||
const textOffsetY = textStyle.getOffsetY();
|
||||
const textRotateWithView = textStyle.getRotateWithView();
|
||||
const textRotation = textStyle.getRotation();
|
||||
this.text_ = textStyle.getText() || '';
|
||||
this.textOffsetX_ = textOffsetX === undefined ? 0 : textOffsetX;
|
||||
this.textOffsetY_ = textOffsetY === undefined ? 0 : textOffsetY;
|
||||
|
||||
Reference in New Issue
Block a user