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

@@ -8,38 +8,39 @@ import BingMaps from '../src/ol/source/BingMaps.js';
import RasterSource from '../src/ol/source/Raster.js';
function growRegion(inputs, data) {
var image = inputs[0];
var seed = data.pixel;
var delta = parseInt(data.delta);
const image = inputs[0];
let seed = data.pixel;
const delta = parseInt(data.delta);
if (!seed) {
return image;
}
seed = seed.map(Math.round);
var width = image.width;
var height = image.height;
var inputData = image.data;
var outputData = new Uint8ClampedArray(inputData);
var seedIdx = (seed[1] * width + seed[0]) * 4;
var seedR = inputData[seedIdx];
var seedG = inputData[seedIdx + 1];
var seedB = inputData[seedIdx + 2];
var edge = [seed];
const width = image.width;
const height = image.height;
const inputData = image.data;
const outputData = new Uint8ClampedArray(inputData);
const seedIdx = (seed[1] * width + seed[0]) * 4;
const seedR = inputData[seedIdx];
const seedG = inputData[seedIdx + 1];
const seedB = inputData[seedIdx + 2];
let edge = [seed];
while (edge.length) {
var newedge = [];
for (var i = 0, ii = edge.length; i < ii; i++) {
const newedge = [];
for (let i = 0, ii = edge.length; i < ii; i++) {
// As noted in the Raster source constructor, this function is provided
// using the `lib` option. Other functions will NOT be visible unless
// provided using the `lib` option.
var next = next4Edges(edge[i]);
for (var j = 0, jj = next.length; j < jj; j++) {
var s = next[j][0], t = next[j][1];
const next = next4Edges(edge[i]);
for (let j = 0, jj = next.length; j < jj; j++) {
const s = next[j][0];
const t = next[j][1];
if (s >= 0 && s < width && t >= 0 && t < height) {
var ci = (t * width + s) * 4;
var cr = inputData[ci];
var cg = inputData[ci + 1];
var cb = inputData[ci + 2];
var ca = inputData[ci + 3];
const ci = (t * width + s) * 4;
const cr = inputData[ci];
const cg = inputData[ci + 1];
const cb = inputData[ci + 2];
const ca = inputData[ci + 3];
// if alpha is zero, carry on
if (ca === 0) {
continue;
@@ -63,7 +64,8 @@ function growRegion(inputs, data) {
}
function next4Edges(edge) {
var x = edge[0], y = edge[1];
const x = edge[0];
const y = edge[1];
return [
[x + 1, y],
[x - 1, y],
@@ -72,13 +74,13 @@ function next4Edges(edge) {
];
}
var key = 'As1HiMj1PvLPlqc_gtM7AqZfBL8ZL3VrjaS3zIb22Uvb9WKhuJObROC-qUpa81U5';
const key = 'As1HiMj1PvLPlqc_gtM7AqZfBL8ZL3VrjaS3zIb22Uvb9WKhuJObROC-qUpa81U5';
var imagery = new TileLayer({
const imagery = new TileLayer({
source: new BingMaps({key: key, imagerySet: 'Aerial'})
});
var raster = new RasterSource({
const raster = new RasterSource({
sources: [imagery.getSource()],
operationType: 'image',
operation: growRegion,
@@ -89,12 +91,12 @@ var raster = new RasterSource({
}
});
var rasterImage = new ImageLayer({
const rasterImage = new ImageLayer({
opacity: 0.7,
source: raster
});
var map = new Map({
const map = new Map({
layers: [imagery, rasterImage],
target: 'map',
view: new View({
@@ -103,18 +105,18 @@ var map = new Map({
})
});
var coordinate;
let coordinate;
map.on('click', function(event) {
coordinate = event.coordinate;
raster.changed();
});
var thresholdControl = document.getElementById('threshold');
const thresholdControl = document.getElementById('threshold');
raster.on('beforeoperations', function(event) {
// the event.data object will be passed to operations
var data = event.data;
const data = event.data;
data.delta = thresholdControl.value;
if (coordinate) {
data.pixel = map.getPixelFromCoordinate(coordinate);