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.
94 lines
2.9 KiB
JavaScript
94 lines
2.9 KiB
JavaScript
import {HALF_SIZE, fromEPSG4326} from '../../../../src/ol/proj/epsg3857.js';
|
|
import {
|
|
addCommon,
|
|
clearAllProjections,
|
|
getPointResolution,
|
|
get as getProjection,
|
|
transform,
|
|
} from '../../../../src/ol/proj.js';
|
|
|
|
describe('ol/proj/epsg3857', function () {
|
|
afterEach(function () {
|
|
clearAllProjections();
|
|
addCommon();
|
|
});
|
|
|
|
describe('fromEPSG4326()', function () {
|
|
it('transforms from geographic to Web Mercator', function () {
|
|
const tolerance = 1e-5;
|
|
|
|
const cases = [
|
|
{
|
|
g: [0, 0],
|
|
m: [0, 0],
|
|
},
|
|
{
|
|
g: [-180, -90],
|
|
m: [-HALF_SIZE, -HALF_SIZE],
|
|
},
|
|
{
|
|
g: [180, 90],
|
|
m: [HALF_SIZE, HALF_SIZE],
|
|
},
|
|
{
|
|
g: [-111.0429, 45.677],
|
|
m: [-12361239.084208, 5728738.469095],
|
|
},
|
|
];
|
|
|
|
for (let i = 0, ii = cases.length; i < ii; ++i) {
|
|
const point = cases[i].g;
|
|
const transformed = fromEPSG4326(point);
|
|
expect(transformed[0]).to.roughlyEqual(cases[i].m[0], tolerance);
|
|
expect(transformed[1]).to.roughlyEqual(cases[i].m[1], tolerance);
|
|
}
|
|
});
|
|
|
|
it('does not produce unexpected results for string coordinates', function () {
|
|
const transformed = fromEPSG4326(['180', '90']);
|
|
expect(transformed[0]).to.roughlyEqual(HALF_SIZE, 1e-5);
|
|
expect(transformed[1]).to.roughlyEqual(HALF_SIZE, 1e-5);
|
|
});
|
|
});
|
|
|
|
describe('getPointResolution', function () {
|
|
it('returns the correct point scale at the equator', function () {
|
|
// @see http://msdn.microsoft.com/en-us/library/aa940990.aspx
|
|
const epsg3857 = getProjection('EPSG:3857');
|
|
const resolution = 19.11;
|
|
const point = [0, 0];
|
|
expect(getPointResolution(epsg3857, resolution, point)).to.roughlyEqual(
|
|
19.11,
|
|
1e-1
|
|
);
|
|
});
|
|
|
|
it('returns the correct point scale at the latitude of Toronto', function () {
|
|
// @see http://msdn.microsoft.com/en-us/library/aa940990.aspx
|
|
const epsg3857 = getProjection('EPSG:3857');
|
|
const epsg4326 = getProjection('EPSG:4326');
|
|
const resolution = 19.11;
|
|
const point = transform([0, 43.65], epsg4326, epsg3857);
|
|
expect(getPointResolution(epsg3857, resolution, point)).to.roughlyEqual(
|
|
19.11 * Math.cos((Math.PI * 43.65) / 180),
|
|
1e-9
|
|
);
|
|
});
|
|
|
|
it('returns the correct point scale at various latitudes', function () {
|
|
// @see http://msdn.microsoft.com/en-us/library/aa940990.aspx
|
|
const epsg3857 = getProjection('EPSG:3857');
|
|
const epsg4326 = getProjection('EPSG:4326');
|
|
const resolution = 19.11;
|
|
let latitude;
|
|
for (latitude = 0; latitude <= 85; ++latitude) {
|
|
const point = transform([0, latitude], epsg4326, epsg3857);
|
|
expect(getPointResolution(epsg3857, resolution, point)).to.roughlyEqual(
|
|
19.11 * Math.cos((Math.PI * latitude) / 180),
|
|
1e-9
|
|
);
|
|
}
|
|
});
|
|
});
|
|
});
|