Files
openlayers/test/spec/ol/source/bingmaps.test.js
Tim Schaub 054af09032 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.
2020-04-06 12:54:09 -06:00

96 lines
2.7 KiB
JavaScript

import BingMaps, {quadKey} from '../../../../src/ol/source/BingMaps.js';
import {unByKey} from '../../../../src/ol/Observable.js';
describe('ol.source.BingMaps', function () {
describe('quadKey()', function () {
it('returns expected string', function () {
const tileCoord = [3, 3, 5];
const s = quadKey(tileCoord);
expect(s).to.eql('213');
});
});
describe('#tileUrlFunction()', function () {
let source, tileGrid;
beforeEach(function (done) {
source = new BingMaps({
imagerySet: 'AerialWithLabelsOnDemand',
key: '',
});
const client = new XMLHttpRequest();
client.open('GET', 'spec/ol/data/bing_aerialwithlabels.json', true);
client.onload = function () {
source.handleImageryMetadataResponse(JSON.parse(client.responseText));
};
client.send();
const key = source.on('change', function () {
if (source.getState() === 'ready') {
unByKey(key);
tileGrid = source.getTileGrid();
done();
}
});
});
it('getImagerySet works correctly', function () {
expect(source.getImagerySet()).to.equal('AerialWithLabelsOnDemand');
});
it('getApiKey works correctly', function () {
expect(source.getApiKey()).to.equal('');
});
it('returns the expected URL', function () {
const coordinate = [829330.2064098881, 5933916.615134273];
const projection = source.getProjection();
const regex = /\/tiles\/h(.*)\.jpeg/;
let tileUrl;
tileUrl = source.tileUrlFunction(
tileGrid.getTileCoordForCoordAndZ(coordinate, 1),
1,
projection
);
expect(tileUrl.match(regex)[1]).to.equal(quadKey([1, 1, 0]));
tileUrl = source.tileUrlFunction(
tileGrid.getTileCoordForCoordAndZ(coordinate, 2),
1,
projection
);
expect(tileUrl.match(regex)[1]).to.equal(quadKey([2, 2, 1]));
tileUrl = source.tileUrlFunction(
tileGrid.getTileCoordForCoordAndZ(coordinate, 3),
1,
projection
);
expect(tileUrl.match(regex)[1]).to.equal(quadKey([3, 4, 2]));
tileUrl = source.tileUrlFunction(
tileGrid.getTileCoordForCoordAndZ(coordinate, 4),
1,
projection
);
expect(tileUrl.match(regex)[1]).to.equal(quadKey([4, 8, 5]));
tileUrl = source.tileUrlFunction(
tileGrid.getTileCoordForCoordAndZ(coordinate, 5),
1,
projection
);
expect(tileUrl.match(regex)[1]).to.equal(quadKey([5, 16, 11]));
tileUrl = source.tileUrlFunction(
tileGrid.getTileCoordForCoordAndZ(coordinate, 6),
1,
projection
);
expect(tileUrl.match(regex)[1]).to.equal(quadKey([6, 33, 22]));
});
});
});