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:
Tim Schaub
2018-01-11 23:32:36 -07:00
parent 0bf2b04dee
commit ad62739a6e
684 changed files with 18120 additions and 18184 deletions

View File

@@ -21,7 +21,7 @@ import _ol_webgl_Context_ from '../../webgl/Context.js';
* @param {ol.layer.Image} imageLayer Tile layer.
* @api
*/
var WebGLImageLayerRenderer = function(mapRenderer, imageLayer) {
const WebGLImageLayerRenderer = function(mapRenderer, imageLayer) {
WebGLLayerRenderer.call(this, mapRenderer, imageLayer);
@@ -68,8 +68,8 @@ WebGLImageLayerRenderer['handles'] = function(type, layer) {
*/
WebGLImageLayerRenderer['create'] = function(mapRenderer, layer) {
return new WebGLImageLayerRenderer(
/** @type {ol.renderer.webgl.Map} */ (mapRenderer),
/** @type {ol.layer.Image} */ (layer)
/** @type {ol.renderer.webgl.Map} */ (mapRenderer),
/** @type {ol.layer.Image} */ (layer)
);
};
@@ -85,11 +85,11 @@ WebGLImageLayerRenderer.prototype.createTexture_ = function(image) {
// http://www.khronos.org/webgl/wiki/WebGL_and_OpenGL_Differences#Non-Power_of_Two_Texture_Support
// http://learningwebgl.com/blog/?p=2101
var imageElement = image.getImage();
var gl = this.mapRenderer.getGL();
const imageElement = image.getImage();
const gl = this.mapRenderer.getGL();
return _ol_webgl_Context_.createTexture(
gl, imageElement, _ol_webgl_.CLAMP_TO_EDGE, _ol_webgl_.CLAMP_TO_EDGE);
gl, imageElement, _ol_webgl_.CLAMP_TO_EDGE, _ol_webgl_.CLAMP_TO_EDGE);
};
@@ -97,21 +97,21 @@ WebGLImageLayerRenderer.prototype.createTexture_ = function(image) {
* @inheritDoc
*/
WebGLImageLayerRenderer.prototype.forEachFeatureAtCoordinate = function(coordinate, frameState, hitTolerance, callback, thisArg) {
var layer = this.getLayer();
var source = layer.getSource();
var resolution = frameState.viewState.resolution;
var rotation = frameState.viewState.rotation;
var skippedFeatureUids = frameState.skippedFeatureUids;
const layer = this.getLayer();
const source = layer.getSource();
const resolution = frameState.viewState.resolution;
const rotation = frameState.viewState.rotation;
const skippedFeatureUids = frameState.skippedFeatureUids;
return source.forEachFeatureAtCoordinate(
coordinate, resolution, rotation, hitTolerance, skippedFeatureUids,
coordinate, resolution, rotation, hitTolerance, skippedFeatureUids,
/**
/**
* @param {ol.Feature|ol.render.Feature} feature Feature.
* @return {?} Callback result.
*/
function(feature) {
return callback.call(thisArg, feature, layer);
});
function(feature) {
return callback.call(thisArg, feature, layer);
});
};
@@ -120,38 +120,38 @@ WebGLImageLayerRenderer.prototype.forEachFeatureAtCoordinate = function(coordina
*/
WebGLImageLayerRenderer.prototype.prepareFrame = function(frameState, layerState, context) {
var gl = this.mapRenderer.getGL();
const gl = this.mapRenderer.getGL();
var pixelRatio = frameState.pixelRatio;
var viewState = frameState.viewState;
var viewCenter = viewState.center;
var viewResolution = viewState.resolution;
var viewRotation = viewState.rotation;
const pixelRatio = frameState.pixelRatio;
const viewState = frameState.viewState;
const viewCenter = viewState.center;
const viewResolution = viewState.resolution;
const viewRotation = viewState.rotation;
var image = this.image_;
var texture = this.texture;
var imageLayer = /** @type {ol.layer.Image} */ (this.getLayer());
var imageSource = imageLayer.getSource();
let image = this.image_;
let texture = this.texture;
const imageLayer = /** @type {ol.layer.Image} */ (this.getLayer());
const imageSource = imageLayer.getSource();
var hints = frameState.viewHints;
const hints = frameState.viewHints;
var renderedExtent = frameState.extent;
let renderedExtent = frameState.extent;
if (layerState.extent !== undefined) {
renderedExtent = getIntersection(renderedExtent, layerState.extent);
}
if (!hints[ViewHint.ANIMATING] && !hints[ViewHint.INTERACTING] &&
!isEmpty(renderedExtent)) {
var projection = viewState.projection;
let projection = viewState.projection;
if (!ENABLE_RASTER_REPROJECTION) {
var sourceProjection = imageSource.getProjection();
const sourceProjection = imageSource.getProjection();
if (sourceProjection) {
projection = sourceProjection;
}
}
var image_ = imageSource.getImage(renderedExtent, viewResolution,
pixelRatio, projection);
const image_ = imageSource.getImage(renderedExtent, viewResolution,
pixelRatio, projection);
if (image_) {
var loaded = this.loadImage(image_);
const loaded = this.loadImage(image_);
if (loaded) {
image = image_;
texture = this.createTexture_(image_);
@@ -160,13 +160,13 @@ WebGLImageLayerRenderer.prototype.prepareFrame = function(frameState, layerState
* @param {WebGLRenderingContext} gl GL.
* @param {WebGLTexture} texture Texture.
*/
var postRenderFunction = function(gl, texture) {
const postRenderFunction = function(gl, texture) {
if (!gl.isContextLost()) {
gl.deleteTexture(texture);
}
}.bind(null, gl, this.texture);
frameState.postRenderFunctions.push(
/** @type {ol.PostRenderFunction} */ (postRenderFunction)
/** @type {ol.PostRenderFunction} */ (postRenderFunction)
);
}
}
@@ -174,15 +174,15 @@ WebGLImageLayerRenderer.prototype.prepareFrame = function(frameState, layerState
}
if (image) {
var canvas = this.mapRenderer.getContext().getCanvas();
const canvas = this.mapRenderer.getContext().getCanvas();
this.updateProjectionMatrix_(canvas.width, canvas.height,
pixelRatio, viewCenter, viewResolution, viewRotation,
image.getExtent());
pixelRatio, viewCenter, viewResolution, viewRotation,
image.getExtent());
this.hitTransformationMatrix_ = null;
// Translate and scale to flip the Y coord.
var texCoordMatrix = this.texCoordMatrix;
const texCoordMatrix = this.texCoordMatrix;
_ol_transform_.reset(texCoordMatrix);
_ol_transform_.scale(texCoordMatrix, 1, -1);
_ol_transform_.translate(texCoordMatrix, 0, -1);
@@ -206,23 +206,23 @@ WebGLImageLayerRenderer.prototype.prepareFrame = function(frameState, layerState
* @private
*/
WebGLImageLayerRenderer.prototype.updateProjectionMatrix_ = function(canvasWidth, canvasHeight, pixelRatio,
viewCenter, viewResolution, viewRotation, imageExtent) {
viewCenter, viewResolution, viewRotation, imageExtent) {
var canvasExtentWidth = canvasWidth * viewResolution;
var canvasExtentHeight = canvasHeight * viewResolution;
const canvasExtentWidth = canvasWidth * viewResolution;
const canvasExtentHeight = canvasHeight * viewResolution;
var projectionMatrix = this.projectionMatrix;
const projectionMatrix = this.projectionMatrix;
_ol_transform_.reset(projectionMatrix);
_ol_transform_.scale(projectionMatrix,
pixelRatio * 2 / canvasExtentWidth,
pixelRatio * 2 / canvasExtentHeight);
pixelRatio * 2 / canvasExtentWidth,
pixelRatio * 2 / canvasExtentHeight);
_ol_transform_.rotate(projectionMatrix, -viewRotation);
_ol_transform_.translate(projectionMatrix,
imageExtent[0] - viewCenter[0],
imageExtent[1] - viewCenter[1]);
imageExtent[0] - viewCenter[0],
imageExtent[1] - viewCenter[1]);
_ol_transform_.scale(projectionMatrix,
(imageExtent[2] - imageExtent[0]) / 2,
(imageExtent[3] - imageExtent[1]) / 2);
(imageExtent[2] - imageExtent[0]) / 2,
(imageExtent[3] - imageExtent[1]) / 2);
_ol_transform_.translate(projectionMatrix, 1, 1);
};
@@ -232,7 +232,7 @@ WebGLImageLayerRenderer.prototype.updateProjectionMatrix_ = function(canvasWidth
* @inheritDoc
*/
WebGLImageLayerRenderer.prototype.hasFeatureAtCoordinate = function(coordinate, frameState) {
var hasFeature = this.forEachFeatureAtCoordinate(coordinate, frameState, 0, TRUE, this);
const hasFeature = this.forEachFeatureAtCoordinate(coordinate, frameState, 0, TRUE, this);
return hasFeature !== undefined;
};
@@ -248,9 +248,9 @@ WebGLImageLayerRenderer.prototype.forEachLayerAtPixel = function(pixel, frameSta
if (this.getLayer().getSource().forEachFeatureAtCoordinate !== nullFunction) {
// for ImageCanvas sources use the original hit-detection logic,
// so that for example also transparent polygons are detected
var coordinate = _ol_transform_.apply(
frameState.pixelToCoordinateTransform, pixel.slice());
var hasFeature = this.forEachFeatureAtCoordinate(coordinate, frameState, 0, TRUE, this);
const coordinate = _ol_transform_.apply(
frameState.pixelToCoordinateTransform, pixel.slice());
const hasFeature = this.forEachFeatureAtCoordinate(coordinate, frameState, 0, TRUE, this);
if (hasFeature) {
return callback.call(thisArg, this.getLayer(), null);
@@ -258,16 +258,16 @@ WebGLImageLayerRenderer.prototype.forEachLayerAtPixel = function(pixel, frameSta
return undefined;
}
} else {
var imageSize =
const imageSize =
[this.image_.getImage().width, this.image_.getImage().height];
if (!this.hitTransformationMatrix_) {
this.hitTransformationMatrix_ = this.getHitTransformationMatrix_(
frameState.size, imageSize);
frameState.size, imageSize);
}
var pixelOnFrameBuffer = _ol_transform_.apply(
this.hitTransformationMatrix_, pixel.slice());
const pixelOnFrameBuffer = _ol_transform_.apply(
this.hitTransformationMatrix_, pixel.slice());
if (pixelOnFrameBuffer[0] < 0 || pixelOnFrameBuffer[0] > imageSize[0] ||
pixelOnFrameBuffer[1] < 0 || pixelOnFrameBuffer[1] > imageSize[1]) {
@@ -281,9 +281,9 @@ WebGLImageLayerRenderer.prototype.forEachLayerAtPixel = function(pixel, frameSta
this.hitCanvasContext_.clearRect(0, 0, 1, 1);
this.hitCanvasContext_.drawImage(this.image_.getImage(),
pixelOnFrameBuffer[0], pixelOnFrameBuffer[1], 1, 1, 0, 0, 1, 1);
pixelOnFrameBuffer[0], pixelOnFrameBuffer[1], 1, 1, 0, 0, 1, 1);
var imageData = this.hitCanvasContext_.getImageData(0, 0, 1, 1).data;
const imageData = this.hitCanvasContext_.getImageData(0, 0, 1, 1).data;
if (imageData[3] > 0) {
return callback.call(thisArg, this.getLayer(), imageData);
} else {
@@ -304,7 +304,7 @@ WebGLImageLayerRenderer.prototype.forEachLayerAtPixel = function(pixel, frameSta
WebGLImageLayerRenderer.prototype.getHitTransformationMatrix_ = function(mapSize, imageSize) {
// the first matrix takes a map pixel, flips the y-axis and scales to
// a range between -1 ... 1
var mapCoordTransform = _ol_transform_.create();
const mapCoordTransform = _ol_transform_.create();
_ol_transform_.translate(mapCoordTransform, -1, -1);
_ol_transform_.scale(mapCoordTransform, 2 / mapSize[0], 2 / mapSize[1]);
_ol_transform_.translate(mapCoordTransform, 0, mapSize[1]);
@@ -312,10 +312,10 @@ WebGLImageLayerRenderer.prototype.getHitTransformationMatrix_ = function(mapSize
// the second matrix is the inverse of the projection matrix used in the
// shader for drawing
var projectionMatrixInv = _ol_transform_.invert(this.projectionMatrix.slice());
const projectionMatrixInv = _ol_transform_.invert(this.projectionMatrix.slice());
// the third matrix scales to the image dimensions and flips the y-axis again
var transform = _ol_transform_.create();
const transform = _ol_transform_.create();
_ol_transform_.translate(transform, 0, imageSize[1]);
_ol_transform_.scale(transform, 1, -1);
_ol_transform_.scale(transform, imageSize[0] / 2, imageSize[1] / 2);