Make code prettier

This updates ESLint and our shared eslint-config-openlayers to use Prettier.  Most formatting changes were automatically applied with this:

    npm run lint -- --fix

A few manual changes were required:

 * In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
 * In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason.  While editing this, I reworked `ExampleBuilder` to be a class.
 * In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
This commit is contained in:
Tim Schaub
2020-04-06 12:25:12 -06:00
parent 53b48baf62
commit 054af09032
790 changed files with 46833 additions and 33765 deletions
+56 -46
View File
@@ -1,14 +1,13 @@
import Map from '../src/ol/Map.js';
import View from '../src/ol/View.js';
import {Image as ImageLayer, Tile as TileLayer} from '../src/ol/layer.js';
import XYZ from '../src/ol/source/XYZ.js';
import RasterSource from '../src/ol/source/Raster.js';
import View from '../src/ol/View.js';
import XYZ from '../src/ol/source/XYZ.js';
import {Image as ImageLayer, Tile as TileLayer} from '../src/ol/layer.js';
const minVgi = 0;
const maxVgi = 0.25;
const bins = 10;
/**
* Calculate the Vegetation Greenness Index (VGI) from an input pixel. This
* is a rough estimate assuming that pixel values correspond to reflectance.
@@ -22,7 +21,6 @@ function vgi(pixel) {
return (2 * g - r - b) / (2 * g + r + b);
}
/**
* Summarize values for a histogram.
* @param {numver} value A VGI value.
@@ -42,23 +40,22 @@ function summarize(value, counts) {
}
}
/**
* Use aerial imagery as the input data for the raster source.
*/
const key = 'get_your_own_D6rA4zTHduk6KOKTXzGB';
const attributions = '<a href="https://www.maptiler.com/copyright/" target="_blank">&copy; MapTiler</a> ' +
const attributions =
'<a href="https://www.maptiler.com/copyright/" target="_blank">&copy; MapTiler</a> ' +
'<a href="https://www.openstreetmap.org/copyright" target="_blank">&copy; OpenStreetMap contributors</a>';
const aerial = new XYZ({
attributions: attributions,
url: 'https://api.maptiler.com/tiles/satellite/{z}/{x}/{y}.jpg?key=' + key,
maxZoom: 20,
crossOrigin: ''
crossOrigin: '',
});
/**
* Create a raster source where pixels with VGI values above a threshold will
* be colored green.
@@ -71,7 +68,7 @@ const raster = new RasterSource({
* @param {Object} data User data object.
* @return {Array} The output pixel.
*/
operation: function(pixels, data) {
operation: function (pixels, data) {
const pixel = pixels[0];
const value = vgi(pixel);
summarize(value, data.counts);
@@ -87,8 +84,8 @@ const raster = new RasterSource({
},
lib: {
vgi: vgi,
summarize: summarize
}
summarize: summarize,
},
});
raster.set('threshold', 0.1);
@@ -101,38 +98,37 @@ function createCounts(min, max, num) {
min: min,
max: max,
values: values,
delta: (max - min) / num
delta: (max - min) / num,
};
}
raster.on('beforeoperations', function(event) {
raster.on('beforeoperations', function (event) {
event.data.counts = createCounts(minVgi, maxVgi, bins);
event.data.threshold = raster.get('threshold');
});
raster.on('afteroperations', function(event) {
raster.on('afteroperations', function (event) {
schedulePlot(event.resolution, event.data.counts, event.data.threshold);
});
const map = new Map({
layers: [
new TileLayer({
source: aerial
source: aerial,
}),
new ImageLayer({
source: raster
})
source: raster,
}),
],
target: 'map',
view: new View({
center: [-9651695, 4937351],
zoom: 13,
minZoom: 12,
maxZoom: 19
})
maxZoom: 19,
}),
});
let timer = null;
function schedulePlot(resolution, counts, threshold) {
if (timer) {
@@ -144,17 +140,19 @@ function schedulePlot(resolution, counts, threshold) {
const barWidth = 15;
const plotHeight = 150;
const chart = d3.select('#plot').append('svg')
const chart = d3
.select('#plot')
.append('svg')
.attr('width', barWidth * bins)
.attr('height', plotHeight);
const chartRect = chart.node().getBoundingClientRect();
const tip = d3.select(document.body).append('div')
.attr('class', 'tip');
const tip = d3.select(document.body).append('div').attr('class', 'tip');
function plot(resolution, counts, threshold) {
const yScale = d3.scaleLinear()
const yScale = d3
.scaleLinear()
.domain([0, d3.max(counts.values)])
.range([0, plotHeight]);
@@ -162,49 +160,61 @@ function plot(resolution, counts, threshold) {
bar.enter().append('rect');
bar.attr('class', function(count, index) {
const value = counts.min + (index * counts.delta);
return 'bar' + (value >= threshold ? ' selected' : '');
})
bar
.attr('class', function (count, index) {
const value = counts.min + index * counts.delta;
return 'bar' + (value >= threshold ? ' selected' : '');
})
.attr('width', barWidth - 2);
bar.transition().attr('transform', function(value, index) {
return 'translate(' + (index * barWidth) + ', ' +
(plotHeight - yScale(value)) + ')';
})
bar
.transition()
.attr('transform', function (value, index) {
return (
'translate(' +
index * barWidth +
', ' +
(plotHeight - yScale(value)) +
')'
);
})
.attr('height', yScale);
bar.on('mousemove', function(count, index) {
const threshold = counts.min + (index * counts.delta);
bar.on('mousemove', function (count, index) {
const threshold = counts.min + index * counts.delta;
if (raster.get('threshold') !== threshold) {
raster.set('threshold', threshold);
raster.changed();
}
});
bar.on('mouseover', function(count, index) {
bar.on('mouseover', function (count, index) {
let area = 0;
for (let i = counts.values.length - 1; i >= index; --i) {
area += resolution * resolution * counts.values[i];
}
tip.html(message(counts.min + (index * counts.delta), area));
tip.html(message(counts.min + index * counts.delta, area));
tip.style('display', 'block');
tip.transition().style({
left: (chartRect.left + (index * barWidth) + (barWidth / 2)) + 'px',
top: (d3.event.y - 60) + 'px',
opacity: 1
left: chartRect.left + index * barWidth + barWidth / 2 + 'px',
top: d3.event.y - 60 + 'px',
opacity: 1,
});
});
bar.on('mouseout', function() {
tip.transition().style('opacity', 0).each('end', function() {
tip.style('display', 'none');
});
bar.on('mouseout', function () {
tip
.transition()
.style('opacity', 0)
.each('end', function () {
tip.style('display', 'none');
});
});
}
function message(value, area) {
const acres = (area / 4046.86).toFixed(0).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
const acres = (area / 4046.86)
.toFixed(0)
.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
return acres + ' acres at<br>' + value.toFixed(2) + ' VGI or above';
}