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

View File

@@ -1,27 +1,27 @@
import Geolocation from '../src/ol/Geolocation.js';
import Map from '../src/ol/Map.js';
import Overlay from '../src/ol/Overlay.js';
import View from '../src/ol/View.js';
import LineString from '../src/ol/geom/LineString.js';
import TileLayer from '../src/ol/layer/Tile.js';
import {fromLonLat} from '../src/ol/proj.js';
import Map from '../src/ol/Map.js';
import OSM from '../src/ol/source/OSM.js';
import Overlay from '../src/ol/Overlay.js';
import TileLayer from '../src/ol/layer/Tile.js';
import View from '../src/ol/View.js';
import {fromLonLat} from '../src/ol/proj.js';
// creating the view
const view = new View({
center: fromLonLat([5.8713, 45.6452]),
zoom: 19
zoom: 19,
});
const tileLayer = new TileLayer({
source: new OSM()
source: new OSM(),
});
// creating the map
const map = new Map({
layers: [tileLayer],
target: 'map',
view: view
view: view,
});
// Geolocation marker
@@ -29,7 +29,7 @@ const markerEl = document.getElementById('geolocation_marker');
const marker = new Overlay({
positioning: 'center-center',
element: markerEl,
stopEvent: false
stopEvent: false,
});
map.addOverlay(marker);
@@ -44,14 +44,14 @@ const geolocation = new Geolocation({
trackingOptions: {
maximumAge: 10000,
enableHighAccuracy: true,
timeout: 600000
}
timeout: 600000,
},
});
let deltaMean = 500; // the geolocation sampling period mean in ms
// Listen to position changes
geolocation.on('change', function() {
geolocation.on('change', function () {
const position = geolocation.getPosition();
const accuracy = geolocation.getAccuracy();
const heading = geolocation.getHeading() || 0;
@@ -71,27 +71,27 @@ geolocation.on('change', function() {
'Accuracy: ' + accuracy,
'Heading: ' + Math.round(radToDeg(heading)) + '°',
'Speed: ' + (speed * 3.6).toFixed(1) + ' km/h',
'Delta: ' + Math.round(deltaMean) + 'ms'
'Delta: ' + Math.round(deltaMean) + 'ms',
].join('<br />');
document.getElementById('info').innerHTML = html;
});
geolocation.on('error', function() {
geolocation.on('error', function () {
alert('geolocation error');
// FIXME we should remove the coordinates in positions
});
// convert radians to degrees
function radToDeg(rad) {
return rad * 360 / (Math.PI * 2);
return (rad * 360) / (Math.PI * 2);
}
// convert degrees to radians
function degToRad(deg) {
return deg * Math.PI * 2 / 360;
return (deg * Math.PI * 2) / 360;
}
// modulo for negative values
function mod(n) {
return ((n % (2 * Math.PI)) + (2 * Math.PI)) % (2 * Math.PI);
return ((n % (2 * Math.PI)) + 2 * Math.PI) % (2 * Math.PI);
}
function addPosition(position, heading, m, speed) {
@@ -105,7 +105,7 @@ function addPosition(position, heading, m, speed) {
// force the rotation change to be less than 180°
if (Math.abs(headingDiff) > Math.PI) {
const sign = (headingDiff >= 0) ? 1 : -1;
const sign = headingDiff >= 0 ? 1 : -1;
headingDiff = -sign * (2 * Math.PI - Math.abs(headingDiff));
}
heading = prevHeading + headingDiff;
@@ -130,8 +130,8 @@ function getCenterWithHeading(position, rotation, resolution) {
const height = size[1];
return [
position[0] - Math.sin(rotation) * height * resolution * 1 / 4,
position[1] + Math.cos(rotation) * height * resolution * 1 / 4
position[0] - (Math.sin(rotation) * height * resolution * 1) / 4,
position[1] + (Math.cos(rotation) * height * resolution * 1) / 4,
];
}
@@ -153,56 +153,63 @@ function updateView() {
// geolocate device
const geolocateBtn = document.getElementById('geolocate');
geolocateBtn.addEventListener('click', function() {
geolocation.setTracking(true); // Start position tracking
geolocateBtn.addEventListener(
'click',
function () {
geolocation.setTracking(true); // Start position tracking
tileLayer.on('postrender', updateView);
map.render();
tileLayer.on('postrender', updateView);
map.render();
disableButtons();
}, false);
disableButtons();
},
false
);
// simulate device move
let simulationData;
const client = new XMLHttpRequest();
client.open('GET', 'data/geolocation-orientation.json');
/**
* Handle data loading.
*/
client.onload = function() {
client.onload = function () {
simulationData = JSON.parse(client.responseText).data;
};
client.send();
const simulateBtn = document.getElementById('simulate');
simulateBtn.addEventListener('click', function() {
const coordinates = simulationData;
simulateBtn.addEventListener(
'click',
function () {
const coordinates = simulationData;
const first = coordinates.shift();
simulatePositionChange(first);
const first = coordinates.shift();
simulatePositionChange(first);
let prevDate = first.timestamp;
function geolocate() {
const position = coordinates.shift();
if (!position) {
return;
let prevDate = first.timestamp;
function geolocate() {
const position = coordinates.shift();
if (!position) {
return;
}
const newDate = position.timestamp;
simulatePositionChange(position);
window.setTimeout(function () {
prevDate = newDate;
geolocate();
}, (newDate - prevDate) / 0.5);
}
const newDate = position.timestamp;
simulatePositionChange(position);
window.setTimeout(function() {
prevDate = newDate;
geolocate();
}, (newDate - prevDate) / 0.5);
}
geolocate();
geolocate();
tileLayer.on('postrender', updateView);
map.render();
tileLayer.on('postrender', updateView);
map.render();
disableButtons();
}, false);
disableButtons();
},
false
);
function simulatePositionChange(position) {
const coords = position.coords;