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,42 +1,39 @@
|
||||
import ImageTile from '../../../../src/ol/ImageTile.js';
|
||||
import {get as getProjection} from '../../../../src/ol/proj.js';
|
||||
import TileGrid from '../../../../src/ol/tilegrid/TileGrid.js';
|
||||
import TileWMS from '../../../../src/ol/source/TileWMS.js';
|
||||
import {createXYZ} from '../../../../src/ol/tilegrid.js';
|
||||
import TileGrid from '../../../../src/ol/tilegrid/TileGrid.js';
|
||||
|
||||
|
||||
describe('ol.source.TileWMS', function() {
|
||||
import {get as getProjection} from '../../../../src/ol/proj.js';
|
||||
|
||||
describe('ol.source.TileWMS', function () {
|
||||
let options, optionsReproj;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
options = {
|
||||
params: {
|
||||
'LAYERS': 'layer'
|
||||
'LAYERS': 'layer',
|
||||
},
|
||||
url: 'http://example.com/wms'
|
||||
url: 'http://example.com/wms',
|
||||
};
|
||||
optionsReproj = {
|
||||
params: {
|
||||
'LAYERS': 'layer'
|
||||
'LAYERS': 'layer',
|
||||
},
|
||||
url: 'http://example.com/wms',
|
||||
projection: 'EPSG:4326'
|
||||
projection: 'EPSG:4326',
|
||||
};
|
||||
});
|
||||
|
||||
describe('constructor', function() {
|
||||
it('can be constructed without url or urls params', function() {
|
||||
describe('constructor', function () {
|
||||
it('can be constructed without url or urls params', function () {
|
||||
const source = new TileWMS({
|
||||
projection: 'EPSG:3857',
|
||||
tileGrid: createXYZ({maxZoom: 6})
|
||||
tileGrid: createXYZ({maxZoom: 6}),
|
||||
});
|
||||
expect(source).to.be.an(TileWMS);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getTile', function() {
|
||||
|
||||
it('returns a tile with the expected URL', function() {
|
||||
describe('#getTile', function () {
|
||||
it('returns a tile with the expected URL', function () {
|
||||
const source = new TileWMS(options);
|
||||
const tile = source.getTile(3, 2, 6, 1, getProjection('EPSG:3857'));
|
||||
expect(tile).to.be.an(ImageTile);
|
||||
@@ -64,7 +61,7 @@ describe('ol.source.TileWMS', function() {
|
||||
expect(uri.hash.replace('#', '')).to.be.empty();
|
||||
});
|
||||
|
||||
it('returns a larger tile when a gutter is specified', function() {
|
||||
it('returns a larger tile when a gutter is specified', function () {
|
||||
options.gutter = 16;
|
||||
const source = new TileWMS(options);
|
||||
const tile = source.getTile(3, 2, 6, 1, getProjection('EPSG:3857'));
|
||||
@@ -72,8 +69,12 @@ describe('ol.source.TileWMS', function() {
|
||||
const uri = new URL(tile.src_);
|
||||
const queryData = uri.searchParams;
|
||||
const bbox = queryData.get('BBOX').split(',');
|
||||
const expected = [-10331840.239250705, -15341217.324948018,
|
||||
-4696291.017841229, -9705668.103538541];
|
||||
const expected = [
|
||||
-10331840.239250705,
|
||||
-15341217.324948018,
|
||||
-4696291.017841229,
|
||||
-9705668.103538541,
|
||||
];
|
||||
for (let i = 0, ii = bbox.length; i < ii; ++i) {
|
||||
expect(parseFloat(bbox[i])).to.roughlyEqual(expected[i], 1e-9);
|
||||
}
|
||||
@@ -81,7 +82,7 @@ describe('ol.source.TileWMS', function() {
|
||||
expect(queryData.get('WIDTH')).to.be('288');
|
||||
});
|
||||
|
||||
it('sets the SRS query value instead of CRS if version < 1.3', function() {
|
||||
it('sets the SRS query value instead of CRS if version < 1.3', function () {
|
||||
options.params.VERSION = '1.2';
|
||||
const source = new TileWMS(options);
|
||||
const tile = source.getTile(3, 2, 2, 1, getProjection('EPSG:4326'));
|
||||
@@ -91,7 +92,7 @@ describe('ol.source.TileWMS', function() {
|
||||
expect(queryData.get('SRS')).to.be('EPSG:4326');
|
||||
});
|
||||
|
||||
it('allows various parameters to be overridden', function() {
|
||||
it('allows various parameters to be overridden', function () {
|
||||
options.params.FORMAT = 'image/jpeg';
|
||||
options.params.TRANSPARENT = false;
|
||||
const source = new TileWMS(options);
|
||||
@@ -102,7 +103,7 @@ describe('ol.source.TileWMS', function() {
|
||||
expect(queryData.get('TRANSPARENT')).to.be('false');
|
||||
});
|
||||
|
||||
it('does not add a STYLES= option if one is specified', function() {
|
||||
it('does not add a STYLES= option if one is specified', function () {
|
||||
options.params.STYLES = 'foo';
|
||||
const source = new TileWMS(options);
|
||||
const tile = source.getTile(3, 2, 2, 1, getProjection('EPSG:4326'));
|
||||
@@ -111,7 +112,7 @@ describe('ol.source.TileWMS', function() {
|
||||
expect(queryData.get('STYLES')).to.be('foo');
|
||||
});
|
||||
|
||||
it('changes the BBOX order for EN axis orientations', function() {
|
||||
it('changes the BBOX order for EN axis orientations', function () {
|
||||
const source = new TileWMS(options);
|
||||
const tile = source.getTile(3, 2, 2, 1, getProjection('EPSG:4326'));
|
||||
const uri = new URL(tile.src_);
|
||||
@@ -119,7 +120,7 @@ describe('ol.source.TileWMS', function() {
|
||||
expect(queryData.get('BBOX')).to.be('-45,-90,0,-45');
|
||||
});
|
||||
|
||||
it('uses EN BBOX order if version < 1.3', function() {
|
||||
it('uses EN BBOX order if version < 1.3', function () {
|
||||
options.params.VERSION = '1.1.0';
|
||||
const source = new TileWMS(options);
|
||||
const tile = source.getTile(3, 2, 2, 1, getProjection('CRS:84'));
|
||||
@@ -128,7 +129,7 @@ describe('ol.source.TileWMS', function() {
|
||||
expect(queryData.get('BBOX')).to.be('-90,-45,-45,0');
|
||||
});
|
||||
|
||||
it('sets FORMAT_OPTIONS when the server is GeoServer', function() {
|
||||
it('sets FORMAT_OPTIONS when the server is GeoServer', function () {
|
||||
options.serverType = 'geoserver';
|
||||
const source = new TileWMS(options);
|
||||
const tile = source.getTile(3, 2, 2, 2, getProjection('CRS:84'));
|
||||
@@ -137,7 +138,7 @@ describe('ol.source.TileWMS', function() {
|
||||
expect(queryData.get('FORMAT_OPTIONS')).to.be('dpi:180');
|
||||
});
|
||||
|
||||
it('extends FORMAT_OPTIONS if it is already present', function() {
|
||||
it('extends FORMAT_OPTIONS if it is already present', function () {
|
||||
options.serverType = 'geoserver';
|
||||
const source = new TileWMS(options);
|
||||
options.params.FORMAT_OPTIONS = 'param1:value1';
|
||||
@@ -147,66 +148,75 @@ describe('ol.source.TileWMS', function() {
|
||||
expect(queryData.get('FORMAT_OPTIONS')).to.be('param1:value1;dpi:180');
|
||||
});
|
||||
|
||||
it('rounds FORMAT_OPTIONS to an integer when the server is GeoServer',
|
||||
function() {
|
||||
options.serverType = 'geoserver';
|
||||
const source = new TileWMS(options);
|
||||
const tile = source.getTile(3, 2, 2, 1.325, getProjection('CRS:84'));
|
||||
const uri = new URL(tile.src_);
|
||||
const queryData = uri.searchParams;
|
||||
expect(queryData.get('FORMAT_OPTIONS')).to.be('dpi:119');
|
||||
});
|
||||
|
||||
it('rounds FORMAT_OPTIONS to an integer when the server is GeoServer', function () {
|
||||
options.serverType = 'geoserver';
|
||||
const source = new TileWMS(options);
|
||||
const tile = source.getTile(3, 2, 2, 1.325, getProjection('CRS:84'));
|
||||
const uri = new URL(tile.src_);
|
||||
const queryData = uri.searchParams;
|
||||
expect(queryData.get('FORMAT_OPTIONS')).to.be('dpi:119');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#tileUrlFunction', function() {
|
||||
|
||||
it('returns a tile if it is contained within layers extent', function() {
|
||||
describe('#tileUrlFunction', function () {
|
||||
it('returns a tile if it is contained within layers extent', function () {
|
||||
options.extent = [-80, -40, -50, -10];
|
||||
const source = new TileWMS(options);
|
||||
const tileCoord = [3, 2, 2];
|
||||
const url = source.tileUrlFunction(tileCoord, 1, getProjection('EPSG:4326'));
|
||||
const url = source.tileUrlFunction(
|
||||
tileCoord,
|
||||
1,
|
||||
getProjection('EPSG:4326')
|
||||
);
|
||||
const uri = new URL(url);
|
||||
const queryData = uri.searchParams;
|
||||
expect(queryData.get('BBOX')).to.be('-45,-90,0,-45');
|
||||
});
|
||||
|
||||
it('returns a tile if it intersects layers extent', function() {
|
||||
it('returns a tile if it intersects layers extent', function () {
|
||||
options.extent = [-80, -40, -40, -10];
|
||||
const source = new TileWMS(options);
|
||||
const tileCoord = [3, 3, 2];
|
||||
const url = source.tileUrlFunction(tileCoord, 1, getProjection('EPSG:4326'));
|
||||
const url = source.tileUrlFunction(
|
||||
tileCoord,
|
||||
1,
|
||||
getProjection('EPSG:4326')
|
||||
);
|
||||
const uri = new URL(url);
|
||||
const queryData = uri.searchParams;
|
||||
expect(queryData.get('BBOX')).to.be('-45,-45,0,0');
|
||||
});
|
||||
|
||||
it('works with non-square tiles', function() {
|
||||
it('works with non-square tiles', function () {
|
||||
options.tileGrid = new TileGrid({
|
||||
tileSize: [640, 320],
|
||||
resolutions: [1.40625, 0.703125, 0.3515625, 0.17578125],
|
||||
origin: [-180, -90]
|
||||
origin: [-180, -90],
|
||||
});
|
||||
const source = new TileWMS(options);
|
||||
const tileCoord = [3, 3, 2];
|
||||
const url = source.tileUrlFunction(tileCoord, 1, getProjection('EPSG:4326'));
|
||||
const url = source.tileUrlFunction(
|
||||
tileCoord,
|
||||
1,
|
||||
getProjection('EPSG:4326')
|
||||
);
|
||||
const uri = new URL(url);
|
||||
const queryData = uri.searchParams;
|
||||
expect(queryData.get('WIDTH')).to.be('640');
|
||||
expect(queryData.get('HEIGHT')).to.be('320');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getFeatureInfoUrl', function() {
|
||||
|
||||
it('returns the expected GetFeatureInfo URL', function() {
|
||||
describe('#getFeatureInfoUrl', function () {
|
||||
it('returns the expected GetFeatureInfo URL', function () {
|
||||
const source = new TileWMS(options);
|
||||
source.pixelRatio_ = 1;
|
||||
const url = source.getFeatureInfoUrl(
|
||||
[-7000000, -12000000],
|
||||
19567.87924100512, getProjection('EPSG:3857'),
|
||||
{INFO_FORMAT: 'text/plain'});
|
||||
19567.87924100512,
|
||||
getProjection('EPSG:3857'),
|
||||
{INFO_FORMAT: 'text/plain'}
|
||||
);
|
||||
const uri = new URL(url);
|
||||
expect(uri.protocol).to.be('http:');
|
||||
expect(uri.hostname).to.be('example.com');
|
||||
@@ -234,19 +244,23 @@ describe('ol.source.TileWMS', function() {
|
||||
expect(uri.hash.replace('#', '')).to.be.empty();
|
||||
});
|
||||
|
||||
it('returns the expected GetFeatureInfo URL when source\'s projection is different from the parameter', function() {
|
||||
it("returns the expected GetFeatureInfo URL when source's projection is different from the parameter", function () {
|
||||
const source = new TileWMS(optionsReproj);
|
||||
source.pixelRatio_ = 1;
|
||||
const url = source.getFeatureInfoUrl(
|
||||
[-7000000, -12000000],
|
||||
19567.87924100512, getProjection('EPSG:3857'),
|
||||
{INFO_FORMAT: 'text/plain'});
|
||||
19567.87924100512,
|
||||
getProjection('EPSG:3857'),
|
||||
{INFO_FORMAT: 'text/plain'}
|
||||
);
|
||||
const uri = new URL(url);
|
||||
expect(uri.protocol).to.be('http:');
|
||||
expect(uri.hostname).to.be('example.com');
|
||||
expect(uri.pathname).to.be('/wms');
|
||||
const queryData = uri.searchParams;
|
||||
expect(queryData.get('BBOX')).to.be('-79.17133464081945,-90,-66.51326044311186,-45');
|
||||
expect(queryData.get('BBOX')).to.be(
|
||||
'-79.17133464081945,-90,-66.51326044311186,-45'
|
||||
);
|
||||
expect(queryData.get('CRS')).to.be('EPSG:4326');
|
||||
expect(queryData.get('FORMAT')).to.be('image/png');
|
||||
expect(queryData.get('HEIGHT')).to.be('256');
|
||||
@@ -264,13 +278,15 @@ describe('ol.source.TileWMS', function() {
|
||||
expect(uri.hash.replace('#', '')).to.be.empty();
|
||||
});
|
||||
|
||||
it('sets the QUERY_LAYERS param as expected', function() {
|
||||
it('sets the QUERY_LAYERS param as expected', function () {
|
||||
const source = new TileWMS(options);
|
||||
source.pixelRatio_ = 1;
|
||||
const url = source.getFeatureInfoUrl(
|
||||
[-7000000, -12000000],
|
||||
19567.87924100512, getProjection('EPSG:3857'),
|
||||
{INFO_FORMAT: 'text/plain', QUERY_LAYERS: 'foo,bar'});
|
||||
19567.87924100512,
|
||||
getProjection('EPSG:3857'),
|
||||
{INFO_FORMAT: 'text/plain', QUERY_LAYERS: 'foo,bar'}
|
||||
);
|
||||
const uri = new URL(url);
|
||||
expect(uri.protocol).to.be('http:');
|
||||
expect(uri.hostname).to.be('example.com');
|
||||
@@ -299,9 +315,8 @@ describe('ol.source.TileWMS', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getLegendGraphicUrl', function() {
|
||||
|
||||
it('returns the getLegenGraphic url as expected', function() {
|
||||
describe('#getLegendGraphicUrl', function () {
|
||||
it('returns the getLegenGraphic url as expected', function () {
|
||||
const source = new TileWMS(options);
|
||||
const url = source.getLegendUrl(0.1);
|
||||
const uri = new URL(url);
|
||||
@@ -317,7 +332,7 @@ describe('ol.source.TileWMS', function() {
|
||||
expect(queryData.get('SCALE')).to.be('357.14214285714274');
|
||||
});
|
||||
|
||||
it('does not include SCALE if no resolution was provided', function() {
|
||||
it('does not include SCALE if no resolution was provided', function () {
|
||||
const source = new TileWMS(options);
|
||||
const url = source.getLegendUrl();
|
||||
const uri = new URL(url);
|
||||
@@ -325,7 +340,7 @@ describe('ol.source.TileWMS', function() {
|
||||
expect(queryData.get('SCALE')).to.be(null);
|
||||
});
|
||||
|
||||
it('adds additional params as expected', function() {
|
||||
it('adds additional params as expected', function () {
|
||||
const source = new TileWMS(options);
|
||||
const url = source.getLegendUrl(0.1, {
|
||||
STYLE: 'STYLE_VALUE',
|
||||
@@ -338,7 +353,7 @@ describe('ol.source.TileWMS', function() {
|
||||
HEIGHT: 'HEIGHT_VALUE',
|
||||
EXCEPTIONS: 'EXCEPTIONS_VALUE',
|
||||
LANGUAGE: 'LANGUAGE_VALUE',
|
||||
LAYER: 'LAYER_VALUE'
|
||||
LAYER: 'LAYER_VALUE',
|
||||
});
|
||||
const uri = new URL(url);
|
||||
expect(uri.protocol).to.be('http:');
|
||||
@@ -362,23 +377,26 @@ describe('ol.source.TileWMS', function() {
|
||||
expect(queryData.get('EXCEPTIONS')).to.be('EXCEPTIONS_VALUE');
|
||||
expect(queryData.get('LANGUAGE')).to.be('LANGUAGE_VALUE');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setUrl()', function() {
|
||||
it('sets the correct url', function() {
|
||||
describe('#setUrl()', function () {
|
||||
it('sets the correct url', function () {
|
||||
const source = new TileWMS(options);
|
||||
const url = 'http://foo/';
|
||||
source.setUrl(url);
|
||||
const tileUrl = source.tileUrlFunction([0, 0, 0], 1, getProjection('EPSG:4326'));
|
||||
const tileUrl = source.tileUrlFunction(
|
||||
[0, 0, 0],
|
||||
1,
|
||||
getProjection('EPSG:4326')
|
||||
);
|
||||
expect(tileUrl.indexOf(url)).to.be(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setUrls()', function() {
|
||||
it('updates the source key', function() {
|
||||
describe('#setUrls()', function () {
|
||||
it('updates the source key', function () {
|
||||
const source = new TileWMS({
|
||||
urls: ['u1', 'u2']
|
||||
urls: ['u1', 'u2'],
|
||||
});
|
||||
const originalKey = source.getKey();
|
||||
source.setUrls(['u3', 'u4']);
|
||||
|
||||
Reference in New Issue
Block a user