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:
@@ -1,34 +1,37 @@
|
||||
import Map from '../src/ol/Map.js';
|
||||
import View from '../src/ol/View.js';
|
||||
import TileLayer from '../src/ol/layer/Tile.js';
|
||||
import TileJSON from '../src/ol/source/TileJSON.js';
|
||||
import Feature from '../src/ol/Feature.js';
|
||||
import Map from '../src/ol/Map.js';
|
||||
import Point from '../src/ol/geom/Point.js';
|
||||
import TileJSON from '../src/ol/source/TileJSON.js';
|
||||
import TileLayer from '../src/ol/layer/Tile.js';
|
||||
import View from '../src/ol/View.js';
|
||||
import WebGLPointsLayer from '../src/ol/layer/WebGLPoints.js';
|
||||
import {Vector} from '../src/ol/source.js';
|
||||
import {fromLonLat} from '../src/ol/proj.js';
|
||||
import WebGLPointsLayer from '../src/ol/layer/WebGLPoints.js';
|
||||
|
||||
const key = 'pk.eyJ1IjoidHNjaGF1YiIsImEiOiJjaW5zYW5lNHkxMTNmdWttM3JyOHZtMmNtIn0.CDIBD8H-G2Gf-cPkIuWtRg';
|
||||
const key =
|
||||
'pk.eyJ1IjoidHNjaGF1YiIsImEiOiJjaW5zYW5lNHkxMTNmdWttM3JyOHZtMmNtIn0.CDIBD8H-G2Gf-cPkIuWtRg';
|
||||
|
||||
const map = new Map({
|
||||
layers: [
|
||||
new TileLayer({
|
||||
source: new TileJSON({
|
||||
url: 'https://api.tiles.mapbox.com/v4/mapbox.world-dark.json?secure&access_token=' + key,
|
||||
crossOrigin: 'anonymous'
|
||||
})
|
||||
})
|
||||
url:
|
||||
'https://api.tiles.mapbox.com/v4/mapbox.world-dark.json?secure&access_token=' +
|
||||
key,
|
||||
crossOrigin: 'anonymous',
|
||||
}),
|
||||
}),
|
||||
],
|
||||
target: document.getElementById('map'),
|
||||
view: new View({
|
||||
center: [0, 4000000],
|
||||
zoom: 2
|
||||
})
|
||||
zoom: 2,
|
||||
}),
|
||||
});
|
||||
|
||||
const vectorSource = new Vector({
|
||||
features: [],
|
||||
attributions: 'National UFO Reporting Center'
|
||||
attributions: 'National UFO Reporting Center',
|
||||
});
|
||||
|
||||
const oldColor = [255, 160, 110];
|
||||
@@ -37,13 +40,13 @@ const size = 16;
|
||||
|
||||
const style = {
|
||||
variables: {
|
||||
filterShape: 'all'
|
||||
filterShape: 'all',
|
||||
},
|
||||
filter: [
|
||||
'case',
|
||||
['!=', ['var', 'filterShape'], 'all'],
|
||||
['==', ['get', 'shape'], ['var', 'filterShape']],
|
||||
true
|
||||
true,
|
||||
],
|
||||
symbol: {
|
||||
symbolType: 'image',
|
||||
@@ -53,44 +56,51 @@ const style = {
|
||||
'interpolate',
|
||||
['linear'],
|
||||
['get', 'year'],
|
||||
1950, oldColor,
|
||||
2013, newColor
|
||||
1950,
|
||||
oldColor,
|
||||
2013,
|
||||
newColor,
|
||||
],
|
||||
rotateWithView: false,
|
||||
offset: [
|
||||
0,
|
||||
0
|
||||
],
|
||||
offset: [0, 0],
|
||||
textureCoord: [
|
||||
'match',
|
||||
['get', 'shape'],
|
||||
'light', [0, 0, 0.25, 0.5],
|
||||
'sphere', [0.25, 0, 0.5, 0.5],
|
||||
'circle', [0.25, 0, 0.5, 0.5],
|
||||
'disc', [0.5, 0, 0.75, 0.5],
|
||||
'oval', [0.5, 0, 0.75, 0.5],
|
||||
'triangle', [0.75, 0, 1, 0.5],
|
||||
'fireball', [0, 0.5, 0.25, 1],
|
||||
[0.75, 0.5, 1, 1]
|
||||
]
|
||||
}
|
||||
'light',
|
||||
[0, 0, 0.25, 0.5],
|
||||
'sphere',
|
||||
[0.25, 0, 0.5, 0.5],
|
||||
'circle',
|
||||
[0.25, 0, 0.5, 0.5],
|
||||
'disc',
|
||||
[0.5, 0, 0.75, 0.5],
|
||||
'oval',
|
||||
[0.5, 0, 0.75, 0.5],
|
||||
'triangle',
|
||||
[0.75, 0, 1, 0.5],
|
||||
'fireball',
|
||||
[0, 0.5, 0.25, 1],
|
||||
[0.75, 0.5, 1, 1],
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
// key is shape name, value is sightings count
|
||||
const shapeTypes = {
|
||||
all: 0
|
||||
all: 0,
|
||||
};
|
||||
const shapeSelect = document.getElementById('shape-filter');
|
||||
shapeSelect.addEventListener('input', function() {
|
||||
style.variables.filterShape = shapeSelect.options[shapeSelect.selectedIndex].value;
|
||||
shapeSelect.addEventListener('input', function () {
|
||||
style.variables.filterShape =
|
||||
shapeSelect.options[shapeSelect.selectedIndex].value;
|
||||
map.render();
|
||||
});
|
||||
function fillShapeSelect() {
|
||||
Object.keys(shapeTypes)
|
||||
.sort(function(a, b) {
|
||||
.sort(function (a, b) {
|
||||
return shapeTypes[b] - shapeTypes[a];
|
||||
})
|
||||
.forEach(function(shape) {
|
||||
.forEach(function (shape) {
|
||||
const option = document.createElement('option');
|
||||
option.text = `${shape} (${shapeTypes[shape]} sightings)`;
|
||||
option.value = shape;
|
||||
@@ -100,7 +110,7 @@ function fillShapeSelect() {
|
||||
|
||||
const client = new XMLHttpRequest();
|
||||
client.open('GET', 'data/csv/ufo_sighting_data.csv');
|
||||
client.onload = function() {
|
||||
client.onload = function () {
|
||||
const csv = client.responseText;
|
||||
const features = [];
|
||||
|
||||
@@ -122,13 +132,15 @@ client.onload = function() {
|
||||
shapeTypes[shape] = (shapeTypes[shape] ? shapeTypes[shape] : 0) + 1;
|
||||
shapeTypes['all']++;
|
||||
|
||||
features.push(new Feature({
|
||||
datetime: line[0],
|
||||
year: parseInt(/[0-9]{4}/.exec(line[0])[0]), // extract the year as int
|
||||
shape: shape,
|
||||
duration: line[3],
|
||||
geometry: new Point(coords)
|
||||
}));
|
||||
features.push(
|
||||
new Feature({
|
||||
datetime: line[0],
|
||||
year: parseInt(/[0-9]{4}/.exec(line[0])[0]), // extract the year as int
|
||||
shape: shape,
|
||||
duration: line[3],
|
||||
geometry: new Point(coords),
|
||||
})
|
||||
);
|
||||
}
|
||||
vectorSource.addFeatures(features);
|
||||
fillShapeSelect();
|
||||
@@ -138,21 +150,28 @@ client.send();
|
||||
map.addLayer(
|
||||
new WebGLPointsLayer({
|
||||
source: vectorSource,
|
||||
style: style
|
||||
style: style,
|
||||
})
|
||||
);
|
||||
|
||||
const info = document.getElementById('info');
|
||||
map.on('pointermove', function(evt) {
|
||||
map.on('pointermove', function (evt) {
|
||||
if (map.getView().getInteracting() || map.getView().getAnimating()) {
|
||||
return;
|
||||
}
|
||||
const pixel = evt.pixel;
|
||||
info.innerText = '';
|
||||
map.forEachFeatureAtPixel(pixel, function(feature) {
|
||||
map.forEachFeatureAtPixel(pixel, function (feature) {
|
||||
const datetime = feature.get('datetime');
|
||||
const duration = feature.get('duration');
|
||||
const shape = feature.get('shape');
|
||||
info.innerText = 'On ' + datetime + ', lasted ' + duration + ' seconds and had a "' + shape + '" shape.';
|
||||
info.innerText =
|
||||
'On ' +
|
||||
datetime +
|
||||
', lasted ' +
|
||||
duration +
|
||||
' seconds and had a "' +
|
||||
shape +
|
||||
'" shape.';
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user