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:
@@ -18,7 +18,7 @@ import {add as addTransformFunc, clear as clearTransformFuncs, get as getTransfo
|
||||
* @type {Object.<ol.proj.Units, number>}
|
||||
* @api
|
||||
*/
|
||||
export var METERS_PER_UNIT = Units.METERS_PER_UNIT;
|
||||
export const METERS_PER_UNIT = Units.METERS_PER_UNIT;
|
||||
|
||||
|
||||
/**
|
||||
@@ -29,9 +29,9 @@ export var METERS_PER_UNIT = Units.METERS_PER_UNIT;
|
||||
* values).
|
||||
*/
|
||||
export function cloneTransform(input, opt_output, opt_dimension) {
|
||||
var output;
|
||||
let output;
|
||||
if (opt_output !== undefined) {
|
||||
for (var i = 0, ii = input.length; i < ii; ++i) {
|
||||
for (let i = 0, ii = input.length; i < ii; ++i) {
|
||||
opt_output[i] = input[i];
|
||||
}
|
||||
output = opt_output;
|
||||
@@ -50,7 +50,7 @@ export function cloneTransform(input, opt_output, opt_dimension) {
|
||||
*/
|
||||
export function identityTransform(input, opt_output, opt_dimension) {
|
||||
if (opt_output !== undefined && input !== opt_output) {
|
||||
for (var i = 0, ii = input.length; i < ii; ++i) {
|
||||
for (let i = 0, ii = input.length; i < ii; ++i) {
|
||||
opt_output[i] = input[i];
|
||||
}
|
||||
input = opt_output;
|
||||
@@ -90,11 +90,11 @@ export function addProjections(projections) {
|
||||
* @api
|
||||
*/
|
||||
export function get(projectionLike) {
|
||||
var projection = null;
|
||||
let projection = null;
|
||||
if (projectionLike instanceof Projection) {
|
||||
projection = projectionLike;
|
||||
} else if (typeof projectionLike === 'string') {
|
||||
var code = projectionLike;
|
||||
const code = projectionLike;
|
||||
projection = _ol_proj_projections_.get(code);
|
||||
}
|
||||
return projection;
|
||||
@@ -123,30 +123,30 @@ export function get(projectionLike) {
|
||||
*/
|
||||
export function getPointResolution(projection, resolution, point, opt_units) {
|
||||
projection = get(projection);
|
||||
var pointResolution;
|
||||
var getter = projection.getPointResolutionFunc();
|
||||
let pointResolution;
|
||||
const getter = projection.getPointResolutionFunc();
|
||||
if (getter) {
|
||||
pointResolution = getter(resolution, point);
|
||||
} else {
|
||||
var units = projection.getUnits();
|
||||
const units = projection.getUnits();
|
||||
if (units == Units.DEGREES && !opt_units || opt_units == Units.DEGREES) {
|
||||
pointResolution = resolution;
|
||||
} else {
|
||||
// Estimate point resolution by transforming the center pixel to EPSG:4326,
|
||||
// measuring its width and height on the normal sphere, and taking the
|
||||
// average of the width and height.
|
||||
var toEPSG4326 = getTransformFromProjections(projection, get('EPSG:4326'));
|
||||
var vertices = [
|
||||
const toEPSG4326 = getTransformFromProjections(projection, get('EPSG:4326'));
|
||||
let vertices = [
|
||||
point[0] - resolution / 2, point[1],
|
||||
point[0] + resolution / 2, point[1],
|
||||
point[0], point[1] - resolution / 2,
|
||||
point[0], point[1] + resolution / 2
|
||||
];
|
||||
vertices = toEPSG4326(vertices, vertices, 2);
|
||||
var width = getDistance(vertices.slice(0, 2), vertices.slice(2, 4));
|
||||
var height = getDistance(vertices.slice(4, 6), vertices.slice(6, 8));
|
||||
const width = getDistance(vertices.slice(0, 2), vertices.slice(2, 4));
|
||||
const height = getDistance(vertices.slice(4, 6), vertices.slice(6, 8));
|
||||
pointResolution = (width + height) / 2;
|
||||
var metersPerUnit = opt_units ?
|
||||
const metersPerUnit = opt_units ?
|
||||
Units.METERS_PER_UNIT[opt_units] :
|
||||
projection.getMetersPerUnit();
|
||||
if (metersPerUnit !== undefined) {
|
||||
@@ -241,10 +241,10 @@ export function createTransformFromCoordinateTransform(coordTransform) {
|
||||
* @return {Array.<number>} Output.
|
||||
*/
|
||||
function(input, opt_output, opt_dimension) {
|
||||
var length = input.length;
|
||||
var dimension = opt_dimension !== undefined ? opt_dimension : 2;
|
||||
var output = opt_output !== undefined ? opt_output : new Array(length);
|
||||
var point, i, j;
|
||||
const length = input.length;
|
||||
const dimension = opt_dimension !== undefined ? opt_dimension : 2;
|
||||
const output = opt_output !== undefined ? opt_output : new Array(length);
|
||||
let point, i, j;
|
||||
for (i = 0; i < length; i += dimension) {
|
||||
point = coordTransform([input[i], input[i + 1]]);
|
||||
output[i] = point[0];
|
||||
@@ -278,8 +278,8 @@ export function createTransformFromCoordinateTransform(coordTransform) {
|
||||
* @api
|
||||
*/
|
||||
export function addCoordinateTransforms(source, destination, forward, inverse) {
|
||||
var sourceProj = get(source);
|
||||
var destProj = get(destination);
|
||||
const sourceProj = get(source);
|
||||
const destProj = get(destination);
|
||||
addTransformFunc(sourceProj, destProj, createTransformFromCoordinateTransform(forward));
|
||||
addTransformFunc(destProj, sourceProj, createTransformFromCoordinateTransform(inverse));
|
||||
}
|
||||
@@ -296,7 +296,7 @@ export function addCoordinateTransforms(source, destination, forward, inverse) {
|
||||
*/
|
||||
export function fromLonLat(coordinate, opt_projection) {
|
||||
return transform(coordinate, 'EPSG:4326',
|
||||
opt_projection !== undefined ? opt_projection : 'EPSG:3857');
|
||||
opt_projection !== undefined ? opt_projection : 'EPSG:3857');
|
||||
}
|
||||
|
||||
|
||||
@@ -310,9 +310,9 @@ export function fromLonLat(coordinate, opt_projection) {
|
||||
* @api
|
||||
*/
|
||||
export function toLonLat(coordinate, opt_projection) {
|
||||
var lonLat = transform(coordinate,
|
||||
opt_projection !== undefined ? opt_projection : 'EPSG:3857', 'EPSG:4326');
|
||||
var lon = lonLat[0];
|
||||
const lonLat = transform(coordinate,
|
||||
opt_projection !== undefined ? opt_projection : 'EPSG:3857', 'EPSG:4326');
|
||||
const lon = lonLat[0];
|
||||
if (lon < -180 || lon > 180) {
|
||||
lonLat[0] = modulo(lon + 180, 360) - 180;
|
||||
}
|
||||
@@ -334,11 +334,11 @@ export function equivalent(projection1, projection2) {
|
||||
if (projection1 === projection2) {
|
||||
return true;
|
||||
}
|
||||
var equalUnits = projection1.getUnits() === projection2.getUnits();
|
||||
const equalUnits = projection1.getUnits() === projection2.getUnits();
|
||||
if (projection1.getCode() === projection2.getCode()) {
|
||||
return equalUnits;
|
||||
} else {
|
||||
var transformFunc = getTransformFromProjections(projection1, projection2);
|
||||
const transformFunc = getTransformFromProjections(projection1, projection2);
|
||||
return transformFunc === cloneTransform && equalUnits;
|
||||
}
|
||||
}
|
||||
@@ -354,9 +354,9 @@ export function equivalent(projection1, projection2) {
|
||||
* @return {ol.TransformFunction} Transform function.
|
||||
*/
|
||||
export function getTransformFromProjections(sourceProjection, destinationProjection) {
|
||||
var sourceCode = sourceProjection.getCode();
|
||||
var destinationCode = destinationProjection.getCode();
|
||||
var transformFunc = getTransformFunc(sourceCode, destinationCode);
|
||||
const sourceCode = sourceProjection.getCode();
|
||||
const destinationCode = destinationProjection.getCode();
|
||||
let transformFunc = getTransformFunc(sourceCode, destinationCode);
|
||||
if (!transformFunc) {
|
||||
transformFunc = identityTransform;
|
||||
}
|
||||
@@ -375,10 +375,10 @@ export function getTransformFromProjections(sourceProjection, destinationProject
|
||||
* @api
|
||||
*/
|
||||
export function getTransform(source, destination) {
|
||||
var sourceProjection = get(source);
|
||||
var destinationProjection = get(destination);
|
||||
const sourceProjection = get(source);
|
||||
const destinationProjection = get(destination);
|
||||
return getTransformFromProjections(
|
||||
sourceProjection, destinationProjection);
|
||||
sourceProjection, destinationProjection);
|
||||
}
|
||||
|
||||
|
||||
@@ -397,7 +397,7 @@ export function getTransform(source, destination) {
|
||||
* @api
|
||||
*/
|
||||
export function transform(coordinate, source, destination) {
|
||||
var transformFunc = getTransform(source, destination);
|
||||
const transformFunc = getTransform(source, destination);
|
||||
return transformFunc(coordinate, undefined, coordinate.length);
|
||||
}
|
||||
|
||||
@@ -413,7 +413,7 @@ export function transform(coordinate, source, destination) {
|
||||
* @api
|
||||
*/
|
||||
export function transformExtent(extent, source, destination) {
|
||||
var transformFunc = getTransform(source, destination);
|
||||
const transformFunc = getTransform(source, destination);
|
||||
return applyTransform(extent, transformFunc);
|
||||
}
|
||||
|
||||
@@ -427,8 +427,8 @@ export function transformExtent(extent, source, destination) {
|
||||
* @return {ol.Coordinate} Point.
|
||||
*/
|
||||
export function transformWithProjections(point, sourceProjection, destinationProjection) {
|
||||
var transformFunc = getTransformFromProjections(
|
||||
sourceProjection, destinationProjection);
|
||||
const transformFunc = getTransformFromProjections(
|
||||
sourceProjection, destinationProjection);
|
||||
return transformFunc(point);
|
||||
}
|
||||
|
||||
@@ -445,10 +445,10 @@ export function addCommon() {
|
||||
// Add transformations to convert EPSG:4326 like coordinates to EPSG:3857 like
|
||||
// coordinates and back.
|
||||
addEquivalentTransforms(
|
||||
EPSG4326.PROJECTIONS,
|
||||
EPSG3857.PROJECTIONS,
|
||||
EPSG3857.fromEPSG4326,
|
||||
EPSG3857.toEPSG4326);
|
||||
EPSG4326.PROJECTIONS,
|
||||
EPSG3857.PROJECTIONS,
|
||||
EPSG3857.fromEPSG4326,
|
||||
EPSG3857.toEPSG4326);
|
||||
}
|
||||
|
||||
addCommon();
|
||||
|
||||
Reference in New Issue
Block a user