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:
@@ -19,7 +19,7 @@ import _ol_webgl_Buffer_ from '../../webgl/Buffer.js';
|
||||
* @param {ol.Extent} maxExtent Max extent.
|
||||
* @struct
|
||||
*/
|
||||
var _ol_render_webgl_TextReplay_ = function(tolerance, maxExtent) {
|
||||
const _ol_render_webgl_TextReplay_ = function(tolerance, maxExtent) {
|
||||
_ol_render_webgl_TextureReplay_.call(this, tolerance, maxExtent);
|
||||
|
||||
/**
|
||||
@@ -122,10 +122,10 @@ inherits(_ol_render_webgl_TextReplay_, _ol_render_webgl_TextureReplay_);
|
||||
*/
|
||||
_ol_render_webgl_TextReplay_.prototype.drawText = function(geometry, feature) {
|
||||
if (this.text_) {
|
||||
var flatCoordinates = null;
|
||||
var offset = 0;
|
||||
var end = 2;
|
||||
var stride = 2;
|
||||
let flatCoordinates = null;
|
||||
const offset = 0;
|
||||
let end = 2;
|
||||
let stride = 2;
|
||||
switch (geometry.getType()) {
|
||||
case GeometryType.POINT:
|
||||
case GeometryType.MULTI_POINT:
|
||||
@@ -155,13 +155,13 @@ _ol_render_webgl_TextReplay_.prototype.drawText = function(geometry, feature) {
|
||||
this.startIndices.push(this.indices.length);
|
||||
this.startIndicesFeature.push(feature);
|
||||
|
||||
var glyphAtlas = this.currAtlas_;
|
||||
var lines = this.text_.split('\n');
|
||||
var textSize = this.getTextSize_(lines);
|
||||
var i, ii, j, jj, currX, currY, charArr, charInfo;
|
||||
var anchorX = Math.round(textSize[0] * this.textAlign_ - this.offsetX_);
|
||||
var anchorY = Math.round(textSize[1] * this.textBaseline_ - this.offsetY_);
|
||||
var lineWidth = (this.state_.lineWidth / 2) * this.state_.scale;
|
||||
const glyphAtlas = this.currAtlas_;
|
||||
const lines = this.text_.split('\n');
|
||||
const textSize = this.getTextSize_(lines);
|
||||
let i, ii, j, jj, currX, currY, charArr, charInfo;
|
||||
const anchorX = Math.round(textSize[0] * this.textAlign_ - this.offsetX_);
|
||||
const anchorY = Math.round(textSize[1] * this.textBaseline_ - this.offsetY_);
|
||||
const lineWidth = (this.state_.lineWidth / 2) * this.state_.scale;
|
||||
|
||||
for (i = 0, ii = lines.length; i < ii; ++i) {
|
||||
currX = 0;
|
||||
@@ -172,7 +172,7 @@ _ol_render_webgl_TextReplay_.prototype.drawText = function(geometry, feature) {
|
||||
charInfo = glyphAtlas.atlas.getInfo(charArr[j]);
|
||||
|
||||
if (charInfo) {
|
||||
var image = charInfo.image;
|
||||
const image = charInfo.image;
|
||||
|
||||
this.anchorX = anchorX - currX;
|
||||
this.anchorY = anchorY - currY;
|
||||
@@ -184,11 +184,10 @@ _ol_render_webgl_TextReplay_.prototype.drawText = function(geometry, feature) {
|
||||
this.imageHeight = image.height;
|
||||
this.imageWidth = image.width;
|
||||
|
||||
var currentImage;
|
||||
if (this.images_.length === 0) {
|
||||
this.images_.push(image);
|
||||
} else {
|
||||
currentImage = this.images_[this.images_.length - 1];
|
||||
const currentImage = this.images_[this.images_.length - 1];
|
||||
if (getUid(currentImage) != getUid(image)) {
|
||||
this.groupIndices.push(this.indices.length);
|
||||
this.images_.push(image);
|
||||
@@ -210,15 +209,15 @@ _ol_render_webgl_TextReplay_.prototype.drawText = function(geometry, feature) {
|
||||
* @return {Array.<number>} Size of the label in pixels.
|
||||
*/
|
||||
_ol_render_webgl_TextReplay_.prototype.getTextSize_ = function(lines) {
|
||||
var self = this;
|
||||
var glyphAtlas = this.currAtlas_;
|
||||
var textHeight = lines.length * glyphAtlas.height;
|
||||
const self = this;
|
||||
const glyphAtlas = this.currAtlas_;
|
||||
const textHeight = lines.length * glyphAtlas.height;
|
||||
//Split every line to an array of chars, sum up their width, and select the longest.
|
||||
var textWidth = lines.map(function(str) {
|
||||
var sum = 0;
|
||||
var i, ii;
|
||||
const textWidth = lines.map(function(str) {
|
||||
let sum = 0;
|
||||
let i, ii;
|
||||
for (i = 0, ii = str.length; i < ii; ++i) {
|
||||
var curr = str[i];
|
||||
const curr = str[i];
|
||||
if (!glyphAtlas.width[curr]) {
|
||||
self.addCharToAtlas_(curr);
|
||||
}
|
||||
@@ -241,8 +240,8 @@ _ol_render_webgl_TextReplay_.prototype.getTextSize_ = function(lines) {
|
||||
* @param {number} stride Stride.
|
||||
*/
|
||||
_ol_render_webgl_TextReplay_.prototype.drawText_ = function(flatCoordinates, offset,
|
||||
end, stride) {
|
||||
var i, ii;
|
||||
end, stride) {
|
||||
let i, ii;
|
||||
for (i = offset, ii = end; i < ii; i += stride) {
|
||||
this.drawCoordinates(flatCoordinates, offset, end, stride);
|
||||
}
|
||||
@@ -255,43 +254,43 @@ _ol_render_webgl_TextReplay_.prototype.drawText_ = function(flatCoordinates, off
|
||||
*/
|
||||
_ol_render_webgl_TextReplay_.prototype.addCharToAtlas_ = function(char) {
|
||||
if (char.length === 1) {
|
||||
var glyphAtlas = this.currAtlas_;
|
||||
var state = this.state_;
|
||||
var mCtx = this.measureCanvas_.getContext('2d');
|
||||
const glyphAtlas = this.currAtlas_;
|
||||
const state = this.state_;
|
||||
const mCtx = this.measureCanvas_.getContext('2d');
|
||||
mCtx.font = state.font;
|
||||
var width = Math.ceil(mCtx.measureText(char).width * state.scale);
|
||||
const width = Math.ceil(mCtx.measureText(char).width * state.scale);
|
||||
|
||||
var info = glyphAtlas.atlas.add(char, width, glyphAtlas.height,
|
||||
function(ctx, x, y) {
|
||||
//Parameterize the canvas
|
||||
ctx.font = /** @type {string} */ (state.font);
|
||||
ctx.fillStyle = state.fillColor;
|
||||
ctx.strokeStyle = state.strokeColor;
|
||||
ctx.lineWidth = state.lineWidth;
|
||||
ctx.lineCap = /*** @type {string} */ (state.lineCap);
|
||||
ctx.lineJoin = /** @type {string} */ (state.lineJoin);
|
||||
ctx.miterLimit = /** @type {number} */ (state.miterLimit);
|
||||
ctx.textAlign = 'left';
|
||||
ctx.textBaseline = 'top';
|
||||
if (_ol_has_.CANVAS_LINE_DASH && state.lineDash) {
|
||||
//FIXME: use pixelRatio
|
||||
ctx.setLineDash(state.lineDash);
|
||||
ctx.lineDashOffset = /** @type {number} */ (state.lineDashOffset);
|
||||
}
|
||||
if (state.scale !== 1) {
|
||||
//FIXME: use pixelRatio
|
||||
ctx.setTransform(/** @type {number} */ (state.scale), 0, 0,
|
||||
/** @type {number} */ (state.scale), 0, 0);
|
||||
}
|
||||
const info = glyphAtlas.atlas.add(char, width, glyphAtlas.height,
|
||||
function(ctx, x, y) {
|
||||
//Parameterize the canvas
|
||||
ctx.font = /** @type {string} */ (state.font);
|
||||
ctx.fillStyle = state.fillColor;
|
||||
ctx.strokeStyle = state.strokeColor;
|
||||
ctx.lineWidth = state.lineWidth;
|
||||
ctx.lineCap = /*** @type {string} */ (state.lineCap);
|
||||
ctx.lineJoin = /** @type {string} */ (state.lineJoin);
|
||||
ctx.miterLimit = /** @type {number} */ (state.miterLimit);
|
||||
ctx.textAlign = 'left';
|
||||
ctx.textBaseline = 'top';
|
||||
if (_ol_has_.CANVAS_LINE_DASH && state.lineDash) {
|
||||
//FIXME: use pixelRatio
|
||||
ctx.setLineDash(state.lineDash);
|
||||
ctx.lineDashOffset = /** @type {number} */ (state.lineDashOffset);
|
||||
}
|
||||
if (state.scale !== 1) {
|
||||
//FIXME: use pixelRatio
|
||||
ctx.setTransform(/** @type {number} */ (state.scale), 0, 0,
|
||||
/** @type {number} */ (state.scale), 0, 0);
|
||||
}
|
||||
|
||||
//Draw the character on the canvas
|
||||
if (state.strokeColor) {
|
||||
ctx.strokeText(char, x, y);
|
||||
}
|
||||
if (state.fillColor) {
|
||||
ctx.fillText(char, x, y);
|
||||
}
|
||||
});
|
||||
//Draw the character on the canvas
|
||||
if (state.strokeColor) {
|
||||
ctx.strokeText(char, x, y);
|
||||
}
|
||||
if (state.fillColor) {
|
||||
ctx.fillText(char, x, y);
|
||||
}
|
||||
});
|
||||
|
||||
if (info) {
|
||||
glyphAtlas.width[char] = width;
|
||||
@@ -304,7 +303,7 @@ _ol_render_webgl_TextReplay_.prototype.addCharToAtlas_ = function(char) {
|
||||
* @inheritDoc
|
||||
*/
|
||||
_ol_render_webgl_TextReplay_.prototype.finish = function(context) {
|
||||
var gl = context.getGL();
|
||||
const gl = context.getGL();
|
||||
|
||||
this.groupIndices.push(this.indices.length);
|
||||
this.hitDetectionGroupIndices = this.groupIndices;
|
||||
@@ -317,7 +316,7 @@ _ol_render_webgl_TextReplay_.prototype.finish = function(context) {
|
||||
|
||||
// create textures
|
||||
/** @type {Object.<string, WebGLTexture>} */
|
||||
var texturePerImage = {};
|
||||
const texturePerImage = {};
|
||||
|
||||
this.createTextures(this.textures_, this.images_, texturePerImage, gl);
|
||||
|
||||
@@ -349,16 +348,16 @@ _ol_render_webgl_TextReplay_.prototype.finish = function(context) {
|
||||
* @inheritDoc
|
||||
*/
|
||||
_ol_render_webgl_TextReplay_.prototype.setTextStyle = function(textStyle) {
|
||||
var state = this.state_;
|
||||
var textFillStyle = textStyle.getFill();
|
||||
var textStrokeStyle = textStyle.getStroke();
|
||||
const state = this.state_;
|
||||
const textFillStyle = textStyle.getFill();
|
||||
const textStrokeStyle = textStyle.getStroke();
|
||||
if (!textStyle || !textStyle.getText() || (!textFillStyle && !textStrokeStyle)) {
|
||||
this.text_ = '';
|
||||
} else {
|
||||
if (!textFillStyle) {
|
||||
state.fillColor = null;
|
||||
} else {
|
||||
var textFillStyleColor = textFillStyle.getColor();
|
||||
const textFillStyleColor = textFillStyle.getColor();
|
||||
state.fillColor = asColorLike(textFillStyleColor ?
|
||||
textFillStyleColor : _ol_render_webgl_.defaultFillStyle);
|
||||
}
|
||||
@@ -366,7 +365,7 @@ _ol_render_webgl_TextReplay_.prototype.setTextStyle = function(textStyle) {
|
||||
state.strokeColor = null;
|
||||
state.lineWidth = 0;
|
||||
} else {
|
||||
var textStrokeStyleColor = textStrokeStyle.getColor();
|
||||
const textStrokeStyleColor = textStrokeStyle.getColor();
|
||||
state.strokeColor = asColorLike(textStrokeStyleColor ?
|
||||
textStrokeStyleColor : _ol_render_webgl_.defaultStrokeStyle);
|
||||
state.lineWidth = textStrokeStyle.getWidth() || _ol_render_webgl_.defaultLineWidth;
|
||||
@@ -374,14 +373,14 @@ _ol_render_webgl_TextReplay_.prototype.setTextStyle = function(textStyle) {
|
||||
state.lineDashOffset = textStrokeStyle.getLineDashOffset() || _ol_render_webgl_.defaultLineDashOffset;
|
||||
state.lineJoin = textStrokeStyle.getLineJoin() || _ol_render_webgl_.defaultLineJoin;
|
||||
state.miterLimit = textStrokeStyle.getMiterLimit() || _ol_render_webgl_.defaultMiterLimit;
|
||||
var lineDash = textStrokeStyle.getLineDash();
|
||||
const lineDash = textStrokeStyle.getLineDash();
|
||||
state.lineDash = lineDash ? lineDash.slice() : _ol_render_webgl_.defaultLineDash;
|
||||
}
|
||||
state.font = textStyle.getFont() || _ol_render_webgl_.defaultFont;
|
||||
state.scale = textStyle.getScale() || 1;
|
||||
this.text_ = /** @type {string} */ (textStyle.getText());
|
||||
var textAlign = _ol_render_replay_.TEXT_ALIGN[textStyle.getTextAlign()];
|
||||
var textBaseline = _ol_render_replay_.TEXT_ALIGN[textStyle.getTextBaseline()];
|
||||
const textAlign = _ol_render_replay_.TEXT_ALIGN[textStyle.getTextAlign()];
|
||||
const textBaseline = _ol_render_replay_.TEXT_ALIGN[textStyle.getTextBaseline()];
|
||||
this.textAlign_ = textAlign === undefined ?
|
||||
_ol_render_webgl_.defaultTextAlign : textAlign;
|
||||
this.textBaseline_ = textBaseline === undefined ?
|
||||
@@ -402,8 +401,8 @@ _ol_render_webgl_TextReplay_.prototype.setTextStyle = function(textStyle) {
|
||||
* @return {ol.WebglGlyphAtlas} Glyph atlas.
|
||||
*/
|
||||
_ol_render_webgl_TextReplay_.prototype.getAtlas_ = function(state) {
|
||||
var params = [];
|
||||
var i;
|
||||
let params = [];
|
||||
let i;
|
||||
for (i in state) {
|
||||
if (state[i] || state[i] === 0) {
|
||||
if (Array.isArray(state[i])) {
|
||||
@@ -413,11 +412,11 @@ _ol_render_webgl_TextReplay_.prototype.getAtlas_ = function(state) {
|
||||
}
|
||||
}
|
||||
}
|
||||
var hash = this.calculateHash_(params);
|
||||
const hash = this.calculateHash_(params);
|
||||
if (!this.atlases_[hash]) {
|
||||
var mCtx = this.measureCanvas_.getContext('2d');
|
||||
const mCtx = this.measureCanvas_.getContext('2d');
|
||||
mCtx.font = state.font;
|
||||
var height = Math.ceil((mCtx.measureText('M').width * 1.5 +
|
||||
const height = Math.ceil((mCtx.measureText('M').width * 1.5 +
|
||||
state.lineWidth / 2) * state.scale);
|
||||
|
||||
this.atlases_[hash] = {
|
||||
@@ -439,8 +438,8 @@ _ol_render_webgl_TextReplay_.prototype.getAtlas_ = function(state) {
|
||||
*/
|
||||
_ol_render_webgl_TextReplay_.prototype.calculateHash_ = function(params) {
|
||||
//TODO: Create a more performant, reliable, general hash function.
|
||||
var i, ii;
|
||||
var hash = '';
|
||||
let i, ii;
|
||||
let hash = '';
|
||||
for (i = 0, ii = params.length; i < ii; ++i) {
|
||||
hash += params[i];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user