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,35 +1,32 @@
|
||||
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() {
|
||||
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() {
|
||||
|
||||
describe('#tileUrlFunction()', function () {
|
||||
let source, tileGrid;
|
||||
|
||||
beforeEach(function(done) {
|
||||
beforeEach(function (done) {
|
||||
source = new BingMaps({
|
||||
imagerySet: 'AerialWithLabelsOnDemand',
|
||||
key: ''
|
||||
key: '',
|
||||
});
|
||||
|
||||
const client = new XMLHttpRequest();
|
||||
client.open('GET', 'spec/ol/data/bing_aerialwithlabels.json', true);
|
||||
client.onload = function() {
|
||||
client.onload = function () {
|
||||
source.handleImageryMetadataResponse(JSON.parse(client.responseText));
|
||||
};
|
||||
client.send();
|
||||
|
||||
const key = source.on('change', function() {
|
||||
const key = source.on('change', function () {
|
||||
if (source.getState() === 'ready') {
|
||||
unByKey(key);
|
||||
tileGrid = source.getTileGrid();
|
||||
@@ -38,50 +35,61 @@ describe('ol.source.BingMaps', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('getImagerySet works correctly', function() {
|
||||
it('getImagerySet works correctly', function () {
|
||||
expect(source.getImagerySet()).to.equal('AerialWithLabelsOnDemand');
|
||||
});
|
||||
|
||||
it('getApiKey works correctly', function() {
|
||||
it('getApiKey works correctly', function () {
|
||||
expect(source.getApiKey()).to.equal('');
|
||||
});
|
||||
|
||||
it('returns the expected URL', function() {
|
||||
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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]));
|
||||
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]));
|
||||
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 6),
|
||||
1,
|
||||
projection
|
||||
);
|
||||
expect(tileUrl.match(regex)[1]).to.equal(quadKey([6, 33, 22]));
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import CartoDB from '../../../../src/ol/source/CartoDB.js';
|
||||
import XYZ from '../../../../src/ol/source/XYZ.js';
|
||||
|
||||
describe('ol.source.CartoDB', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('returns a CartoDB source', function() {
|
||||
describe('ol.source.CartoDB', function () {
|
||||
describe('constructor', function () {
|
||||
it('returns a CartoDB source', function () {
|
||||
const source = new CartoDB({
|
||||
account: 'documentation',
|
||||
config: {}
|
||||
config: {},
|
||||
});
|
||||
expect(source).to.be.a(XYZ);
|
||||
expect(source).to.be.a(CartoDB);
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
import Cluster from '../../../../src/ol/source/Cluster.js';
|
||||
import EventType from '../../../../src/ol/events/EventType.js';
|
||||
import Feature from '../../../../src/ol/Feature.js';
|
||||
import LineString from '../../../../src/ol/geom/LineString.js';
|
||||
import Point from '../../../../src/ol/geom/Point.js';
|
||||
import Polygon from '../../../../src/ol/geom/Polygon.js';
|
||||
import {get as getProjection} from '../../../../src/ol/proj.js';
|
||||
import Cluster from '../../../../src/ol/source/Cluster.js';
|
||||
import Source from '../../../../src/ol/source/Source.js';
|
||||
import VectorSource from '../../../../src/ol/source/Vector.js';
|
||||
import EventType from '../../../../src/ol/events/EventType.js';
|
||||
import {get as getProjection} from '../../../../src/ol/proj.js';
|
||||
|
||||
describe('ol.source.Cluster', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('returns a cluster source', function() {
|
||||
describe('ol.source.Cluster', function () {
|
||||
describe('constructor', function () {
|
||||
it('returns a cluster source', function () {
|
||||
const source = new Cluster({
|
||||
projection: getProjection('EPSG:4326'),
|
||||
source: new VectorSource()
|
||||
source: new VectorSource(),
|
||||
});
|
||||
expect(source).to.be.a(Source);
|
||||
expect(source).to.be.a(Cluster);
|
||||
@@ -22,25 +21,25 @@ describe('ol.source.Cluster', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#loadFeatures', function() {
|
||||
describe('#loadFeatures', function () {
|
||||
const extent = [-1, -1, 1, 1];
|
||||
const projection = getProjection('EPSG:3857');
|
||||
it('clusters a source with point features', function() {
|
||||
it('clusters a source with point features', function () {
|
||||
const source = new Cluster({
|
||||
source: new VectorSource({
|
||||
features: [
|
||||
new Feature(new Point([0, 0])),
|
||||
new Feature(new Point([0, 0]))
|
||||
]
|
||||
})
|
||||
new Feature(new Point([0, 0])),
|
||||
],
|
||||
}),
|
||||
});
|
||||
source.loadFeatures(extent, 1, projection);
|
||||
expect(source.getFeatures().length).to.be(1);
|
||||
expect(source.getFeatures()[0].get('features').length).to.be(2);
|
||||
});
|
||||
it('clusters with a custom geometryFunction', function() {
|
||||
it('clusters with a custom geometryFunction', function () {
|
||||
const source = new Cluster({
|
||||
geometryFunction: function(feature) {
|
||||
geometryFunction: function (feature) {
|
||||
const geom = feature.getGeometry();
|
||||
if (geom.getType() == 'Point') {
|
||||
return geom;
|
||||
@@ -52,11 +51,25 @@ describe('ol.source.Cluster', function() {
|
||||
source: new VectorSource({
|
||||
features: [
|
||||
new Feature(new Point([0, 0])),
|
||||
new Feature(new LineString([[0, 0], [1, 1]])),
|
||||
new Feature(new Polygon(
|
||||
[[[-1, -1], [-1, 1], [1, 1], [1, -1], [-1, -1]]]))
|
||||
]
|
||||
})
|
||||
new Feature(
|
||||
new LineString([
|
||||
[0, 0],
|
||||
[1, 1],
|
||||
])
|
||||
),
|
||||
new Feature(
|
||||
new Polygon([
|
||||
[
|
||||
[-1, -1],
|
||||
[-1, 1],
|
||||
[1, 1],
|
||||
[1, -1],
|
||||
[-1, -1],
|
||||
],
|
||||
])
|
||||
),
|
||||
],
|
||||
}),
|
||||
});
|
||||
source.loadFeatures(extent, 1, projection);
|
||||
expect(source.getFeatures().length).to.be(1);
|
||||
@@ -64,36 +77,35 @@ describe('ol.source.Cluster', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setDistance', function() {
|
||||
it('changes the distance value', function() {
|
||||
describe('#setDistance', function () {
|
||||
it('changes the distance value', function () {
|
||||
const source = new Cluster({
|
||||
distance: 100,
|
||||
source: new VectorSource()
|
||||
source: new VectorSource(),
|
||||
});
|
||||
expect(source.getDistance()).to.be(100);
|
||||
source.setDistance(10);
|
||||
expect(source.getDistance()).to.be(10);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setSource', function() {
|
||||
it('removes the change listener from the old source', function() {
|
||||
describe('#setSource', function () {
|
||||
it('removes the change listener from the old source', function () {
|
||||
const source = new VectorSource();
|
||||
const clusterSource = new Cluster({
|
||||
source: source
|
||||
source: source,
|
||||
});
|
||||
expect(source.hasListener(EventType.CHANGE)).to.be(true);
|
||||
clusterSource.setSource(null);
|
||||
expect(source.hasListener(EventType.CHANGE)).to.be(false);
|
||||
});
|
||||
|
||||
it('properly removes the previous features', function() {
|
||||
it('properly removes the previous features', function () {
|
||||
const source = new Cluster({
|
||||
source: new VectorSource({
|
||||
features: [new Feature(new Point([0, 0]))]
|
||||
})
|
||||
features: [new Feature(new Point([0, 0]))],
|
||||
}),
|
||||
});
|
||||
|
||||
const projection = getProjection('EPSG:3857');
|
||||
@@ -104,6 +116,4 @@ describe('#setSource', function() {
|
||||
source.setSource(null);
|
||||
expect(source.features.length).to.be(0);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -1,181 +1,190 @@
|
||||
import {DEFAULT_TILE_SIZE} from '../../../../src/ol/tilegrid/common.js';
|
||||
import IIIF from '../../../../src/ol/source/IIIF.js';
|
||||
import {DEFAULT_TILE_SIZE} from '../../../../src/ol/tilegrid/common.js';
|
||||
import {Versions} from '../../../../src/ol/format/IIIFInfo.js';
|
||||
|
||||
|
||||
describe('ol.source.IIIF', function() {
|
||||
describe('ol.source.IIIF', function () {
|
||||
const width = 2000,
|
||||
height = 1500,
|
||||
size = [width, height],
|
||||
url = 'http://iiif.test/image-id';
|
||||
height = 1500,
|
||||
size = [width, height],
|
||||
url = 'http://iiif.test/image-id';
|
||||
|
||||
function getMinimalSource() {
|
||||
return new IIIF({
|
||||
size: size
|
||||
size: size,
|
||||
});
|
||||
}
|
||||
|
||||
function getSource(additionalOptions) {
|
||||
const options = Object.assign({}, {
|
||||
size: size,
|
||||
url: url
|
||||
}, additionalOptions === undefined ? {} : additionalOptions);
|
||||
const options = Object.assign(
|
||||
{},
|
||||
{
|
||||
size: size,
|
||||
url: url,
|
||||
},
|
||||
additionalOptions === undefined ? {} : additionalOptions
|
||||
);
|
||||
return new IIIF(options);
|
||||
}
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('requires valid size option', function() {
|
||||
|
||||
expect(function() {
|
||||
describe('constructor', function () {
|
||||
it('requires valid size option', function () {
|
||||
expect(function () {
|
||||
new IIIF();
|
||||
}).to.throwException();
|
||||
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
new IIIF({});
|
||||
}).to.throwException();
|
||||
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
new IIIF({
|
||||
size: []
|
||||
size: [],
|
||||
});
|
||||
}).to.throwException();
|
||||
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
new IIIF({
|
||||
size: 100
|
||||
size: 100,
|
||||
});
|
||||
}).to.throwException();
|
||||
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
new IIIF({
|
||||
size: [100]
|
||||
size: [100],
|
||||
});
|
||||
}).to.throwException();
|
||||
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
new IIIF({
|
||||
size: [null, 100]
|
||||
size: [null, 100],
|
||||
});
|
||||
}).to.throwException();
|
||||
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
new IIIF({
|
||||
size: ['very wide', 100]
|
||||
size: ['very wide', 100],
|
||||
});
|
||||
}).to.throwException();
|
||||
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
new IIIF({
|
||||
size: [0, 100]
|
||||
size: [0, 100],
|
||||
});
|
||||
}).to.throwException();
|
||||
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
new IIIF({
|
||||
size: [100, null]
|
||||
size: [100, null],
|
||||
});
|
||||
}).to.throwException();
|
||||
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
new IIIF({
|
||||
size: [100, 0]
|
||||
size: [100, 0],
|
||||
});
|
||||
}).to.throwException();
|
||||
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
new IIIF({
|
||||
size: [100, 'not that high']
|
||||
size: [100, 'not that high'],
|
||||
});
|
||||
}).to.throwException();
|
||||
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
new IIIF({
|
||||
size: [100, 200, 300]
|
||||
size: [100, 200, 300],
|
||||
});
|
||||
}).to.throwException();
|
||||
|
||||
let source;
|
||||
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
source = new IIIF({
|
||||
size: [100, 200]
|
||||
size: [100, 200],
|
||||
});
|
||||
}).to.not.throwException();
|
||||
|
||||
expect(source).to.be.a(IIIF);
|
||||
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
getMinimalSource();
|
||||
}).to.not.throwException();
|
||||
|
||||
});
|
||||
|
||||
it('uses empty base URL, default quality, jpg format as default', function() {
|
||||
|
||||
it('uses empty base URL, default quality, jpg format as default', function () {
|
||||
const tileUrlFunction = getMinimalSource().getTileUrlFunction();
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be('full/full/0/default.jpg');
|
||||
|
||||
});
|
||||
|
||||
it('uses native as default quality for version 1', function() {
|
||||
|
||||
it('uses native as default quality for version 1', function () {
|
||||
const tileUrlFunction = new IIIF({
|
||||
size: size,
|
||||
version: Versions.VERSION1
|
||||
version: Versions.VERSION1,
|
||||
}).getTileUrlFunction();
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be('full/full/0/native.jpg');
|
||||
|
||||
});
|
||||
|
||||
it('corrects non empty base URL if trailing slash is missing', function() {
|
||||
|
||||
it('corrects non empty base URL if trailing slash is missing', function () {
|
||||
// missing trailing slash is added
|
||||
let tileUrlFunction = getSource().getTileUrlFunction();
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be('http://iiif.test/image-id/full/full/0/default.jpg');
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/full/full/0/default.jpg'
|
||||
);
|
||||
|
||||
// existent trailing slash isn't doubled
|
||||
tileUrlFunction = getSource({
|
||||
url: 'http://iiif.test/other-image-id/'
|
||||
url: 'http://iiif.test/other-image-id/',
|
||||
}).getTileUrlFunction();
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be('http://iiif.test/other-image-id/full/full/0/default.jpg');
|
||||
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be(
|
||||
'http://iiif.test/other-image-id/full/full/0/default.jpg'
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('tileUrlFunction', function() {
|
||||
|
||||
it('has only one resolution and one tile if no tiles, resolutions, sizes and supported features are given', function() {
|
||||
|
||||
describe('tileUrlFunction', function () {
|
||||
it('has only one resolution and one tile if no tiles, resolutions, sizes and supported features are given', function () {
|
||||
let tileUrlFunction = getSource().getTileUrlFunction();
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be('http://iiif.test/image-id/full/full/0/default.jpg');
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/full/full/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([-1, 0, 0])).to.be(undefined);
|
||||
expect(tileUrlFunction([1, 0, 0])).to.be(undefined);
|
||||
expect(tileUrlFunction([0, 1, 0])).to.be(undefined);
|
||||
expect(tileUrlFunction([0, 0, 1])).to.be(undefined);
|
||||
|
||||
tileUrlFunction = getSource({
|
||||
version: Versions.VERSION1
|
||||
version: Versions.VERSION1,
|
||||
}).getTileUrlFunction();
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be('http://iiif.test/image-id/full/full/0/native.jpg');
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/full/full/0/native.jpg'
|
||||
);
|
||||
|
||||
tileUrlFunction = getSource({
|
||||
version: Versions.VERSION3
|
||||
version: Versions.VERSION3,
|
||||
}).getTileUrlFunction();
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be('http://iiif.test/image-id/full/max/0/default.jpg');
|
||||
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/full/max/0/default.jpg'
|
||||
);
|
||||
});
|
||||
|
||||
it('constructs the same number of resolutions as distinguishable sizes are given', function() {
|
||||
|
||||
it('constructs the same number of resolutions as distinguishable sizes are given', function () {
|
||||
let tileUrlFunction = getSource({
|
||||
sizes: [[2000, 1500], [1000, 750], [500, 375]]
|
||||
sizes: [
|
||||
[2000, 1500],
|
||||
[1000, 750],
|
||||
[500, 375],
|
||||
],
|
||||
}).getTileUrlFunction();
|
||||
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be('http://iiif.test/image-id/full/500,/0/default.jpg');
|
||||
expect(tileUrlFunction([1, 0, 0])).to.be('http://iiif.test/image-id/full/1000,/0/default.jpg');
|
||||
expect(tileUrlFunction([2, 0, 0])).to.be('http://iiif.test/image-id/full/full/0/default.jpg');
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/full/500,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([1, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/full/1000,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([2, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/full/full/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([3, 0, 0])).to.be(undefined);
|
||||
expect(tileUrlFunction([-1, 0, 0])).to.be(undefined);
|
||||
expect(tileUrlFunction([0, 1, 0])).to.be(undefined);
|
||||
@@ -184,219 +193,382 @@ describe('ol.source.IIIF', function() {
|
||||
expect(tileUrlFunction([1, 0, 1])).to.be(undefined);
|
||||
|
||||
tileUrlFunction = getSource({
|
||||
sizes: [[2000, 1500], [1000, 750], [500, 375]],
|
||||
version: Versions.VERSION3
|
||||
sizes: [
|
||||
[2000, 1500],
|
||||
[1000, 750],
|
||||
[500, 375],
|
||||
],
|
||||
version: Versions.VERSION3,
|
||||
}).getTileUrlFunction();
|
||||
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be('http://iiif.test/image-id/full/500,375/0/default.jpg');
|
||||
expect(tileUrlFunction([1, 0, 0])).to.be('http://iiif.test/image-id/full/1000,750/0/default.jpg');
|
||||
expect(tileUrlFunction([2, 0, 0])).to.be('http://iiif.test/image-id/full/max/0/default.jpg');
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/full/500,375/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([1, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/full/1000,750/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([2, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/full/max/0/default.jpg'
|
||||
);
|
||||
|
||||
tileUrlFunction = getSource({
|
||||
sizes: [[2000, 1500], [1000, 749], [1000, 750], [500, 375], [500, 374]]
|
||||
sizes: [
|
||||
[2000, 1500],
|
||||
[1000, 749],
|
||||
[1000, 750],
|
||||
[500, 375],
|
||||
[500, 374],
|
||||
],
|
||||
}).getTileUrlFunction();
|
||||
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be('http://iiif.test/image-id/full/500,/0/default.jpg');
|
||||
expect(tileUrlFunction([1, 0, 0])).to.be('http://iiif.test/image-id/full/1000,/0/default.jpg');
|
||||
expect(tileUrlFunction([2, 0, 0])).to.be('http://iiif.test/image-id/full/full/0/default.jpg');
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/full/500,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([1, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/full/1000,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([2, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/full/full/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([3, 0, 0])).to.be(undefined);
|
||||
|
||||
tileUrlFunction = getSource({
|
||||
version: Versions.VERSION3,
|
||||
sizes: [[2000, 1500], [1000, 750], [500, 375]]
|
||||
sizes: [
|
||||
[2000, 1500],
|
||||
[1000, 750],
|
||||
[500, 375],
|
||||
],
|
||||
}).getTileUrlFunction();
|
||||
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be('http://iiif.test/image-id/full/500,375/0/default.jpg');
|
||||
expect(tileUrlFunction([1, 0, 0])).to.be('http://iiif.test/image-id/full/1000,750/0/default.jpg');
|
||||
expect(tileUrlFunction([2, 0, 0])).to.be('http://iiif.test/image-id/full/max/0/default.jpg');
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/full/500,375/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([1, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/full/1000,750/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([2, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/full/max/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([3, 0, 0])).to.be(undefined);
|
||||
expect(tileUrlFunction([-1, 0, 0])).to.be(undefined);
|
||||
expect(tileUrlFunction([0, 1, 0])).to.be(undefined);
|
||||
expect(tileUrlFunction([0, 0, 1])).to.be(undefined);
|
||||
expect(tileUrlFunction([1, 1, 0])).to.be(undefined);
|
||||
expect(tileUrlFunction([1, 0, 1])).to.be(undefined);
|
||||
|
||||
});
|
||||
|
||||
it('cannot provide scaled tiles without provided tilesize or supported features', function() {
|
||||
|
||||
it('cannot provide scaled tiles without provided tilesize or supported features', function () {
|
||||
const tileUrlFunction = getSource({
|
||||
resolutions: [16, 8, 4, 2, 1]
|
||||
resolutions: [16, 8, 4, 2, 1],
|
||||
}).getTileUrlFunction();
|
||||
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be('http://iiif.test/image-id/full/full/0/default.jpg');
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/full/full/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([-1, 0, 0])).to.be(undefined);
|
||||
expect(tileUrlFunction([1, 0, 0])).to.be(undefined);
|
||||
expect(tileUrlFunction([0, 1, 0])).to.be(undefined);
|
||||
expect(tileUrlFunction([0, 0, 1])).to.be(undefined);
|
||||
|
||||
});
|
||||
|
||||
it('provides canonical tile URLs for all necessary resolutions if only a tileSize exists', function() {
|
||||
|
||||
it('provides canonical tile URLs for all necessary resolutions if only a tileSize exists', function () {
|
||||
let tileUrlFunction = getSource({
|
||||
tileSize: 512
|
||||
tileSize: 512,
|
||||
}).getTileUrlFunction();
|
||||
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be('http://iiif.test/image-id/full/500,/0/default.jpg');
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/full/500,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([-1, 0, 0])).to.be(undefined);
|
||||
expect(tileUrlFunction([0, 1, 0])).to.be(undefined);
|
||||
expect(tileUrlFunction([0, 0, 1])).to.be(undefined);
|
||||
expect(tileUrlFunction([1, 0, 0])).to.be('http://iiif.test/image-id/0,0,1024,1024/512,/0/default.jpg');
|
||||
expect(tileUrlFunction([1, 1, 0])).to.be('http://iiif.test/image-id/1024,0,976,1024/488,/0/default.jpg');
|
||||
expect(tileUrlFunction([1, 0, 1])).to.be('http://iiif.test/image-id/0,1024,1024,476/512,/0/default.jpg');
|
||||
expect(tileUrlFunction([1, 1, 1])).to.be('http://iiif.test/image-id/1024,1024,976,476/488,/0/default.jpg');
|
||||
expect(tileUrlFunction([2, 0, 0])).to.be('http://iiif.test/image-id/0,0,512,512/512,/0/default.jpg');
|
||||
expect(tileUrlFunction([2, 3, 0])).to.be('http://iiif.test/image-id/1536,0,464,512/464,/0/default.jpg');
|
||||
expect(tileUrlFunction([2, 0, 2])).to.be('http://iiif.test/image-id/0,1024,512,476/512,/0/default.jpg');
|
||||
expect(tileUrlFunction([2, 3, 2])).to.be('http://iiif.test/image-id/1536,1024,464,476/464,/0/default.jpg');
|
||||
expect(tileUrlFunction([1, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/0,0,1024,1024/512,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([1, 1, 0])).to.be(
|
||||
'http://iiif.test/image-id/1024,0,976,1024/488,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([1, 0, 1])).to.be(
|
||||
'http://iiif.test/image-id/0,1024,1024,476/512,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([1, 1, 1])).to.be(
|
||||
'http://iiif.test/image-id/1024,1024,976,476/488,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([2, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/0,0,512,512/512,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([2, 3, 0])).to.be(
|
||||
'http://iiif.test/image-id/1536,0,464,512/464,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([2, 0, 2])).to.be(
|
||||
'http://iiif.test/image-id/0,1024,512,476/512,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([2, 3, 2])).to.be(
|
||||
'http://iiif.test/image-id/1536,1024,464,476/464,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([3, 0, 0])).to.be(undefined);
|
||||
|
||||
tileUrlFunction = getSource({
|
||||
tileSize: 512,
|
||||
version: Versions.VERSION3
|
||||
version: Versions.VERSION3,
|
||||
}).getTileUrlFunction();
|
||||
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be('http://iiif.test/image-id/full/500,375/0/default.jpg');
|
||||
expect(tileUrlFunction([1, 0, 0])).to.be('http://iiif.test/image-id/0,0,1024,1024/512,512/0/default.jpg');
|
||||
expect(tileUrlFunction([1, 1, 0])).to.be('http://iiif.test/image-id/1024,0,976,1024/488,512/0/default.jpg');
|
||||
expect(tileUrlFunction([1, 0, 1])).to.be('http://iiif.test/image-id/0,1024,1024,476/512,238/0/default.jpg');
|
||||
expect(tileUrlFunction([1, 1, 1])).to.be('http://iiif.test/image-id/1024,1024,976,476/488,238/0/default.jpg');
|
||||
expect(tileUrlFunction([2, 0, 0])).to.be('http://iiif.test/image-id/0,0,512,512/512,512/0/default.jpg');
|
||||
expect(tileUrlFunction([2, 3, 0])).to.be('http://iiif.test/image-id/1536,0,464,512/464,512/0/default.jpg');
|
||||
expect(tileUrlFunction([2, 0, 2])).to.be('http://iiif.test/image-id/0,1024,512,476/512,476/0/default.jpg');
|
||||
expect(tileUrlFunction([2, 3, 2])).to.be('http://iiif.test/image-id/1536,1024,464,476/464,476/0/default.jpg');
|
||||
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/full/500,375/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([1, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/0,0,1024,1024/512,512/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([1, 1, 0])).to.be(
|
||||
'http://iiif.test/image-id/1024,0,976,1024/488,512/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([1, 0, 1])).to.be(
|
||||
'http://iiif.test/image-id/0,1024,1024,476/512,238/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([1, 1, 1])).to.be(
|
||||
'http://iiif.test/image-id/1024,1024,976,476/488,238/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([2, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/0,0,512,512/512,512/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([2, 3, 0])).to.be(
|
||||
'http://iiif.test/image-id/1536,0,464,512/464,512/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([2, 0, 2])).to.be(
|
||||
'http://iiif.test/image-id/0,1024,512,476/512,476/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([2, 3, 2])).to.be(
|
||||
'http://iiif.test/image-id/1536,1024,464,476/464,476/0/default.jpg'
|
||||
);
|
||||
});
|
||||
|
||||
it('provides canonical tile URLs for all provided resolutions if a tileSize also exists', function() {
|
||||
|
||||
it('provides canonical tile URLs for all provided resolutions if a tileSize also exists', function () {
|
||||
const tileUrlFunction = getSource({
|
||||
tileSize: 512,
|
||||
resolutions: [8, 4, 2, 1]
|
||||
resolutions: [8, 4, 2, 1],
|
||||
}).getTileUrlFunction();
|
||||
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be('http://iiif.test/image-id/full/250,/0/default.jpg');
|
||||
expect(tileUrlFunction([1, 0, 0])).to.be('http://iiif.test/image-id/full/500,/0/default.jpg');
|
||||
expect(tileUrlFunction([2, 0, 0])).to.be('http://iiif.test/image-id/0,0,1024,1024/512,/0/default.jpg');
|
||||
expect(tileUrlFunction([2, 1, 0])).to.be('http://iiif.test/image-id/1024,0,976,1024/488,/0/default.jpg');
|
||||
expect(tileUrlFunction([2, 0, 1])).to.be('http://iiif.test/image-id/0,1024,1024,476/512,/0/default.jpg');
|
||||
expect(tileUrlFunction([2, 1, 1])).to.be('http://iiif.test/image-id/1024,1024,976,476/488,/0/default.jpg');
|
||||
expect(tileUrlFunction([3, 0, 0])).to.be('http://iiif.test/image-id/0,0,512,512/512,/0/default.jpg');
|
||||
expect(tileUrlFunction([3, 3, 0])).to.be('http://iiif.test/image-id/1536,0,464,512/464,/0/default.jpg');
|
||||
expect(tileUrlFunction([3, 0, 2])).to.be('http://iiif.test/image-id/0,1024,512,476/512,/0/default.jpg');
|
||||
expect(tileUrlFunction([3, 3, 2])).to.be('http://iiif.test/image-id/1536,1024,464,476/464,/0/default.jpg');
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/full/250,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([1, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/full/500,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([2, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/0,0,1024,1024/512,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([2, 1, 0])).to.be(
|
||||
'http://iiif.test/image-id/1024,0,976,1024/488,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([2, 0, 1])).to.be(
|
||||
'http://iiif.test/image-id/0,1024,1024,476/512,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([2, 1, 1])).to.be(
|
||||
'http://iiif.test/image-id/1024,1024,976,476/488,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([3, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/0,0,512,512/512,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([3, 3, 0])).to.be(
|
||||
'http://iiif.test/image-id/1536,0,464,512/464,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([3, 0, 2])).to.be(
|
||||
'http://iiif.test/image-id/0,1024,512,476/512,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([3, 3, 2])).to.be(
|
||||
'http://iiif.test/image-id/1536,1024,464,476/464,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([4, 0, 0])).to.be(undefined);
|
||||
|
||||
});
|
||||
|
||||
it('supports non square tiles', function() {
|
||||
|
||||
it('supports non square tiles', function () {
|
||||
let tileUrlFunction = getSource({
|
||||
tileSize: [1024, 512]
|
||||
tileSize: [1024, 512],
|
||||
}).getTileUrlFunction();
|
||||
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be('http://iiif.test/image-id/full/500,/0/default.jpg');
|
||||
expect(tileUrlFunction([1, 0, 0])).to.be('http://iiif.test/image-id/0,0,2000,1024/1000,/0/default.jpg');
|
||||
expect(tileUrlFunction([1, 0, 1])).to.be('http://iiif.test/image-id/0,1024,2000,476/1000,/0/default.jpg');
|
||||
expect(tileUrlFunction([2, 0, 0])).to.be('http://iiif.test/image-id/0,0,1024,512/1024,/0/default.jpg');
|
||||
expect(tileUrlFunction([2, 1, 0])).to.be('http://iiif.test/image-id/1024,0,976,512/976,/0/default.jpg');
|
||||
expect(tileUrlFunction([2, 0, 2])).to.be('http://iiif.test/image-id/0,1024,1024,476/1024,/0/default.jpg');
|
||||
expect(tileUrlFunction([2, 1, 2])).to.be('http://iiif.test/image-id/1024,1024,976,476/976,/0/default.jpg');
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/full/500,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([1, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/0,0,2000,1024/1000,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([1, 0, 1])).to.be(
|
||||
'http://iiif.test/image-id/0,1024,2000,476/1000,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([2, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/0,0,1024,512/1024,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([2, 1, 0])).to.be(
|
||||
'http://iiif.test/image-id/1024,0,976,512/976,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([2, 0, 2])).to.be(
|
||||
'http://iiif.test/image-id/0,1024,1024,476/1024,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([2, 1, 2])).to.be(
|
||||
'http://iiif.test/image-id/1024,1024,976,476/976,/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([3, 0, 0])).to.be(undefined);
|
||||
|
||||
tileUrlFunction = getSource({
|
||||
tileSize: [1024, 512],
|
||||
version: Versions.VERSION3
|
||||
version: Versions.VERSION3,
|
||||
}).getTileUrlFunction();
|
||||
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be('http://iiif.test/image-id/full/500,375/0/default.jpg');
|
||||
expect(tileUrlFunction([2, 0, 0])).to.be('http://iiif.test/image-id/0,0,1024,512/1024,512/0/default.jpg');
|
||||
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/full/500,375/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([2, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/0,0,1024,512/1024,512/0/default.jpg'
|
||||
);
|
||||
});
|
||||
|
||||
it('provides tile URLs with default tile size if sufficient supported features are provided', function() {
|
||||
|
||||
it('provides tile URLs with default tile size if sufficient supported features are provided', function () {
|
||||
let tileUrlFunction = getSource({
|
||||
supports: ['regionByPx', 'sizeByW']
|
||||
supports: ['regionByPx', 'sizeByW'],
|
||||
}).getTileUrlFunction();
|
||||
|
||||
const maxZoom = Math.ceil(Math.log2(width / DEFAULT_TILE_SIZE));
|
||||
|
||||
expect(tileUrlFunction([maxZoom, 0, 0])).to.be('http://iiif.test/image-id/0,0,' + DEFAULT_TILE_SIZE + ',' + DEFAULT_TILE_SIZE + '/' + DEFAULT_TILE_SIZE + ',/0/default.jpg');
|
||||
expect(tileUrlFunction([maxZoom, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/0,0,' +
|
||||
DEFAULT_TILE_SIZE +
|
||||
',' +
|
||||
DEFAULT_TILE_SIZE +
|
||||
'/' +
|
||||
DEFAULT_TILE_SIZE +
|
||||
',/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([maxZoom + 1, 0, 0])).to.be(undefined);
|
||||
|
||||
tileUrlFunction = getSource({
|
||||
supports: ['regionByPx', 'sizeByH']
|
||||
supports: ['regionByPx', 'sizeByH'],
|
||||
}).getTileUrlFunction();
|
||||
|
||||
expect(tileUrlFunction([maxZoom, 0, 0])).to.be('http://iiif.test/image-id/0,0,' + DEFAULT_TILE_SIZE + ',' + DEFAULT_TILE_SIZE + '/,' + DEFAULT_TILE_SIZE + '/0/default.jpg');
|
||||
expect(tileUrlFunction([maxZoom, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/0,0,' +
|
||||
DEFAULT_TILE_SIZE +
|
||||
',' +
|
||||
DEFAULT_TILE_SIZE +
|
||||
'/,' +
|
||||
DEFAULT_TILE_SIZE +
|
||||
'/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([maxZoom + 1, 0, 0])).to.be(undefined);
|
||||
|
||||
tileUrlFunction = getSource({
|
||||
supports: ['regionByPx', 'sizeByWh']
|
||||
supports: ['regionByPx', 'sizeByWh'],
|
||||
}).getTileUrlFunction();
|
||||
|
||||
expect(tileUrlFunction([maxZoom, 0, 0])).to.be('http://iiif.test/image-id/0,0,' + DEFAULT_TILE_SIZE + ',' + DEFAULT_TILE_SIZE + '/' + DEFAULT_TILE_SIZE + ',' + DEFAULT_TILE_SIZE + '/0/default.jpg');
|
||||
expect(tileUrlFunction([maxZoom, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/0,0,' +
|
||||
DEFAULT_TILE_SIZE +
|
||||
',' +
|
||||
DEFAULT_TILE_SIZE +
|
||||
'/' +
|
||||
DEFAULT_TILE_SIZE +
|
||||
',' +
|
||||
DEFAULT_TILE_SIZE +
|
||||
'/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([maxZoom + 1, 0, 0])).to.be(undefined);
|
||||
|
||||
tileUrlFunction = getSource({
|
||||
supports: ['regionByPct', 'sizeByPct']
|
||||
supports: ['regionByPct', 'sizeByPct'],
|
||||
}).getTileUrlFunction();
|
||||
|
||||
const tileWPct = (DEFAULT_TILE_SIZE / width * 100).toLocaleString('en', {maximumFractionDigits: 10}),
|
||||
tileHPct = (DEFAULT_TILE_SIZE / height * 100).toLocaleString('en', {maximumFractionDigits: 10});
|
||||
const tileWPct = ((DEFAULT_TILE_SIZE / width) * 100).toLocaleString(
|
||||
'en',
|
||||
{maximumFractionDigits: 10}
|
||||
),
|
||||
tileHPct = ((DEFAULT_TILE_SIZE / height) * 100).toLocaleString('en', {
|
||||
maximumFractionDigits: 10,
|
||||
});
|
||||
|
||||
expect(tileUrlFunction([maxZoom, 0, 0])).to.be('http://iiif.test/image-id/pct:0,0,' + tileWPct + ',' + tileHPct + '/pct:100/0/default.jpg');
|
||||
expect(tileUrlFunction([maxZoom, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/pct:0,0,' +
|
||||
tileWPct +
|
||||
',' +
|
||||
tileHPct +
|
||||
'/pct:100/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([maxZoom + 1, 0, 0])).to.be(undefined);
|
||||
|
||||
});
|
||||
|
||||
it('prefers canonical tile URLs', function() {
|
||||
|
||||
it('prefers canonical tile URLs', function () {
|
||||
let tileUrlFunction = getSource({
|
||||
tileSize: 512,
|
||||
supports: ['regionByPx', 'regionByPct', 'sizeByW', 'sizeByH', 'sizeByWh', 'sizeByPct']
|
||||
supports: [
|
||||
'regionByPx',
|
||||
'regionByPct',
|
||||
'sizeByW',
|
||||
'sizeByH',
|
||||
'sizeByWh',
|
||||
'sizeByPct',
|
||||
],
|
||||
}).getTileUrlFunction();
|
||||
|
||||
expect(tileUrlFunction([2, 0, 0])).to.be('http://iiif.test/image-id/0,0,512,512/512,/0/default.jpg');
|
||||
expect(tileUrlFunction([2, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/0,0,512,512/512,/0/default.jpg'
|
||||
);
|
||||
|
||||
tileUrlFunction = getSource({
|
||||
tileSize: 512,
|
||||
version: Versions.VERSION3,
|
||||
supports: ['regionByPx', 'regionByPct', 'sizeByW', 'sizeByH', 'sizeByWh', 'sizeByPct']
|
||||
supports: [
|
||||
'regionByPx',
|
||||
'regionByPct',
|
||||
'sizeByW',
|
||||
'sizeByH',
|
||||
'sizeByWh',
|
||||
'sizeByPct',
|
||||
],
|
||||
}).getTileUrlFunction();
|
||||
|
||||
expect(tileUrlFunction([2, 0, 0])).to.be('http://iiif.test/image-id/0,0,512,512/512,512/0/default.jpg');
|
||||
|
||||
expect(tileUrlFunction([2, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/0,0,512,512/512,512/0/default.jpg'
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
it('provides correct tile URLs for percentage URL parameter values', function() {
|
||||
|
||||
it('provides correct tile URLs for percentage URL parameter values', function () {
|
||||
const tileUrlFunction = getSource({
|
||||
tileSize: 512,
|
||||
supports: ['regionByPct', 'sizeByPct']
|
||||
supports: ['regionByPct', 'sizeByPct'],
|
||||
}).getTileUrlFunction();
|
||||
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be('http://iiif.test/image-id/full/pct:25/0/default.jpg');
|
||||
expect(tileUrlFunction([0, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/full/pct:25/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([-1, 0, 0])).to.be(undefined);
|
||||
expect(tileUrlFunction([0, 1, 0])).to.be(undefined);
|
||||
expect(tileUrlFunction([0, 0, 1])).to.be(undefined);
|
||||
|
||||
expect(tileUrlFunction([1, 0, 0])).to.be('http://iiif.test/image-id/pct:0,0,51.2,68.2666666667/pct:50/0/default.jpg');
|
||||
expect(tileUrlFunction([1, 1, 0])).to.be('http://iiif.test/image-id/pct:51.2,0,48.8,68.2666666667/pct:50/0/default.jpg');
|
||||
expect(tileUrlFunction([1, 0, 1])).to.be('http://iiif.test/image-id/pct:0,68.2666666667,51.2,31.7333333333/pct:50/0/default.jpg');
|
||||
expect(tileUrlFunction([1, 1, 1])).to.be('http://iiif.test/image-id/pct:51.2,68.2666666667,48.8,31.7333333333/pct:50/0/default.jpg');
|
||||
expect(tileUrlFunction([1, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/pct:0,0,51.2,68.2666666667/pct:50/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([1, 1, 0])).to.be(
|
||||
'http://iiif.test/image-id/pct:51.2,0,48.8,68.2666666667/pct:50/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([1, 0, 1])).to.be(
|
||||
'http://iiif.test/image-id/pct:0,68.2666666667,51.2,31.7333333333/pct:50/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([1, 1, 1])).to.be(
|
||||
'http://iiif.test/image-id/pct:51.2,68.2666666667,48.8,31.7333333333/pct:50/0/default.jpg'
|
||||
);
|
||||
|
||||
expect(tileUrlFunction([2, 0, 0])).to.be('http://iiif.test/image-id/pct:0,0,25.6,34.1333333333/pct:100/0/default.jpg');
|
||||
expect(tileUrlFunction([2, 3, 0])).to.be('http://iiif.test/image-id/pct:76.8,0,23.2,34.1333333333/pct:100/0/default.jpg');
|
||||
expect(tileUrlFunction([2, 0, 2])).to.be('http://iiif.test/image-id/pct:0,68.2666666667,25.6,31.7333333333/pct:100/0/default.jpg');
|
||||
expect(tileUrlFunction([2, 3, 2])).to.be('http://iiif.test/image-id/pct:76.8,68.2666666667,23.2,31.7333333333/pct:100/0/default.jpg');
|
||||
expect(tileUrlFunction([2, 0, 0])).to.be(
|
||||
'http://iiif.test/image-id/pct:0,0,25.6,34.1333333333/pct:100/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([2, 3, 0])).to.be(
|
||||
'http://iiif.test/image-id/pct:76.8,0,23.2,34.1333333333/pct:100/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([2, 0, 2])).to.be(
|
||||
'http://iiif.test/image-id/pct:0,68.2666666667,25.6,31.7333333333/pct:100/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([2, 3, 2])).to.be(
|
||||
'http://iiif.test/image-id/pct:76.8,68.2666666667,23.2,31.7333333333/pct:100/0/default.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([3, 0, 0])).to.be(undefined);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,26 +1,28 @@
|
||||
import ImageArcGISRest from '../../../../src/ol/source/ImageArcGISRest.js';
|
||||
import {get as getProjection} from '../../../../src/ol/proj.js';
|
||||
|
||||
|
||||
describe('ol.source.ImageArcGISRest', function() {
|
||||
|
||||
describe('ol.source.ImageArcGISRest', function () {
|
||||
let pixelRatio, options, projection, proj3857, resolution;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
pixelRatio = 1;
|
||||
projection = getProjection('EPSG:4326');
|
||||
proj3857 = getProjection('EPSG:3857');
|
||||
resolution = 0.1;
|
||||
options = {
|
||||
params: {},
|
||||
url: 'http://example.com/MapServer'
|
||||
url: 'http://example.com/MapServer',
|
||||
};
|
||||
});
|
||||
|
||||
describe('#getImage', function() {
|
||||
|
||||
it('returns a image with the expected URL', function() {
|
||||
describe('#getImage', function () {
|
||||
it('returns a image with the expected URL', function () {
|
||||
const source = new ImageArcGISRest(options);
|
||||
const image = source.getImage([3, 2, -7, 1], resolution, pixelRatio, proj3857);
|
||||
const image = source.getImage(
|
||||
[3, 2, -7, 1],
|
||||
resolution,
|
||||
pixelRatio,
|
||||
proj3857
|
||||
);
|
||||
const uri = new URL(image.src_);
|
||||
expect(uri.protocol).to.be('http:');
|
||||
expect(uri.hostname).to.be('example.com');
|
||||
@@ -31,21 +33,30 @@ describe('ol.source.ImageArcGISRest', function() {
|
||||
expect(queryData.get('IMAGESR')).to.be('3857');
|
||||
expect(queryData.get('BBOXSR')).to.be('3857');
|
||||
expect(queryData.get('TRANSPARENT')).to.be('true');
|
||||
|
||||
});
|
||||
|
||||
it('returns a non floating point DPI value', function() {
|
||||
it('returns a non floating point DPI value', function () {
|
||||
const source = new ImageArcGISRest(options);
|
||||
const image = source.getImage([3, 2, -7, 1.12], resolution, 1.01, proj3857);
|
||||
const image = source.getImage(
|
||||
[3, 2, -7, 1.12],
|
||||
resolution,
|
||||
1.01,
|
||||
proj3857
|
||||
);
|
||||
const uri = new URL(image.src_);
|
||||
const queryData = uri.searchParams;
|
||||
expect(queryData.get('DPI')).to.be('91');
|
||||
});
|
||||
|
||||
it('returns a image with the expected URL for ImageServer', function() {
|
||||
it('returns a image with the expected URL for ImageServer', function () {
|
||||
options.url = 'http://example.com/ImageServer';
|
||||
const source = new ImageArcGISRest(options);
|
||||
const image = source.getImage([3, 2, -7, 1], resolution, pixelRatio, proj3857);
|
||||
const image = source.getImage(
|
||||
[3, 2, -7, 1],
|
||||
resolution,
|
||||
pixelRatio,
|
||||
proj3857
|
||||
);
|
||||
const uri = new URL(image.src_);
|
||||
expect(uri.protocol).to.be('http:');
|
||||
expect(uri.hostname).to.be('example.com');
|
||||
@@ -58,56 +69,73 @@ describe('ol.source.ImageArcGISRest', function() {
|
||||
expect(queryData.get('TRANSPARENT')).to.be('true');
|
||||
});
|
||||
|
||||
it('allows various parameters to be overridden', function() {
|
||||
it('allows various parameters to be overridden', function () {
|
||||
options.params.FORMAT = 'png';
|
||||
options.params.TRANSPARENT = false;
|
||||
const source = new ImageArcGISRest(options);
|
||||
const image = source.getImage([3, 2, -3, 1], resolution, pixelRatio, projection);
|
||||
const image = source.getImage(
|
||||
[3, 2, -3, 1],
|
||||
resolution,
|
||||
pixelRatio,
|
||||
projection
|
||||
);
|
||||
const uri = new URL(image.src_);
|
||||
const queryData = uri.searchParams;
|
||||
expect(queryData.get('FORMAT')).to.be('png');
|
||||
expect(queryData.get('TRANSPARENT')).to.be('false');
|
||||
});
|
||||
|
||||
it('allows adding rest option', function() {
|
||||
it('allows adding rest option', function () {
|
||||
options.params.LAYERS = 'show:1,3,4';
|
||||
const source = new ImageArcGISRest(options);
|
||||
const image = source.getImage([3, 2, -3, 1], resolution, pixelRatio, proj3857);
|
||||
const image = source.getImage(
|
||||
[3, 2, -3, 1],
|
||||
resolution,
|
||||
pixelRatio,
|
||||
proj3857
|
||||
);
|
||||
const uri = new URL(image.src_);
|
||||
const queryData = uri.searchParams;
|
||||
expect(queryData.get('LAYERS')).to.be('show:1,3,4');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#updateParams', function() {
|
||||
|
||||
it('add a new param', function() {
|
||||
describe('#updateParams', function () {
|
||||
it('add a new param', function () {
|
||||
const source = new ImageArcGISRest(options);
|
||||
source.updateParams({'TEST': 'value'});
|
||||
|
||||
const image = source.getImage([3, 2, -7, 1], resolution, pixelRatio, proj3857);
|
||||
const image = source.getImage(
|
||||
[3, 2, -7, 1],
|
||||
resolution,
|
||||
pixelRatio,
|
||||
proj3857
|
||||
);
|
||||
const uri = new URL(image.src_);
|
||||
const queryData = uri.searchParams;
|
||||
expect(queryData.get('TEST')).to.be('value');
|
||||
});
|
||||
|
||||
it('updates an existing param', function() {
|
||||
it('updates an existing param', function () {
|
||||
options.params.TEST = 'value';
|
||||
|
||||
const source = new ImageArcGISRest(options);
|
||||
source.updateParams({'TEST': 'newValue'});
|
||||
|
||||
const image = source.getImage([3, 2, -7, 1], resolution, pixelRatio, proj3857);
|
||||
const image = source.getImage(
|
||||
[3, 2, -7, 1],
|
||||
resolution,
|
||||
pixelRatio,
|
||||
proj3857
|
||||
);
|
||||
const uri = new URL(image.src_);
|
||||
const queryData = uri.searchParams;
|
||||
expect(queryData.get('TEST')).to.be('newValue');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getParams', function() {
|
||||
|
||||
it('verify getting a param', function() {
|
||||
describe('#getParams', function () {
|
||||
it('verify getting a param', function () {
|
||||
options.params.TEST = 'value';
|
||||
const source = new ImageArcGISRest(options);
|
||||
|
||||
@@ -116,7 +144,7 @@ describe('ol.source.ImageArcGISRest', function() {
|
||||
expect(setParams).to.eql({TEST: 'value'});
|
||||
});
|
||||
|
||||
it('verify on adding a param', function() {
|
||||
it('verify on adding a param', function () {
|
||||
options.params.TEST = 'value';
|
||||
|
||||
const source = new ImageArcGISRest(options);
|
||||
@@ -127,7 +155,7 @@ describe('ol.source.ImageArcGISRest', function() {
|
||||
expect(setParams).to.eql({TEST: 'value', TEST2: 'newValue'});
|
||||
});
|
||||
|
||||
it('verify on update a param', function() {
|
||||
it('verify on update a param', function () {
|
||||
options.params.TEST = 'value';
|
||||
|
||||
const source = new ImageArcGISRest(options);
|
||||
@@ -137,12 +165,10 @@ describe('ol.source.ImageArcGISRest', function() {
|
||||
|
||||
expect(setParams).to.eql({TEST: 'newValue'});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getUrl', function() {
|
||||
|
||||
it('verify getting url', function() {
|
||||
describe('#getUrl', function () {
|
||||
it('verify getting url', function () {
|
||||
options.url = 'http://test.com/MapServer';
|
||||
|
||||
const source = new ImageArcGISRest(options);
|
||||
@@ -151,14 +177,10 @@ describe('ol.source.ImageArcGISRest', function() {
|
||||
|
||||
expect(url).to.eql('http://test.com/MapServer');
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
describe('#setUrl', function() {
|
||||
|
||||
it('verify setting url when not set yet', function() {
|
||||
|
||||
describe('#setUrl', function () {
|
||||
it('verify setting url when not set yet', function () {
|
||||
const source = new ImageArcGISRest(options);
|
||||
source.setUrl('http://test.com/MapServer');
|
||||
|
||||
@@ -167,7 +189,7 @@ describe('ol.source.ImageArcGISRest', function() {
|
||||
expect(url).to.eql('http://test.com/MapServer');
|
||||
});
|
||||
|
||||
it('verify setting url with existing url', function() {
|
||||
it('verify setting url with existing url', function () {
|
||||
options.url = 'http://test.com/MapServer';
|
||||
|
||||
const source = new ImageArcGISRest(options);
|
||||
@@ -178,6 +200,4 @@ describe('ol.source.ImageArcGISRest', function() {
|
||||
expect(url).to.eql('http://test2.com/MapServer');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
@@ -1,33 +1,36 @@
|
||||
import Static from '../../../../src/ol/source/ImageStatic.js';
|
||||
import {get as getProjection} from '../../../../src/ol/proj.js';
|
||||
|
||||
|
||||
describe('ol.source.ImageStatic', function() {
|
||||
|
||||
describe('ol.source.ImageStatic', function () {
|
||||
let extent, pixelRatio, projection, resolution;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
extent = [
|
||||
-13637278.73946974, 4543799.13271362,
|
||||
-13617443.330629736, 4553927.038961405];
|
||||
-13637278.73946974,
|
||||
4543799.13271362,
|
||||
-13617443.330629736,
|
||||
4553927.038961405,
|
||||
];
|
||||
pixelRatio = 1;
|
||||
projection = getProjection('EPSG:3857');
|
||||
resolution = 38;
|
||||
});
|
||||
|
||||
describe('#getImage', function() {
|
||||
|
||||
it('scales image to fit imageExtent', function(done) {
|
||||
describe('#getImage', function () {
|
||||
it('scales image to fit imageExtent', function (done) {
|
||||
const source = new Static({
|
||||
url: 'spec/ol/source/images/12-655-1583.png',
|
||||
imageExtent: [
|
||||
-13629027.891360067, 4539747.983913189,
|
||||
-13619243.951739565, 4559315.863154193],
|
||||
projection: projection
|
||||
-13629027.891360067,
|
||||
4539747.983913189,
|
||||
-13619243.951739565,
|
||||
4559315.863154193,
|
||||
],
|
||||
projection: projection,
|
||||
});
|
||||
|
||||
const image = source.getImage(extent, resolution, pixelRatio, projection);
|
||||
|
||||
source.on('imageloadend', function(event) {
|
||||
source.on('imageloadend', function (event) {
|
||||
expect(image.getImage().width).to.be(128);
|
||||
expect(image.getImage().height).to.be(256);
|
||||
done();
|
||||
@@ -36,19 +39,22 @@ describe('ol.source.ImageStatic', function() {
|
||||
image.load();
|
||||
});
|
||||
|
||||
it('respects imageSize', function(done) {
|
||||
it('respects imageSize', function (done) {
|
||||
const source = new Static({
|
||||
url: 'spec/ol/source/images/12-655-1583.png',
|
||||
imageExtent: [
|
||||
-13629027.891360067, 4539747.983913189,
|
||||
-13619243.951739565, 4559315.863154193],
|
||||
-13629027.891360067,
|
||||
4539747.983913189,
|
||||
-13619243.951739565,
|
||||
4559315.863154193,
|
||||
],
|
||||
imageSize: [254, 254],
|
||||
projection: projection
|
||||
projection: projection,
|
||||
});
|
||||
|
||||
const image = source.getImage(extent, resolution, pixelRatio, projection);
|
||||
|
||||
source.on('imageloadend', function(event) {
|
||||
source.on('imageloadend', function (event) {
|
||||
expect(image.getImage().width).to.be(127);
|
||||
expect(image.getImage().height).to.be(254);
|
||||
done();
|
||||
@@ -57,13 +63,16 @@ describe('ol.source.ImageStatic', function() {
|
||||
image.load();
|
||||
});
|
||||
|
||||
it('triggers image load events', function(done) {
|
||||
it('triggers image load events', function (done) {
|
||||
const source = new Static({
|
||||
url: 'spec/ol/source/images/12-655-1583.png',
|
||||
imageExtent: [
|
||||
-13629027.891360067, 4539747.983913189,
|
||||
-13619243.951739565, 4549531.923533691],
|
||||
projection: projection
|
||||
-13629027.891360067,
|
||||
4539747.983913189,
|
||||
-13619243.951739565,
|
||||
4549531.923533691,
|
||||
],
|
||||
projection: projection,
|
||||
});
|
||||
|
||||
const imageloadstart = sinon.spy();
|
||||
@@ -71,7 +80,7 @@ describe('ol.source.ImageStatic', function() {
|
||||
|
||||
source.on('imageloadstart', imageloadstart);
|
||||
source.on('imageloaderror', imageloaderror);
|
||||
source.on('imageloadend', function(event) {
|
||||
source.on('imageloadend', function (event) {
|
||||
expect(imageloadstart.callCount).to.be(1);
|
||||
expect(imageloaderror.callCount).to.be(0);
|
||||
done();
|
||||
|
||||
@@ -1,47 +1,49 @@
|
||||
import ImageWMS from '../../../../src/ol/source/ImageWMS.js';
|
||||
import Image from '../../../../src/ol/layer/Image.js';
|
||||
import {get as getProjection} from '../../../../src/ol/proj.js';
|
||||
import {getWidth, getHeight} from '../../../../src/ol/extent.js';
|
||||
import View from '../../../../src/ol/View.js';
|
||||
import Map from '../../../../src/ol/Map.js';
|
||||
import ImageState from '../../../../src/ol/ImageState.js';
|
||||
import ImageWMS from '../../../../src/ol/source/ImageWMS.js';
|
||||
import Map from '../../../../src/ol/Map.js';
|
||||
import View from '../../../../src/ol/View.js';
|
||||
import {getHeight, getWidth} from '../../../../src/ol/extent.js';
|
||||
import {get as getProjection} from '../../../../src/ol/proj.js';
|
||||
|
||||
|
||||
describe('ol.source.ImageWMS', function() {
|
||||
|
||||
describe('ol.source.ImageWMS', function () {
|
||||
let extent, pixelRatio, options, optionsReproj, projection, resolution;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
extent = [10, 20, 30, 40];
|
||||
pixelRatio = 1;
|
||||
projection = getProjection('EPSG:4326');
|
||||
resolution = 0.1;
|
||||
options = {
|
||||
params: {
|
||||
'LAYERS': 'layer'
|
||||
},
|
||||
ratio: 1,
|
||||
url: 'http://example.com/wms'
|
||||
};
|
||||
optionsReproj = {
|
||||
params: {
|
||||
'LAYERS': 'layer'
|
||||
'LAYERS': 'layer',
|
||||
},
|
||||
ratio: 1,
|
||||
url: 'http://example.com/wms',
|
||||
projection: 'EPSG:3857'
|
||||
};
|
||||
optionsReproj = {
|
||||
params: {
|
||||
'LAYERS': 'layer',
|
||||
},
|
||||
ratio: 1,
|
||||
url: 'http://example.com/wms',
|
||||
projection: 'EPSG:3857',
|
||||
};
|
||||
});
|
||||
|
||||
describe('#getImage', function() {
|
||||
|
||||
it('returns the expected image URL', function() {
|
||||
[1, 1.5].forEach(function(ratio) {
|
||||
describe('#getImage', function () {
|
||||
it('returns the expected image URL', function () {
|
||||
[1, 1.5].forEach(function (ratio) {
|
||||
options.ratio = ratio;
|
||||
const source = new ImageWMS(options);
|
||||
const viewExtent = [10, 20, 30.1, 39.9];
|
||||
const viewWidth = getWidth(viewExtent);
|
||||
const viewHeight = getHeight(viewExtent);
|
||||
const image = source.getImage(viewExtent, resolution, pixelRatio, projection);
|
||||
const image = source.getImage(
|
||||
viewExtent,
|
||||
resolution,
|
||||
pixelRatio,
|
||||
projection
|
||||
);
|
||||
const uri = new URL(image.src_);
|
||||
const queryData = uri.searchParams;
|
||||
const imageWidth = Number(queryData.get('WIDTH'));
|
||||
@@ -49,13 +51,13 @@ describe('ol.source.ImageWMS', function() {
|
||||
const bbox = queryData.get('BBOX').split(',').map(Number);
|
||||
const bboxAspectRatio = (bbox[3] - bbox[1]) / (bbox[2] - bbox[0]);
|
||||
const imageAspectRatio = imageWidth / imageHeight;
|
||||
expect (imageWidth).to.be(Math.ceil(viewWidth / resolution * ratio));
|
||||
expect (imageHeight).to.be(Math.ceil(viewHeight / resolution * ratio));
|
||||
expect(imageWidth).to.be(Math.ceil((viewWidth / resolution) * ratio));
|
||||
expect(imageHeight).to.be(Math.ceil((viewHeight / resolution) * ratio));
|
||||
expect(bboxAspectRatio).to.roughlyEqual(imageAspectRatio, 1e-12);
|
||||
});
|
||||
});
|
||||
|
||||
it('uses correct WIDTH and HEIGHT for HiDPI devices', function() {
|
||||
it('uses correct WIDTH and HEIGHT for HiDPI devices', function () {
|
||||
pixelRatio = 2;
|
||||
options.serverType = 'geoserver';
|
||||
const source = new ImageWMS(options);
|
||||
@@ -68,10 +70,15 @@ describe('ol.source.ImageWMS', function() {
|
||||
expect(height).to.be(400);
|
||||
});
|
||||
|
||||
it('requests integer WIDTH and HEIGHT', function() {
|
||||
it('requests integer WIDTH and HEIGHT', function () {
|
||||
options.ratio = 1.5;
|
||||
const source = new ImageWMS(options);
|
||||
const image = source.getImage([10, 20, 30.1, 39.9], resolution, pixelRatio, projection);
|
||||
const image = source.getImage(
|
||||
[10, 20, 30.1, 39.9],
|
||||
resolution,
|
||||
pixelRatio,
|
||||
projection
|
||||
);
|
||||
const uri = new URL(image.src_);
|
||||
const queryData = uri.searchParams;
|
||||
const width = parseFloat(queryData.get('WIDTH'));
|
||||
@@ -80,7 +87,7 @@ describe('ol.source.ImageWMS', function() {
|
||||
expect(height).to.be(Math.round(height));
|
||||
});
|
||||
|
||||
it('sets WIDTH and HEIGHT to match the aspect ratio of BBOX', function() {
|
||||
it('sets WIDTH and HEIGHT to match the aspect ratio of BBOX', function () {
|
||||
const source = new ImageWMS(options);
|
||||
const image = source.getImage(extent, resolution, pixelRatio, projection);
|
||||
const uri = new URL(image.src_);
|
||||
@@ -103,7 +110,7 @@ describe('ol.source.ImageWMS', function() {
|
||||
expect(uri.hash.replace('#', '')).to.be.empty();
|
||||
});
|
||||
|
||||
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 ImageWMS(options);
|
||||
const image = source.getImage(extent, resolution, pixelRatio, projection);
|
||||
@@ -113,7 +120,7 @@ describe('ol.source.ImageWMS', 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 ImageWMS(options);
|
||||
@@ -124,7 +131,7 @@ describe('ol.source.ImageWMS', 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 ImageWMS(options);
|
||||
const image = source.getImage(extent, resolution, pixelRatio, projection);
|
||||
@@ -133,7 +140,7 @@ describe('ol.source.ImageWMS', 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 ImageWMS(options);
|
||||
projection = getProjection('CRS:84');
|
||||
const image = source.getImage(extent, resolution, pixelRatio, projection);
|
||||
@@ -142,17 +149,16 @@ describe('ol.source.ImageWMS', function() {
|
||||
expect(queryData.get('BBOX')).to.be('10,20,30,40');
|
||||
});
|
||||
|
||||
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 ImageWMS(options);
|
||||
const image =
|
||||
source.getImage(extent, resolution, pixelRatio, projection);
|
||||
const image = source.getImage(extent, resolution, pixelRatio, projection);
|
||||
const uri = new URL(image.src_);
|
||||
const queryData = uri.searchParams;
|
||||
expect(queryData.get('BBOX')).to.be('10,20,30,40');
|
||||
});
|
||||
|
||||
it('sets MAP_RESOLUTION when the server is MapServer', function() {
|
||||
it('sets MAP_RESOLUTION when the server is MapServer', function () {
|
||||
options.serverType = 'mapserver';
|
||||
const source = new ImageWMS(options);
|
||||
pixelRatio = 2;
|
||||
@@ -162,7 +168,7 @@ describe('ol.source.ImageWMS', function() {
|
||||
expect(queryData.get('MAP_RESOLUTION')).to.be('180');
|
||||
});
|
||||
|
||||
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 ImageWMS(options);
|
||||
pixelRatio = 2;
|
||||
@@ -172,7 +178,7 @@ describe('ol.source.ImageWMS', 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 ImageWMS(options);
|
||||
options.params.FORMAT_OPTIONS = 'param1:value1';
|
||||
@@ -183,19 +189,17 @@ describe('ol.source.ImageWMS', 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 ImageWMS(options);
|
||||
pixelRatio = 1.325;
|
||||
const image =
|
||||
source.getImage(extent, resolution, pixelRatio, projection);
|
||||
const uri = new URL(image.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 ImageWMS(options);
|
||||
pixelRatio = 1.325;
|
||||
const image = source.getImage(extent, resolution, pixelRatio, projection);
|
||||
const uri = new URL(image.src_);
|
||||
const queryData = uri.searchParams;
|
||||
expect(queryData.get('FORMAT_OPTIONS')).to.be('dpi:119');
|
||||
});
|
||||
|
||||
it('sets DPI when the server is QGIS', function() {
|
||||
it('sets DPI when the server is QGIS', function () {
|
||||
options.serverType = 'qgis';
|
||||
const source = new ImageWMS(options);
|
||||
pixelRatio = 2;
|
||||
@@ -205,7 +209,7 @@ describe('ol.source.ImageWMS', function() {
|
||||
expect(queryData.get('DPI')).to.be('180');
|
||||
});
|
||||
|
||||
it('creates an image with a custom imageLoadFunction', function() {
|
||||
it('creates an image with a custom imageLoadFunction', function () {
|
||||
const imageLoadFunction = sinon.spy();
|
||||
options.imageLoadFunction = imageLoadFunction;
|
||||
const source = new ImageWMS(options);
|
||||
@@ -215,41 +219,59 @@ describe('ol.source.ImageWMS', function() {
|
||||
expect(imageLoadFunction.calledWith(image, image.src_)).to.be(true);
|
||||
});
|
||||
|
||||
it('returns same image for consecutive calls with same args', function() {
|
||||
it('returns same image for consecutive calls with same args', function () {
|
||||
const extent = [10.01, 20, 30.01, 40];
|
||||
const source = new ImageWMS(options);
|
||||
const image1 = source.getImage(extent, resolution, pixelRatio, projection);
|
||||
const image2 = source.getImage(extent, resolution, pixelRatio, projection);
|
||||
const image1 = source.getImage(
|
||||
extent,
|
||||
resolution,
|
||||
pixelRatio,
|
||||
projection
|
||||
);
|
||||
const image2 = source.getImage(
|
||||
extent,
|
||||
resolution,
|
||||
pixelRatio,
|
||||
projection
|
||||
);
|
||||
expect(image1).to.equal(image2);
|
||||
});
|
||||
|
||||
it('returns same image for calls with similar extents', function() {
|
||||
it('returns same image for calls with similar extents', function () {
|
||||
options.ratio = 1.5;
|
||||
const source = new ImageWMS(options);
|
||||
let extent = [10.01, 20, 30.01, 40];
|
||||
const image1 = source.getImage(extent, resolution, pixelRatio, projection);
|
||||
const image1 = source.getImage(
|
||||
extent,
|
||||
resolution,
|
||||
pixelRatio,
|
||||
projection
|
||||
);
|
||||
extent = [10.01, 20.1, 30.01, 40.1];
|
||||
const image2 = source.getImage(extent, resolution, pixelRatio, projection);
|
||||
const image2 = source.getImage(
|
||||
extent,
|
||||
resolution,
|
||||
pixelRatio,
|
||||
projection
|
||||
);
|
||||
expect(image1).to.equal(image2);
|
||||
});
|
||||
|
||||
it('calculates correct image size with ratio', function() {
|
||||
it('calculates correct image size with ratio', function () {
|
||||
options.ratio = 1.5;
|
||||
const source = new ImageWMS(options);
|
||||
const extent = [10, 5, 30, 45];
|
||||
source.getImage(extent, resolution, pixelRatio, projection);
|
||||
expect(source.imageSize_).to.eql([300, 600]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getFeatureInfoUrl', function() {
|
||||
|
||||
it('returns the expected GetFeatureInfo URL', function() {
|
||||
describe('#getFeatureInfoUrl', function () {
|
||||
it('returns the expected GetFeatureInfo URL', function () {
|
||||
const source = new ImageWMS(options);
|
||||
const url = source.getFeatureInfoUrl(
|
||||
[20, 30], resolution, projection,
|
||||
{INFO_FORMAT: 'text/plain'});
|
||||
const url = source.getFeatureInfoUrl([20, 30], resolution, projection, {
|
||||
INFO_FORMAT: 'text/plain',
|
||||
});
|
||||
const uri = new URL(url);
|
||||
expect(uri.protocol).to.be('http:');
|
||||
expect(uri.hostname).to.be('example.com');
|
||||
@@ -273,17 +295,19 @@ describe('ol.source.ImageWMS', 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 ImageWMS(optionsReproj);
|
||||
const url = source.getFeatureInfoUrl(
|
||||
[20, 30], resolution, projection,
|
||||
{INFO_FORMAT: 'text/plain'});
|
||||
const url = source.getFeatureInfoUrl([20, 30], resolution, projection, {
|
||||
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('1577259.402312431,2854419.4299513334,2875520.229418512,4152680.2570574144');
|
||||
expect(queryData.get('BBOX')).to.be(
|
||||
'1577259.402312431,2854419.4299513334,2875520.229418512,4152680.2570574144'
|
||||
);
|
||||
expect(queryData.get('CRS')).to.be('EPSG:3857');
|
||||
expect(queryData.get('FORMAT')).to.be('image/png');
|
||||
expect(queryData.get('HEIGHT')).to.be('101');
|
||||
@@ -301,11 +325,12 @@ describe('ol.source.ImageWMS', 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 ImageWMS(options);
|
||||
const url = source.getFeatureInfoUrl(
|
||||
[20, 30], resolution, projection,
|
||||
{INFO_FORMAT: 'text/plain', QUERY_LAYERS: 'foo,bar'});
|
||||
const url = source.getFeatureInfoUrl([20, 30], resolution, projection, {
|
||||
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');
|
||||
@@ -330,9 +355,8 @@ describe('ol.source.ImageWMS', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getLegendUrl', function() {
|
||||
|
||||
it('returns the GetLegendGraphic url as expected', function() {
|
||||
describe('#getLegendUrl', function () {
|
||||
it('returns the GetLegendGraphic url as expected', function () {
|
||||
const source = new ImageWMS(options);
|
||||
const url = source.getLegendUrl(resolution);
|
||||
const uri = new URL(url);
|
||||
@@ -348,7 +372,7 @@ describe('ol.source.ImageWMS', 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 ImageWMS(options);
|
||||
const url = source.getLegendUrl();
|
||||
const uri = new URL(url);
|
||||
@@ -356,7 +380,7 @@ describe('ol.source.ImageWMS', 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 ImageWMS(options);
|
||||
const url = source.getLegendUrl(resolution, {
|
||||
STYLE: 'STYLE_VALUE',
|
||||
@@ -369,7 +393,7 @@ describe('ol.source.ImageWMS', 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:');
|
||||
@@ -393,16 +417,14 @@ describe('ol.source.ImageWMS', function() {
|
||||
expect(queryData.get('EXCEPTIONS')).to.be('EXCEPTIONS_VALUE');
|
||||
expect(queryData.get('LANGUAGE')).to.be('LANGUAGE_VALUE');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#refresh()', function() {
|
||||
|
||||
describe('#refresh()', function () {
|
||||
let map, source;
|
||||
let callCount = 0;
|
||||
beforeEach(function(done) {
|
||||
beforeEach(function (done) {
|
||||
source = new ImageWMS(options);
|
||||
source.setImageLoadFunction(function(image) {
|
||||
source.setImageLoadFunction(function (image) {
|
||||
++callCount;
|
||||
image.state = ImageState.LOADED;
|
||||
source.loading = false;
|
||||
@@ -415,33 +437,31 @@ describe('ol.source.ImageWMS', function() {
|
||||
target: target,
|
||||
layers: [
|
||||
new Image({
|
||||
source: source
|
||||
})
|
||||
source: source,
|
||||
}),
|
||||
],
|
||||
view: new View({
|
||||
center: [0, 0],
|
||||
zoom: 0
|
||||
})
|
||||
zoom: 0,
|
||||
}),
|
||||
});
|
||||
map.once('rendercomplete', function() {
|
||||
map.once('rendercomplete', function () {
|
||||
callCount = 0;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
document.body.removeChild(map.getTargetElement());
|
||||
map.setTarget(null);
|
||||
});
|
||||
|
||||
it('reloads from server', function(done) {
|
||||
map.once('rendercomplete', function() {
|
||||
it('reloads from server', function (done) {
|
||||
map.once('rendercomplete', function () {
|
||||
expect(callCount).to.be(1);
|
||||
done();
|
||||
});
|
||||
source.refresh();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,30 +1,31 @@
|
||||
import Map from '../../../../src/ol/Map.js';
|
||||
import TileState from '../../../../src/ol/TileState.js';
|
||||
import View from '../../../../src/ol/View.js';
|
||||
import Feature from '../../../../src/ol/Feature.js';
|
||||
import ImageLayer from '../../../../src/ol/layer/Image.js';
|
||||
import VectorImageLayer from '../../../../src/ol/layer/VectorImage.js';
|
||||
import Map from '../../../../src/ol/Map.js';
|
||||
import Point from '../../../../src/ol/geom/Point.js';
|
||||
import Projection from '../../../../src/ol/proj/Projection.js';
|
||||
import Static from '../../../../src/ol/source/ImageStatic.js';
|
||||
import RasterSource from '../../../../src/ol/source/Raster.js';
|
||||
import Source from '../../../../src/ol/source/Source.js';
|
||||
import Static from '../../../../src/ol/source/ImageStatic.js';
|
||||
import TileSource from '../../../../src/ol/source/Tile.js';
|
||||
import TileState from '../../../../src/ol/TileState.js';
|
||||
import VectorImageLayer from '../../../../src/ol/layer/VectorImage.js';
|
||||
import VectorSource from '../../../../src/ol/source/Vector.js';
|
||||
import Feature from '../../../../src/ol/Feature.js';
|
||||
import Point from '../../../../src/ol/geom/Point.js';
|
||||
import {Style, Circle, Fill} from '../../../../src/ol/style.js';
|
||||
import View from '../../../../src/ol/View.js';
|
||||
import XYZ from '../../../../src/ol/source/XYZ.js';
|
||||
import {Circle, Fill, Style} from '../../../../src/ol/style.js';
|
||||
|
||||
const red = 'data:image/gif;base64,R0lGODlhAQABAPAAAP8AAP///yH5BAAAAAAALAAAAAA' +
|
||||
'BAAEAAAICRAEAOw==';
|
||||
const red =
|
||||
'data:image/gif;base64,R0lGODlhAQABAPAAAP8AAP///yH5BAAAAAAALAAAAAA' +
|
||||
'BAAEAAAICRAEAOw==';
|
||||
|
||||
const green = 'data:image/gif;base64,R0lGODlhAQABAPAAAAD/AP///yH5BAAAAAAALAAAA' +
|
||||
'AABAAEAAAICRAEAOw==';
|
||||
|
||||
where('Uint8ClampedArray').describe('ol.source.Raster', function() {
|
||||
const green =
|
||||
'data:image/gif;base64,R0lGODlhAQABAPAAAAD/AP///yH5BAAAAAAALAAAA' +
|
||||
'AABAAEAAAICRAEAOw==';
|
||||
|
||||
where('Uint8ClampedArray').describe('ol.source.Raster', function () {
|
||||
let map, target, redSource, greenSource, blueSource, raster;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
target = document.createElement('div');
|
||||
|
||||
const style = target.style;
|
||||
@@ -40,33 +41,33 @@ where('Uint8ClampedArray').describe('ol.source.Raster', function() {
|
||||
redSource = new Static({
|
||||
url: red,
|
||||
imageExtent: extent,
|
||||
attributions: ['red raster source']
|
||||
attributions: ['red raster source'],
|
||||
});
|
||||
|
||||
greenSource = new Static({
|
||||
url: green,
|
||||
imageExtent: extent,
|
||||
attributions: ['green raster source']
|
||||
attributions: ['green raster source'],
|
||||
});
|
||||
|
||||
blueSource = new VectorImageLayer({
|
||||
source: new VectorSource({
|
||||
features: [new Feature(new Point([0, 0]))]
|
||||
features: [new Feature(new Point([0, 0]))],
|
||||
}),
|
||||
style: new Style({
|
||||
image: new Circle({
|
||||
radius: 3,
|
||||
fill: new Fill({color: 'blue'})
|
||||
})
|
||||
})
|
||||
fill: new Fill({color: 'blue'}),
|
||||
}),
|
||||
}),
|
||||
});
|
||||
|
||||
raster = new RasterSource({
|
||||
threads: 0,
|
||||
sources: [redSource, greenSource, blueSource],
|
||||
operation: function(inputs) {
|
||||
operation: function (inputs) {
|
||||
return inputs[0];
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
map = new Map({
|
||||
@@ -76,18 +77,18 @@ where('Uint8ClampedArray').describe('ol.source.Raster', function() {
|
||||
projection: new Projection({
|
||||
code: 'image',
|
||||
units: 'pixels',
|
||||
extent: extent
|
||||
})
|
||||
extent: extent,
|
||||
}),
|
||||
}),
|
||||
layers: [
|
||||
new ImageLayer({
|
||||
source: raster
|
||||
})
|
||||
]
|
||||
source: raster,
|
||||
}),
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
if (map) {
|
||||
disposeMap(map);
|
||||
}
|
||||
@@ -98,31 +99,29 @@ where('Uint8ClampedArray').describe('ol.source.Raster', function() {
|
||||
blueSource.dispose();
|
||||
});
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('returns a raster source', function() {
|
||||
describe('constructor', function () {
|
||||
it('returns a raster source', function () {
|
||||
const source = new RasterSource({
|
||||
threads: 0,
|
||||
sources: [new TileSource({})]
|
||||
sources: [new TileSource({})],
|
||||
});
|
||||
expect(source).to.be.a(Source);
|
||||
expect(source).to.be.a(RasterSource);
|
||||
});
|
||||
|
||||
it('defaults to "pixel" operation', function(done) {
|
||||
|
||||
it('defaults to "pixel" operation', function (done) {
|
||||
const log = [];
|
||||
|
||||
const source = new RasterSource({
|
||||
threads: 0,
|
||||
sources: [redSource, greenSource, blueSource],
|
||||
operation: function(inputs) {
|
||||
operation: function (inputs) {
|
||||
log.push(inputs);
|
||||
return inputs[0];
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
source.once('afteroperations', function() {
|
||||
source.once('afteroperations', function () {
|
||||
expect(log.length).to.equal(4);
|
||||
const inputs = log[0];
|
||||
const pixel = inputs[0];
|
||||
@@ -134,23 +133,22 @@ where('Uint8ClampedArray').describe('ol.source.Raster', function() {
|
||||
const view = map.getView();
|
||||
view.setCenter([0, 0]);
|
||||
view.setZoom(0);
|
||||
|
||||
});
|
||||
|
||||
it('allows operation type to be set to "image"', function(done) {
|
||||
it('allows operation type to be set to "image"', function (done) {
|
||||
const log = [];
|
||||
|
||||
const source = new RasterSource({
|
||||
operationType: 'image',
|
||||
threads: 0,
|
||||
sources: [redSource, greenSource, blueSource],
|
||||
operation: function(inputs) {
|
||||
operation: function (inputs) {
|
||||
log.push(inputs);
|
||||
return inputs[0];
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
source.once('afteroperations', function() {
|
||||
source.once('afteroperations', function () {
|
||||
expect(log.length).to.equal(1);
|
||||
const inputs = log[0];
|
||||
const imageData = inputs[0];
|
||||
@@ -164,33 +162,31 @@ where('Uint8ClampedArray').describe('ol.source.Raster', function() {
|
||||
const view = map.getView();
|
||||
view.setCenter([0, 0]);
|
||||
view.setZoom(0);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('config option `attributions`', function() {
|
||||
it('handles empty attributions', function() {
|
||||
describe('config option `attributions`', function () {
|
||||
it('handles empty attributions', function () {
|
||||
const blue = new RasterSource({
|
||||
operationType: 'image',
|
||||
threads: 0,
|
||||
sources: [blueSource],
|
||||
operation: function(inputs) {
|
||||
operation: function (inputs) {
|
||||
return inputs[0];
|
||||
}
|
||||
},
|
||||
});
|
||||
const blueAttributions = blue.getAttributions();
|
||||
expect(blueAttributions()).to.be(null);
|
||||
});
|
||||
|
||||
it('shows single attributions', function() {
|
||||
it('shows single attributions', function () {
|
||||
const red = new RasterSource({
|
||||
operationType: 'image',
|
||||
threads: 0,
|
||||
sources: [redSource],
|
||||
operation: function(inputs) {
|
||||
operation: function (inputs) {
|
||||
return inputs[0];
|
||||
}
|
||||
},
|
||||
});
|
||||
const redAttribtuions = red.getAttributions();
|
||||
|
||||
@@ -199,30 +195,30 @@ where('Uint8ClampedArray').describe('ol.source.Raster', function() {
|
||||
expect(redAttribtuions()).to.eql(['red raster source']);
|
||||
});
|
||||
|
||||
it('concatinates multiple attributions', function() {
|
||||
it('concatinates multiple attributions', function () {
|
||||
const redGreen = new RasterSource({
|
||||
operationType: 'image',
|
||||
threads: 0,
|
||||
sources: [redSource, greenSource],
|
||||
operation: function(inputs) {
|
||||
operation: function (inputs) {
|
||||
return inputs[0];
|
||||
}
|
||||
},
|
||||
});
|
||||
const redGreenAttributions = redGreen.getAttributions();
|
||||
|
||||
expect(redGreenAttributions()).to.not.be(null);
|
||||
expect(typeof redGreenAttributions).to.be('function');
|
||||
expect(redGreenAttributions()).to.eql(['red raster source', 'green raster source']);
|
||||
expect(redGreenAttributions()).to.eql([
|
||||
'red raster source',
|
||||
'green raster source',
|
||||
]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setOperation()', function() {
|
||||
|
||||
it('allows operation to be set', function(done) {
|
||||
|
||||
describe('#setOperation()', function () {
|
||||
it('allows operation to be set', function (done) {
|
||||
let count = 0;
|
||||
raster.setOperation(function(pixels) {
|
||||
raster.setOperation(function (pixels) {
|
||||
++count;
|
||||
const redPixel = pixels[0];
|
||||
const greenPixel = pixels[1];
|
||||
@@ -237,46 +233,40 @@ where('Uint8ClampedArray').describe('ol.source.Raster', function() {
|
||||
view.setCenter([0, 0]);
|
||||
view.setZoom(0);
|
||||
|
||||
raster.once('afteroperations', function(event) {
|
||||
raster.once('afteroperations', function (event) {
|
||||
expect(count).to.equal(4);
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('updates and re-runs the operation', function(done) {
|
||||
|
||||
it('updates and re-runs the operation', function (done) {
|
||||
const view = map.getView();
|
||||
view.setCenter([0, 0]);
|
||||
view.setZoom(0);
|
||||
|
||||
let count = 0;
|
||||
raster.on('afteroperations', function(event) {
|
||||
raster.on('afteroperations', function (event) {
|
||||
++count;
|
||||
if (count === 1) {
|
||||
raster.setOperation(function(inputs) {
|
||||
raster.setOperation(function (inputs) {
|
||||
return inputs[0];
|
||||
});
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('beforeoperations', function() {
|
||||
|
||||
it('gets called before operations are run', function(done) {
|
||||
|
||||
describe('beforeoperations', function () {
|
||||
it('gets called before operations are run', function (done) {
|
||||
let count = 0;
|
||||
raster.setOperation(function(inputs) {
|
||||
raster.setOperation(function (inputs) {
|
||||
++count;
|
||||
return inputs[0];
|
||||
});
|
||||
|
||||
raster.once('beforeoperations', function(event) {
|
||||
raster.once('beforeoperations', function (event) {
|
||||
expect(count).to.equal(0);
|
||||
expect(!!event).to.be(true);
|
||||
expect(event.extent).to.be.an('array');
|
||||
@@ -288,22 +278,19 @@ where('Uint8ClampedArray').describe('ol.source.Raster', function() {
|
||||
const view = map.getView();
|
||||
view.setCenter([0, 0]);
|
||||
view.setZoom(0);
|
||||
|
||||
});
|
||||
|
||||
|
||||
it('allows data to be set for the operation', function(done) {
|
||||
|
||||
raster.setOperation(function(inputs, data) {
|
||||
it('allows data to be set for the operation', function (done) {
|
||||
raster.setOperation(function (inputs, data) {
|
||||
++data.count;
|
||||
return inputs[0];
|
||||
});
|
||||
|
||||
raster.on('beforeoperations', function(event) {
|
||||
raster.on('beforeoperations', function (event) {
|
||||
event.data.count = 0;
|
||||
});
|
||||
|
||||
raster.once('afteroperations', function(event) {
|
||||
raster.once('afteroperations', function (event) {
|
||||
expect(event.data.count).to.equal(4);
|
||||
done();
|
||||
});
|
||||
@@ -311,22 +298,18 @@ where('Uint8ClampedArray').describe('ol.source.Raster', function() {
|
||||
const view = map.getView();
|
||||
view.setCenter([0, 0]);
|
||||
view.setZoom(0);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('afteroperations', function() {
|
||||
|
||||
it('gets called after operations are run', function(done) {
|
||||
|
||||
describe('afteroperations', function () {
|
||||
it('gets called after operations are run', function (done) {
|
||||
let count = 0;
|
||||
raster.setOperation(function(inputs) {
|
||||
raster.setOperation(function (inputs) {
|
||||
++count;
|
||||
return inputs[0];
|
||||
});
|
||||
|
||||
raster.once('afteroperations', function(event) {
|
||||
raster.once('afteroperations', function (event) {
|
||||
expect(count).to.equal(4);
|
||||
expect(!!event).to.be(true);
|
||||
expect(event.extent).to.be.an('array');
|
||||
@@ -338,17 +321,15 @@ where('Uint8ClampedArray').describe('ol.source.Raster', function() {
|
||||
const view = map.getView();
|
||||
view.setCenter([0, 0]);
|
||||
view.setZoom(0);
|
||||
|
||||
});
|
||||
|
||||
it('receives data set by the operation', function(done) {
|
||||
|
||||
raster.setOperation(function(inputs, data) {
|
||||
it('receives data set by the operation', function (done) {
|
||||
raster.setOperation(function (inputs, data) {
|
||||
data.message = 'hello world';
|
||||
return inputs[0];
|
||||
});
|
||||
|
||||
raster.once('afteroperations', function(event) {
|
||||
raster.once('afteroperations', function (event) {
|
||||
expect(event.data.message).to.equal('hello world');
|
||||
done();
|
||||
});
|
||||
@@ -356,57 +337,54 @@ where('Uint8ClampedArray').describe('ol.source.Raster', function() {
|
||||
const view = map.getView();
|
||||
view.setCenter([0, 0]);
|
||||
view.setZoom(0);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('tile loading', function() {
|
||||
describe('tile loading', function () {
|
||||
let map2;
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
disposeMap(map2);
|
||||
map2 = null;
|
||||
});
|
||||
|
||||
it('is initiated on the underlying source', function(done) {
|
||||
|
||||
it('is initiated on the underlying source', function (done) {
|
||||
const source = new XYZ({
|
||||
url: 'spec/ol/data/osm-{z}-{x}-{y}.png'
|
||||
url: 'spec/ol/data/osm-{z}-{x}-{y}.png',
|
||||
});
|
||||
|
||||
raster = new RasterSource({
|
||||
threads: 0,
|
||||
sources: [source],
|
||||
operation: function(inputs) {
|
||||
operation: function (inputs) {
|
||||
return inputs[0];
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
map2 = new Map({
|
||||
target: target,
|
||||
view: new View({
|
||||
center: [0, 0],
|
||||
zoom: 0
|
||||
zoom: 0,
|
||||
}),
|
||||
layers: [
|
||||
new ImageLayer({
|
||||
source: raster
|
||||
})
|
||||
]
|
||||
source: raster,
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
const tileCache = source.tileCache;
|
||||
|
||||
expect(tileCache.getCount()).to.equal(0);
|
||||
|
||||
map2.once('moveend', function() {
|
||||
map2.once('moveend', function () {
|
||||
expect(tileCache.getCount()).to.equal(1);
|
||||
const state = tileCache.peekLast().getState();
|
||||
expect(state === TileState.LOADING || state === TileState.LOADED).to.be(true);
|
||||
expect(state === TileState.LOADING || state === TileState.LOADED).to.be(
|
||||
true
|
||||
);
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,28 +1,26 @@
|
||||
import {get as getProjection} from '../../../../src/ol/proj.js';
|
||||
import Source from '../../../../src/ol/source/Source.js';
|
||||
import {get as getProjection} from '../../../../src/ol/proj.js';
|
||||
|
||||
|
||||
describe('ol.source.Source', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('returns a source', function() {
|
||||
describe('ol.source.Source', function () {
|
||||
describe('constructor', function () {
|
||||
it('returns a source', function () {
|
||||
const source = new Source({
|
||||
projection: getProjection('EPSG:4326')
|
||||
projection: getProjection('EPSG:4326'),
|
||||
});
|
||||
expect(source).to.be.a(Source);
|
||||
});
|
||||
});
|
||||
|
||||
describe('config option `attributions`', function() {
|
||||
it('accepts undefined', function() {
|
||||
describe('config option `attributions`', function () {
|
||||
it('accepts undefined', function () {
|
||||
const source = new Source({});
|
||||
const attributions = source.getAttributions();
|
||||
expect(attributions).to.be(null);
|
||||
});
|
||||
|
||||
it('accepts a single string', function() {
|
||||
it('accepts a single string', function () {
|
||||
const source = new Source({
|
||||
attributions: 'Humpty'
|
||||
attributions: 'Humpty',
|
||||
});
|
||||
const attributions = source.getAttributions();
|
||||
expect(attributions).to.not.be(null);
|
||||
@@ -30,9 +28,9 @@ describe('ol.source.Source', function() {
|
||||
expect(attributions()).to.eql(['Humpty']);
|
||||
});
|
||||
|
||||
it('accepts an array of strings', function() {
|
||||
it('accepts an array of strings', function () {
|
||||
const source = new Source({
|
||||
attributions: ['Humpty', 'Dumpty']
|
||||
attributions: ['Humpty', 'Dumpty'],
|
||||
});
|
||||
const attributions = source.getAttributions();
|
||||
expect(attributions).to.not.be(null);
|
||||
@@ -40,11 +38,11 @@ describe('ol.source.Source', function() {
|
||||
expect(attributions()).to.eql(['Humpty', 'Dumpty']);
|
||||
});
|
||||
|
||||
it('accepts a function that returns a string', function() {
|
||||
it('accepts a function that returns a string', function () {
|
||||
const source = new Source({
|
||||
attributions: function() {
|
||||
attributions: function () {
|
||||
return 'Humpty';
|
||||
}
|
||||
},
|
||||
});
|
||||
const attributions = source.getAttributions();
|
||||
expect(attributions).to.not.be(null);
|
||||
@@ -52,11 +50,11 @@ describe('ol.source.Source', function() {
|
||||
expect(attributions()).to.be('Humpty');
|
||||
});
|
||||
|
||||
it('accepts a function that returns an array of strings', function() {
|
||||
it('accepts a function that returns an array of strings', function () {
|
||||
const source = new Source({
|
||||
attributions: function() {
|
||||
attributions: function () {
|
||||
return ['Humpty', 'Dumpty'];
|
||||
}
|
||||
},
|
||||
});
|
||||
const attributions = source.getAttributions();
|
||||
expect(attributions).to.not.be(null);
|
||||
@@ -65,10 +63,10 @@ describe('ol.source.Source', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#refresh()', function() {
|
||||
it('dispatches the change event', function() {
|
||||
describe('#refresh()', function () {
|
||||
it('dispatches the change event', function () {
|
||||
const source = new Source({
|
||||
projection: getProjection('EPSG:4326')
|
||||
projection: getProjection('EPSG:4326'),
|
||||
});
|
||||
const changedSpy = sinon.spy();
|
||||
source.on('change', changedSpy);
|
||||
@@ -77,26 +75,26 @@ describe('ol.source.Source', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setAttributions()', function() {
|
||||
describe('#setAttributions()', function () {
|
||||
let source = null;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
source = new Source({
|
||||
attributions: 'before'
|
||||
attributions: 'before',
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
source = null;
|
||||
});
|
||||
|
||||
it('accepts undefined', function() {
|
||||
it('accepts undefined', function () {
|
||||
source.setAttributions();
|
||||
const attributions = source.getAttributions();
|
||||
expect(attributions).to.be(null);
|
||||
});
|
||||
|
||||
it('accepts a single string', function() {
|
||||
it('accepts a single string', function () {
|
||||
source.setAttributions('Humpty');
|
||||
const attributions = source.getAttributions();
|
||||
expect(attributions).to.not.be(null);
|
||||
@@ -104,7 +102,7 @@ describe('ol.source.Source', function() {
|
||||
expect(attributions()).to.eql(['Humpty']);
|
||||
});
|
||||
|
||||
it('accepts an array of strings', function() {
|
||||
it('accepts an array of strings', function () {
|
||||
source.setAttributions(['Humpty', 'Dumpty']);
|
||||
const attributions = source.getAttributions();
|
||||
expect(attributions).to.not.be(null);
|
||||
@@ -112,8 +110,8 @@ describe('ol.source.Source', function() {
|
||||
expect(attributions()).to.eql(['Humpty', 'Dumpty']);
|
||||
});
|
||||
|
||||
it('accepts a function that returns a string', function() {
|
||||
source.setAttributions(function() {
|
||||
it('accepts a function that returns a string', function () {
|
||||
source.setAttributions(function () {
|
||||
return 'Humpty';
|
||||
});
|
||||
const attributions = source.getAttributions();
|
||||
@@ -122,8 +120,8 @@ describe('ol.source.Source', function() {
|
||||
expect(attributions()).to.eql('Humpty');
|
||||
});
|
||||
|
||||
it('accepts a function that returns an array of strings', function() {
|
||||
source.setAttributions(function() {
|
||||
it('accepts a function that returns an array of strings', function () {
|
||||
source.setAttributions(function () {
|
||||
return ['Humpty', 'Dumpty'];
|
||||
});
|
||||
const attributions = source.getAttributions();
|
||||
@@ -132,5 +130,4 @@ describe('ol.source.Source', function() {
|
||||
expect(attributions()).to.eql(['Humpty', 'Dumpty']);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,27 +1,21 @@
|
||||
import Stamen from '../../../../src/ol/source/Stamen.js';
|
||||
|
||||
|
||||
describe('ol.source.Stamen', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('can be constructed with a custom minZoom', function() {
|
||||
describe('ol.source.Stamen', function () {
|
||||
describe('constructor', function () {
|
||||
it('can be constructed with a custom minZoom', function () {
|
||||
const source = new Stamen({
|
||||
layer: 'watercolor',
|
||||
minZoom: 10
|
||||
minZoom: 10,
|
||||
});
|
||||
expect(source.getTileGrid().getMinZoom()).to.be(10);
|
||||
});
|
||||
|
||||
it('can be constructed with a custom maxZoom', function() {
|
||||
it('can be constructed with a custom maxZoom', function () {
|
||||
const source = new Stamen({
|
||||
layer: 'watercolor',
|
||||
maxZoom: 8
|
||||
maxZoom: 8,
|
||||
});
|
||||
expect(source.getTileGrid().getMaxZoom()).to.be(8);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import Tile from '../../../../src/ol/Tile.js';
|
||||
import TileRange from '../../../../src/ol/TileRange.js';
|
||||
import {get as getProjection} from '../../../../src/ol/proj.js';
|
||||
import Projection from '../../../../src/ol/proj/Projection.js';
|
||||
import Source from '../../../../src/ol/source/Source.js';
|
||||
import Tile from '../../../../src/ol/Tile.js';
|
||||
import TileGrid from '../../../../src/ol/tilegrid/TileGrid.js';
|
||||
import TileRange from '../../../../src/ol/TileRange.js';
|
||||
import TileSource from '../../../../src/ol/source/Tile.js';
|
||||
import {getKeyZXY} from '../../../../src/ol/tilecoord.js';
|
||||
import TileGrid from '../../../../src/ol/tilegrid/TileGrid.js';
|
||||
|
||||
import {get as getProjection} from '../../../../src/ol/proj.js';
|
||||
|
||||
/**
|
||||
* Tile source for tests that uses a EPSG:4326 based grid with 4 resolutions and
|
||||
@@ -20,12 +19,12 @@ class MockTile extends TileSource {
|
||||
const tileGrid = new TileGrid({
|
||||
resolutions: [360 / 256, 180 / 256, 90 / 256, 45 / 256],
|
||||
origin: [-180, -180],
|
||||
tileSize: 256
|
||||
tileSize: 256,
|
||||
});
|
||||
|
||||
super({
|
||||
projection: getProjection('EPSG:4326'),
|
||||
tileGrid: tileGrid
|
||||
tileGrid: tileGrid,
|
||||
});
|
||||
|
||||
for (const key in tileStates) {
|
||||
@@ -34,8 +33,7 @@ class MockTile extends TileSource {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MockTile.prototype.getTile = function(z, x, y) {
|
||||
MockTile.prototype.getTile = function (z, x, y) {
|
||||
const key = getKeyZXY(z, x, y);
|
||||
if (this.tileCache.containsKey(key)) {
|
||||
return /** @type {!ol.Tile} */ (this.tileCache.get(key));
|
||||
@@ -46,38 +44,47 @@ MockTile.prototype.getTile = function(z, x, y) {
|
||||
}
|
||||
};
|
||||
|
||||
describe('ol.source.Tile', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('returns a tile source', function() {
|
||||
describe('ol.source.Tile', function () {
|
||||
describe('constructor', function () {
|
||||
it('returns a tile source', function () {
|
||||
const source = new TileSource({
|
||||
projection: getProjection('EPSG:4326')
|
||||
projection: getProjection('EPSG:4326'),
|
||||
});
|
||||
expect(source).to.be.a(Source);
|
||||
expect(source).to.be.a(TileSource);
|
||||
});
|
||||
it('sets a screen dependent cache size', function() {
|
||||
it('sets a screen dependent cache size', function () {
|
||||
const source = new TileSource({});
|
||||
expect(source.tileCache.highWaterMark).to.be(4 * Math.ceil(screen.availWidth / 256) * Math.ceil(screen.availHeight / 256));
|
||||
expect(source.tileCache.highWaterMark).to.be(
|
||||
4 *
|
||||
Math.ceil(screen.availWidth / 256) *
|
||||
Math.ceil(screen.availHeight / 256)
|
||||
);
|
||||
});
|
||||
it('ignores a cache size that is too small', function() {
|
||||
it('ignores a cache size that is too small', function () {
|
||||
const source = new TileSource({
|
||||
cacheSize: 1
|
||||
cacheSize: 1,
|
||||
});
|
||||
expect(source.tileCache.highWaterMark).to.be(4 * Math.ceil(screen.availWidth / 256) * Math.ceil(screen.availHeight / 256));
|
||||
expect(source.tileCache.highWaterMark).to.be(
|
||||
4 *
|
||||
Math.ceil(screen.availWidth / 256) *
|
||||
Math.ceil(screen.availHeight / 256)
|
||||
);
|
||||
});
|
||||
it('sets a custom cache size', function() {
|
||||
it('sets a custom cache size', function () {
|
||||
const projection = getProjection('EPSG:4326');
|
||||
const source = new TileSource({
|
||||
projection: projection,
|
||||
cacheSize: 442
|
||||
cacheSize: 442,
|
||||
});
|
||||
expect(source.getTileCacheForProjection(projection).highWaterMark).to.be(442);
|
||||
expect(source.getTileCacheForProjection(projection).highWaterMark).to.be(
|
||||
442
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setKey()', function() {
|
||||
it('sets the source key', function() {
|
||||
describe('#setKey()', function () {
|
||||
it('sets the source key', function () {
|
||||
const source = new TileSource({});
|
||||
expect(source.getKey()).to.equal('');
|
||||
|
||||
@@ -87,26 +94,26 @@ describe('ol.source.Tile', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setKey()', function() {
|
||||
it('dispatches a change event', function(done) {
|
||||
describe('#setKey()', function () {
|
||||
it('dispatches a change event', function (done) {
|
||||
const source = new TileSource({});
|
||||
|
||||
const key = 'foo';
|
||||
source.once('change', function() {
|
||||
source.once('change', function () {
|
||||
done();
|
||||
});
|
||||
source.setKey(key);
|
||||
});
|
||||
|
||||
it('does not dispatch change if key does not change', function(done) {
|
||||
it('does not dispatch change if key does not change', function (done) {
|
||||
const source = new TileSource({});
|
||||
|
||||
const key = 'foo';
|
||||
source.once('change', function() {
|
||||
source.once('change', function() {
|
||||
source.once('change', function () {
|
||||
source.once('change', function () {
|
||||
done(new Error('Unexpected change event after source.setKey()'));
|
||||
});
|
||||
setTimeout(function() {
|
||||
setTimeout(function () {
|
||||
done();
|
||||
}, 10);
|
||||
source.setKey(key); // this should not result in a change event
|
||||
@@ -114,17 +121,15 @@ describe('ol.source.Tile', function() {
|
||||
|
||||
source.setKey(key); // this should result in a change event
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#forEachLoadedTile()', function() {
|
||||
|
||||
describe('#forEachLoadedTile()', function () {
|
||||
let callback;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
callback = sinon.spy();
|
||||
});
|
||||
|
||||
it('does not call the callback if no tiles are loaded', function() {
|
||||
it('does not call the callback if no tiles are loaded', function () {
|
||||
const source = new MockTile({});
|
||||
const grid = source.getTileGrid();
|
||||
const extent = [-180, -180, 180, 180];
|
||||
@@ -135,7 +140,7 @@ describe('ol.source.Tile', function() {
|
||||
expect(callback.callCount).to.be(0);
|
||||
});
|
||||
|
||||
it('does not call getTile() if no tiles are loaded', function() {
|
||||
it('does not call getTile() if no tiles are loaded', function () {
|
||||
const source = new MockTile({});
|
||||
sinon.spy(source, 'getTile');
|
||||
const grid = source.getTileGrid();
|
||||
@@ -148,13 +153,12 @@ describe('ol.source.Tile', function() {
|
||||
source.getTile.restore();
|
||||
});
|
||||
|
||||
|
||||
it('calls callback for each loaded tile', function() {
|
||||
it('calls callback for each loaded tile', function () {
|
||||
const source = new MockTile({
|
||||
'1/0/0': 2, // LOADED
|
||||
'1/0/1': 2, // LOADED
|
||||
'1/1/0': 1, // LOADING,
|
||||
'1/1/1': 2 // LOADED
|
||||
'1/1/1': 2, // LOADED
|
||||
});
|
||||
|
||||
const zoom = 1;
|
||||
@@ -164,74 +168,81 @@ describe('ol.source.Tile', function() {
|
||||
expect(callback.callCount).to.be(3);
|
||||
});
|
||||
|
||||
it('returns true if range is fully loaded', function() {
|
||||
it('returns true if range is fully loaded', function () {
|
||||
// a source with no loaded tiles
|
||||
const source = new MockTile({
|
||||
'1/0/0': 2, // LOADED,
|
||||
'1/0/1': 2, // LOADED,
|
||||
'1/1/0': 2, // LOADED,
|
||||
'1/1/1': 2 // LOADED
|
||||
'1/1/1': 2, // LOADED
|
||||
});
|
||||
|
||||
const zoom = 1;
|
||||
const range = new TileRange(0, 1, 0, 1);
|
||||
|
||||
const covered = source.forEachLoadedTile(
|
||||
source.getProjection(), zoom, range,
|
||||
function() {
|
||||
source.getProjection(),
|
||||
zoom,
|
||||
range,
|
||||
function () {
|
||||
return true;
|
||||
});
|
||||
}
|
||||
);
|
||||
expect(covered).to.be(true);
|
||||
});
|
||||
|
||||
it('returns false if range is not fully loaded', function() {
|
||||
it('returns false if range is not fully loaded', function () {
|
||||
// a source with no loaded tiles
|
||||
const source = new MockTile({
|
||||
'1/0/0': 2, // LOADED,
|
||||
'1/0/1': 2, // LOADED,
|
||||
'1/1/0': 1, // LOADING,
|
||||
'1/1/1': 2 // LOADED
|
||||
'1/1/1': 2, // LOADED
|
||||
});
|
||||
|
||||
const zoom = 1;
|
||||
const range = new TileRange(0, 1, 0, 1);
|
||||
|
||||
const covered = source.forEachLoadedTile(
|
||||
source.getProjection(), zoom,
|
||||
range, function() {
|
||||
source.getProjection(),
|
||||
zoom,
|
||||
range,
|
||||
function () {
|
||||
return true;
|
||||
});
|
||||
}
|
||||
);
|
||||
expect(covered).to.be(false);
|
||||
});
|
||||
|
||||
it('allows callback to override loaded check', function() {
|
||||
it('allows callback to override loaded check', function () {
|
||||
// a source with no loaded tiles
|
||||
const source = new MockTile({
|
||||
'1/0/0': 2, // LOADED,
|
||||
'1/0/1': 2, // LOADED,
|
||||
'1/1/0': 2, // LOADED,
|
||||
'1/1/1': 2 // LOADED
|
||||
'1/1/1': 2, // LOADED
|
||||
});
|
||||
|
||||
const zoom = 1;
|
||||
const range = new TileRange(0, 1, 0, 1);
|
||||
|
||||
const covered = source.forEachLoadedTile(
|
||||
source.getProjection(), zoom, range,
|
||||
function() {
|
||||
source.getProjection(),
|
||||
zoom,
|
||||
range,
|
||||
function () {
|
||||
return false;
|
||||
});
|
||||
}
|
||||
);
|
||||
expect(covered).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getTileCoordForTileUrlFunction()', function() {
|
||||
|
||||
it('returns the expected tile coordinate - {wrapX: true}', function() {
|
||||
describe('#getTileCoordForTileUrlFunction()', function () {
|
||||
it('returns the expected tile coordinate - {wrapX: true}', function () {
|
||||
const tileSource = new TileSource({
|
||||
projection: 'EPSG:3857',
|
||||
wrapX: true
|
||||
wrapX: true,
|
||||
});
|
||||
|
||||
let tileCoord = tileSource.getTileCoordForTileUrlFunction([6, -31, 22]);
|
||||
@@ -244,10 +255,10 @@ describe('ol.source.Tile', function() {
|
||||
expect(tileCoord).to.eql([6, 33, 22]);
|
||||
});
|
||||
|
||||
it('returns the expected tile coordinate - {wrapX: false}', function() {
|
||||
it('returns the expected tile coordinate - {wrapX: false}', function () {
|
||||
const tileSource = new TileSource({
|
||||
projection: 'EPSG:3857',
|
||||
wrapX: false
|
||||
wrapX: false,
|
||||
});
|
||||
|
||||
let tileCoord = tileSource.getTileCoordForTileUrlFunction([6, -31, 22]);
|
||||
@@ -260,14 +271,14 @@ describe('ol.source.Tile', function() {
|
||||
expect(tileCoord).to.eql(null);
|
||||
});
|
||||
|
||||
it('works with wrapX and custom projection without extent', function() {
|
||||
it('works with wrapX and custom projection without extent', function () {
|
||||
const tileSource = new TileSource({
|
||||
projection: new Projection({
|
||||
code: 'foo',
|
||||
global: true,
|
||||
units: 'm'
|
||||
units: 'm',
|
||||
}),
|
||||
wrapX: true
|
||||
wrapX: true,
|
||||
});
|
||||
|
||||
const tileCoord = tileSource.getTileCoordForTileUrlFunction([6, -31, 22]);
|
||||
@@ -275,11 +286,11 @@ describe('ol.source.Tile', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#refresh()', function() {
|
||||
it('checks clearing of internal state', function() {
|
||||
describe('#refresh()', function () {
|
||||
it('checks clearing of internal state', function () {
|
||||
// create a source with one loaded tile
|
||||
const source = new MockTile({
|
||||
'1/0/0': 2 // LOADED
|
||||
'1/0/0': 2, // LOADED
|
||||
});
|
||||
// check the loaded tile is there
|
||||
const tile = source.getTile(1, 0, 0);
|
||||
@@ -292,25 +303,22 @@ describe('ol.source.Tile', function() {
|
||||
expect(source.tileCache.getCount()).to.eql(0);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('MockTile', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates a tile source', function() {
|
||||
describe('MockTile', function () {
|
||||
describe('constructor', function () {
|
||||
it('creates a tile source', function () {
|
||||
const source = new MockTile({});
|
||||
expect(source).to.be.a(TileSource);
|
||||
expect(source).to.be.a(MockTile);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getTile()', function() {
|
||||
it('returns a tile with state based on constructor arg', function() {
|
||||
describe('#getTile()', function () {
|
||||
it('returns a tile with state based on constructor arg', function () {
|
||||
const source = new MockTile({
|
||||
'0/0/0': 2, // LOADED,
|
||||
'1/0/0': 2 // LOADED
|
||||
'1/0/0': 2, // LOADED
|
||||
});
|
||||
let tile;
|
||||
|
||||
@@ -328,8 +336,6 @@ describe('MockTile', function() {
|
||||
tile = source.getTile(1, 0, 0);
|
||||
expect(tile).to.be.a(Tile);
|
||||
expect(tile.state).to.be(2); // LOADED
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -2,20 +2,17 @@ import ImageTile from '../../../../src/ol/ImageTile.js';
|
||||
import TileArcGISRest from '../../../../src/ol/source/TileArcGISRest.js';
|
||||
import {get as getProjection} from '../../../../src/ol/proj.js';
|
||||
|
||||
|
||||
describe('ol.source.TileArcGISRest', function() {
|
||||
|
||||
describe('ol.source.TileArcGISRest', function () {
|
||||
let options;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
options = {
|
||||
params: {},
|
||||
url: 'http://example.com/MapServer'
|
||||
url: 'http://example.com/MapServer',
|
||||
};
|
||||
});
|
||||
|
||||
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 TileArcGISRest(options);
|
||||
const tile = source.getTile(3, 2, 6, 1, getProjection('EPSG:3857'));
|
||||
expect(tile).to.be.an(ImageTile);
|
||||
@@ -34,10 +31,9 @@ describe('ol.source.TileArcGISRest', function() {
|
||||
expect(queryData.get('IMAGESR')).to.be('3857');
|
||||
expect(queryData.get('BBOXSR')).to.be('3857');
|
||||
expect(queryData.get('TRANSPARENT')).to.be('true');
|
||||
|
||||
});
|
||||
|
||||
it('returns a non floating point DPI value', function() {
|
||||
it('returns a non floating point DPI value', function () {
|
||||
const source = new TileArcGISRest(options);
|
||||
const tile = source.getTile(3, 2, 6, 1.12, getProjection('EPSG:3857'));
|
||||
const uri = new URL(tile.src_);
|
||||
@@ -45,7 +41,7 @@ describe('ol.source.TileArcGISRest', function() {
|
||||
expect(queryData.get('DPI')).to.be('101');
|
||||
});
|
||||
|
||||
it('takes DPI from params if specified', function() {
|
||||
it('takes DPI from params if specified', function () {
|
||||
options.params.DPI = 96;
|
||||
const source = new TileArcGISRest(options);
|
||||
const tile = source.getTile(3, 2, 6, 1.12, getProjection('EPSG:3857'));
|
||||
@@ -55,9 +51,11 @@ describe('ol.source.TileArcGISRest', function() {
|
||||
delete options.params.DPI;
|
||||
});
|
||||
|
||||
it('returns a tile with the expected URL with url list', function() {
|
||||
|
||||
options.urls = ['http://test1.com/MapServer', 'http://test2.com/MapServer'];
|
||||
it('returns a tile with the expected URL with url list', function () {
|
||||
options.urls = [
|
||||
'http://test1.com/MapServer',
|
||||
'http://test2.com/MapServer',
|
||||
];
|
||||
const source = new TileArcGISRest(options);
|
||||
|
||||
const tile = source.getTile(3, 2, 6, 1, getProjection('EPSG:3857'));
|
||||
@@ -77,10 +75,9 @@ describe('ol.source.TileArcGISRest', function() {
|
||||
expect(queryData.get('IMAGESR')).to.be('3857');
|
||||
expect(queryData.get('BBOXSR')).to.be('3857');
|
||||
expect(queryData.get('TRANSPARENT')).to.be('true');
|
||||
|
||||
});
|
||||
|
||||
it('returns a tile with the expected URL for ImageServer', function() {
|
||||
it('returns a tile with the expected URL for ImageServer', function () {
|
||||
options.url = 'http://example.com/ImageServer';
|
||||
const source = new TileArcGISRest(options);
|
||||
const tile = source.getTile(3, 2, 6, 1, getProjection('EPSG:3857'));
|
||||
@@ -102,7 +99,7 @@ describe('ol.source.TileArcGISRest', function() {
|
||||
expect(queryData.get('TRANSPARENT')).to.be('true');
|
||||
});
|
||||
|
||||
it('allows various parameters to be overridden', function() {
|
||||
it('allows various parameters to be overridden', function () {
|
||||
options.params.FORMAT = 'png';
|
||||
options.params.TRANSPARENT = false;
|
||||
const source = new TileArcGISRest(options);
|
||||
@@ -113,7 +110,7 @@ describe('ol.source.TileArcGISRest', function() {
|
||||
expect(queryData.get('TRANSPARENT')).to.be('false');
|
||||
});
|
||||
|
||||
it('allows adding rest option', function() {
|
||||
it('allows adding rest option', function () {
|
||||
options.params.LAYERS = 'show:1,3,4';
|
||||
const source = new TileArcGISRest(options);
|
||||
const tile = source.getTile(3, 2, 2, 1, getProjection('EPSG:4326'));
|
||||
@@ -123,9 +120,8 @@ describe('ol.source.TileArcGISRest', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#updateParams', function() {
|
||||
|
||||
it('add a new param', function() {
|
||||
describe('#updateParams', function () {
|
||||
it('add a new param', function () {
|
||||
const source = new TileArcGISRest(options);
|
||||
source.updateParams({'TEST': 'value'});
|
||||
|
||||
@@ -135,7 +131,7 @@ describe('ol.source.TileArcGISRest', function() {
|
||||
expect(queryData.get('TEST')).to.be('value');
|
||||
});
|
||||
|
||||
it('updates an existing param', function() {
|
||||
it('updates an existing param', function () {
|
||||
options.params.TEST = 'value';
|
||||
|
||||
const source = new TileArcGISRest(options);
|
||||
@@ -146,12 +142,10 @@ describe('ol.source.TileArcGISRest', function() {
|
||||
const queryData = uri.searchParams;
|
||||
expect(queryData.get('TEST')).to.be('newValue');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getParams', function() {
|
||||
|
||||
it('verify getting a param', function() {
|
||||
describe('#getParams', function () {
|
||||
it('verify getting a param', function () {
|
||||
options.params.TEST = 'value';
|
||||
const source = new TileArcGISRest(options);
|
||||
|
||||
@@ -160,7 +154,7 @@ describe('ol.source.TileArcGISRest', function() {
|
||||
expect(setParams).to.eql({TEST: 'value'});
|
||||
});
|
||||
|
||||
it('verify on adding a param', function() {
|
||||
it('verify on adding a param', function () {
|
||||
options.params.TEST = 'value';
|
||||
|
||||
const source = new TileArcGISRest(options);
|
||||
@@ -171,7 +165,7 @@ describe('ol.source.TileArcGISRest', function() {
|
||||
expect(setParams).to.eql({TEST: 'value', TEST2: 'newValue'});
|
||||
});
|
||||
|
||||
it('verify on update a param', function() {
|
||||
it('verify on update a param', function () {
|
||||
options.params.TEST = 'value';
|
||||
|
||||
const source = new TileArcGISRest(options);
|
||||
@@ -181,52 +175,65 @@ describe('ol.source.TileArcGISRest', function() {
|
||||
|
||||
expect(setParams).to.eql({TEST: 'newValue'});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getUrls', function() {
|
||||
|
||||
it('verify getting array of urls', function() {
|
||||
options.urls = ['http://test.com/MapServer', 'http://test2.com/MapServer'];
|
||||
describe('#getUrls', function () {
|
||||
it('verify getting array of urls', function () {
|
||||
options.urls = [
|
||||
'http://test.com/MapServer',
|
||||
'http://test2.com/MapServer',
|
||||
];
|
||||
|
||||
const source = new TileArcGISRest(options);
|
||||
|
||||
const urls = source.getUrls();
|
||||
|
||||
expect(urls).to.eql(['http://test.com/MapServer', 'http://test2.com/MapServer']);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
describe('#setUrls', function() {
|
||||
|
||||
it('verify setting urls when not set yet', function() {
|
||||
|
||||
const source = new TileArcGISRest(options);
|
||||
source.setUrls(['http://test.com/MapServer', 'http://test2.com/MapServer']);
|
||||
|
||||
const urls = source.getUrls();
|
||||
|
||||
expect(urls).to.eql(['http://test.com/MapServer', 'http://test2.com/MapServer']);
|
||||
});
|
||||
|
||||
it('verify setting urls with existing list', function() {
|
||||
options.urls = ['http://test.com/MapServer', 'http://test2.com/MapServer'];
|
||||
|
||||
const source = new TileArcGISRest(options);
|
||||
source.setUrls(['http://test3.com/MapServer', 'http://test4.com/MapServer']);
|
||||
|
||||
const urls = source.getUrls();
|
||||
|
||||
expect(urls).to.eql(['http://test3.com/MapServer', 'http://test4.com/MapServer']);
|
||||
expect(urls).to.eql([
|
||||
'http://test.com/MapServer',
|
||||
'http://test2.com/MapServer',
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setUrl', function() {
|
||||
describe('#setUrls', function () {
|
||||
it('verify setting urls when not set yet', function () {
|
||||
const source = new TileArcGISRest(options);
|
||||
source.setUrls([
|
||||
'http://test.com/MapServer',
|
||||
'http://test2.com/MapServer',
|
||||
]);
|
||||
|
||||
it('verify setting url with no urls', function() {
|
||||
const urls = source.getUrls();
|
||||
|
||||
expect(urls).to.eql([
|
||||
'http://test.com/MapServer',
|
||||
'http://test2.com/MapServer',
|
||||
]);
|
||||
});
|
||||
|
||||
it('verify setting urls with existing list', function () {
|
||||
options.urls = [
|
||||
'http://test.com/MapServer',
|
||||
'http://test2.com/MapServer',
|
||||
];
|
||||
|
||||
const source = new TileArcGISRest(options);
|
||||
source.setUrls([
|
||||
'http://test3.com/MapServer',
|
||||
'http://test4.com/MapServer',
|
||||
]);
|
||||
|
||||
const urls = source.getUrls();
|
||||
|
||||
expect(urls).to.eql([
|
||||
'http://test3.com/MapServer',
|
||||
'http://test4.com/MapServer',
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setUrl', function () {
|
||||
it('verify setting url with no urls', function () {
|
||||
const source = new TileArcGISRest(options);
|
||||
source.setUrl('http://test.com/MapServer');
|
||||
|
||||
@@ -235,8 +242,11 @@ describe('ol.source.TileArcGISRest', function() {
|
||||
expect(urls).to.eql(['http://test.com/MapServer']);
|
||||
});
|
||||
|
||||
it('verify setting url with list of urls', function() {
|
||||
options.urls = ['http://test.com/MapServer', 'http://test2.com/MapServer'];
|
||||
it('verify setting url with list of urls', function () {
|
||||
options.urls = [
|
||||
'http://test.com/MapServer',
|
||||
'http://test2.com/MapServer',
|
||||
];
|
||||
|
||||
const source = new TileArcGISRest(options);
|
||||
source.setUrl('http://test3.com/MapServer');
|
||||
@@ -245,11 +255,12 @@ describe('ol.source.TileArcGISRest', function() {
|
||||
|
||||
expect(urls).to.eql(['http://test3.com/MapServer']);
|
||||
|
||||
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(urls[0])).to.be(0);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,52 +1,62 @@
|
||||
import ImageTile from '../../../../src/ol/ImageTile.js';
|
||||
import TileState from '../../../../src/ol/TileState.js';
|
||||
import {createFromTemplate} from '../../../../src/ol/tileurlfunction.js';
|
||||
import {listen} from '../../../../src/ol/events.js';
|
||||
import {addCommon, clearAllProjections, get as getProjection} from '../../../../src/ol/proj.js';
|
||||
import {register} from '../../../../src/ol/proj/proj4.js';
|
||||
import {WORLD_EXTENT} from '../../../../src/ol/proj/epsg3857.js';
|
||||
import Projection from '../../../../src/ol/proj/Projection.js';
|
||||
import ReprojTile from '../../../../src/ol/reproj/Tile.js';
|
||||
import TileImage from '../../../../src/ol/source/TileImage.js';
|
||||
import TileState from '../../../../src/ol/TileState.js';
|
||||
import {WORLD_EXTENT} from '../../../../src/ol/proj/epsg3857.js';
|
||||
import {
|
||||
addCommon,
|
||||
clearAllProjections,
|
||||
get as getProjection,
|
||||
} from '../../../../src/ol/proj.js';
|
||||
import {createForProjection, createXYZ} from '../../../../src/ol/tilegrid.js';
|
||||
import {createFromTemplate} from '../../../../src/ol/tileurlfunction.js';
|
||||
import {getKeyZXY} from '../../../../src/ol/tilecoord.js';
|
||||
import {createXYZ, createForProjection} from '../../../../src/ol/tilegrid.js';
|
||||
import {listen} from '../../../../src/ol/events.js';
|
||||
import {register} from '../../../../src/ol/proj/proj4.js';
|
||||
|
||||
|
||||
describe('ol.source.TileImage', function() {
|
||||
describe('ol.source.TileImage', function () {
|
||||
function createSource(opt_proj, opt_tileGrid, opt_cacheSize) {
|
||||
const proj = opt_proj || 'EPSG:3857';
|
||||
return new TileImage({
|
||||
cacheSize: opt_cacheSize,
|
||||
projection: proj,
|
||||
tileGrid: opt_tileGrid ||
|
||||
createForProjection(proj, undefined, [2, 2]),
|
||||
tileUrlFunction: createFromTemplate('data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=')
|
||||
tileGrid: opt_tileGrid || createForProjection(proj, undefined, [2, 2]),
|
||||
tileUrlFunction: createFromTemplate(
|
||||
'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs='
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
describe('#getTileCacheForProjection', function() {
|
||||
it('uses the cacheSize for reprojected tile caches', function() {
|
||||
describe('#getTileCacheForProjection', function () {
|
||||
it('uses the cacheSize for reprojected tile caches', function () {
|
||||
const source = createSource(undefined, undefined, 442);
|
||||
const tileCache = source.getTileCacheForProjection(getProjection('EPSG:4326'));
|
||||
const tileCache = source.getTileCacheForProjection(
|
||||
getProjection('EPSG:4326')
|
||||
);
|
||||
expect(tileCache.highWaterMark).to.be(442);
|
||||
expect(tileCache).to.not.equal(source.getTileCacheForProjection(source.getProjection()));
|
||||
expect(tileCache).to.not.equal(
|
||||
source.getTileCacheForProjection(source.getProjection())
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setTileGridForProjection', function() {
|
||||
it('uses the tilegrid for given projection', function() {
|
||||
describe('#setTileGridForProjection', function () {
|
||||
it('uses the tilegrid for given projection', function () {
|
||||
const source = createSource();
|
||||
const tileGrid = createForProjection('EPSG:4326', 3, [10, 20]);
|
||||
source.setTileGridForProjection('EPSG:4326', tileGrid);
|
||||
const retrieved = source.getTileGridForProjection(getProjection('EPSG:4326'));
|
||||
const retrieved = source.getTileGridForProjection(
|
||||
getProjection('EPSG:4326')
|
||||
);
|
||||
expect(retrieved).to.be(tileGrid);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getTileInternal', function() {
|
||||
describe('#getTileInternal', function () {
|
||||
let source, tile;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
source = createSource();
|
||||
expect(source.getKey()).to.be('');
|
||||
source.getTileInternal(0, 0, 0, 1, getProjection('EPSG:3857'));
|
||||
@@ -54,69 +64,102 @@ describe('ol.source.TileImage', function() {
|
||||
tile = source.tileCache.get(getKeyZXY(0, 0, 0));
|
||||
});
|
||||
|
||||
it('gets the tile from the cache', function() {
|
||||
const returnedTile = source.getTileInternal(0, 0, 0, 1, getProjection('EPSG:3857'));
|
||||
it('gets the tile from the cache', function () {
|
||||
const returnedTile = source.getTileInternal(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
getProjection('EPSG:3857')
|
||||
);
|
||||
expect(returnedTile).to.be(tile);
|
||||
});
|
||||
|
||||
describe('change a dynamic param', function() {
|
||||
|
||||
describe('tile is not loaded', function() {
|
||||
it('returns a tile with no interim tile', function() {
|
||||
source.getKey = function() {
|
||||
describe('change a dynamic param', function () {
|
||||
describe('tile is not loaded', function () {
|
||||
it('returns a tile with no interim tile', function () {
|
||||
source.getKey = function () {
|
||||
return 'key0';
|
||||
};
|
||||
const returnedTile = source.getTileInternal(0, 0, 0, 1, getProjection('EPSG:3857'));
|
||||
const returnedTile = source.getTileInternal(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
getProjection('EPSG:3857')
|
||||
);
|
||||
expect(returnedTile).not.to.be(tile);
|
||||
expect(returnedTile.key).to.be('key0');
|
||||
expect(returnedTile.interimTile).to.be(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('tile is loaded', function() {
|
||||
it('returns a tile with interim tile', function() {
|
||||
source.getKey = function() {
|
||||
describe('tile is loaded', function () {
|
||||
it('returns a tile with interim tile', function () {
|
||||
source.getKey = function () {
|
||||
return 'key0';
|
||||
};
|
||||
tile.state = 2; // LOADED
|
||||
const returnedTile = source.getTileInternal(0, 0, 0, 1, getProjection('EPSG:3857'));
|
||||
const returnedTile = source.getTileInternal(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
getProjection('EPSG:3857')
|
||||
);
|
||||
expect(returnedTile).not.to.be(tile);
|
||||
expect(returnedTile.key).to.be('key0');
|
||||
expect(returnedTile.interimTile).to.be(tile);
|
||||
});
|
||||
});
|
||||
|
||||
describe('tile is not loaded but interim tile is', function() {
|
||||
it('returns a tile with interim tile', function() {
|
||||
describe('tile is not loaded but interim tile is', function () {
|
||||
it('returns a tile with interim tile', function () {
|
||||
let dynamicParamsKey, returnedTile;
|
||||
source.getKey = function() {
|
||||
source.getKey = function () {
|
||||
return dynamicParamsKey;
|
||||
};
|
||||
dynamicParamsKey = 'key0';
|
||||
tile.state = 2; // LOADED
|
||||
returnedTile = source.getTileInternal(0, 0, 0, 1, getProjection('EPSG:3857'));
|
||||
returnedTile = source.getTileInternal(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
getProjection('EPSG:3857')
|
||||
);
|
||||
dynamicParamsKey = 'key1';
|
||||
returnedTile = source.getTileInternal(0, 0, 0, 1, getProjection('EPSG:3857'));
|
||||
returnedTile = source.getTileInternal(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
getProjection('EPSG:3857')
|
||||
);
|
||||
expect(returnedTile).not.to.be(tile);
|
||||
expect(returnedTile.key).to.be('key1');
|
||||
expect(returnedTile.interimTile).to.be(tile);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getTile', function() {
|
||||
it('does not do reprojection for identity', function() {
|
||||
describe('#getTile', function () {
|
||||
it('does not do reprojection for identity', function () {
|
||||
const source3857 = createSource('EPSG:3857');
|
||||
const tile3857 = source3857.getTile(0, 0, 0, 1, getProjection('EPSG:3857'));
|
||||
const tile3857 = source3857.getTile(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
getProjection('EPSG:3857')
|
||||
);
|
||||
expect(tile3857).to.be.a(ImageTile);
|
||||
expect(tile3857).not.to.be.a(ReprojTile);
|
||||
|
||||
const projXXX = new Projection({
|
||||
code: 'XXX',
|
||||
units: 'degrees'
|
||||
units: 'degrees',
|
||||
});
|
||||
const sourceXXX = createSource(projXXX);
|
||||
const tileXXX = sourceXXX.getTile(0, 0, 0, 1, projXXX);
|
||||
@@ -124,46 +167,53 @@ describe('ol.source.TileImage', function() {
|
||||
expect(tileXXX).not.to.be.a(ReprojTile);
|
||||
});
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
proj4.defs('4326_noextentnounits', '+proj=longlat +datum=WGS84 +no_defs');
|
||||
register(proj4);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
delete proj4.defs['4326_noextentnounits'];
|
||||
clearAllProjections();
|
||||
addCommon();
|
||||
});
|
||||
|
||||
it('can handle source projection without extent and units', function(done) {
|
||||
const source = createSource('4326_noextentnounits', createXYZ({
|
||||
extent: [-180, -90, 180, 90],
|
||||
tileSize: [2, 2]
|
||||
}));
|
||||
it('can handle source projection without extent and units', function (done) {
|
||||
const source = createSource(
|
||||
'4326_noextentnounits',
|
||||
createXYZ({
|
||||
extent: [-180, -90, 180, 90],
|
||||
tileSize: [2, 2],
|
||||
})
|
||||
);
|
||||
const tile = source.getTile(0, 0, 0, 1, getProjection('EPSG:3857'));
|
||||
expect(tile).to.be.a(ReprojTile);
|
||||
|
||||
listen(tile, 'change', function() {
|
||||
if (tile.getState() == 2) { // LOADED
|
||||
listen(tile, 'change', function () {
|
||||
if (tile.getState() == 2) {
|
||||
// LOADED
|
||||
done();
|
||||
}
|
||||
});
|
||||
tile.load();
|
||||
});
|
||||
|
||||
it('can handle target projection without extent and units', function(done) {
|
||||
it('can handle target projection without extent and units', function (done) {
|
||||
const proj = getProjection('4326_noextentnounits');
|
||||
const source = createSource();
|
||||
source.setTileGridForProjection(proj,
|
||||
source.setTileGridForProjection(
|
||||
proj,
|
||||
createXYZ({
|
||||
extent: WORLD_EXTENT,
|
||||
tileSize: [2, 2]
|
||||
}));
|
||||
tileSize: [2, 2],
|
||||
})
|
||||
);
|
||||
const tile = source.getTile(0, 0, 0, 1, proj);
|
||||
expect(tile).to.be.a(ReprojTile);
|
||||
|
||||
listen(tile, 'change', function() {
|
||||
if (tile.getState() == 2) { // LOADED
|
||||
listen(tile, 'change', function () {
|
||||
if (tile.getState() == 2) {
|
||||
// LOADED
|
||||
done();
|
||||
}
|
||||
});
|
||||
@@ -171,18 +221,17 @@ describe('ol.source.TileImage', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('tile load events', function() {
|
||||
|
||||
describe('tile load events', function () {
|
||||
let source;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
source = new TileImage({
|
||||
url: '{z}/{x}/{y}'
|
||||
url: '{z}/{x}/{y}',
|
||||
});
|
||||
});
|
||||
|
||||
it('dispatches tileloadstart and tileloadend events', function() {
|
||||
source.setTileLoadFunction(function(tile) {
|
||||
it('dispatches tileloadstart and tileloadend events', function () {
|
||||
source.setTileLoadFunction(function (tile) {
|
||||
tile.setState(TileState.LOADED);
|
||||
});
|
||||
const startSpy = sinon.spy();
|
||||
@@ -195,22 +244,23 @@ describe('ol.source.TileImage', function() {
|
||||
expect(endSpy.callCount).to.be(1);
|
||||
});
|
||||
|
||||
it('works for loading-error-loading-loaded sequences', function(done) {
|
||||
source.setTileLoadFunction(function(tile) {
|
||||
it('works for loading-error-loading-loaded sequences', function (done) {
|
||||
source.setTileLoadFunction(function (tile) {
|
||||
tile.setState(
|
||||
tile.state == TileState.ERROR ? TileState.LOADED : TileState.ERROR);
|
||||
tile.state == TileState.ERROR ? TileState.LOADED : TileState.ERROR
|
||||
);
|
||||
});
|
||||
const startSpy = sinon.spy();
|
||||
source.on('tileloadstart', startSpy);
|
||||
const errorSpy = sinon.spy();
|
||||
source.on('tileloaderror', function(e) {
|
||||
setTimeout(function() {
|
||||
source.on('tileloaderror', function (e) {
|
||||
setTimeout(function () {
|
||||
e.tile.setState(TileState.LOADING);
|
||||
e.tile.setState(TileState.LOADED);
|
||||
}, 0);
|
||||
errorSpy();
|
||||
});
|
||||
source.on('tileloadend', function() {
|
||||
source.on('tileloadend', function () {
|
||||
expect(startSpy.callCount).to.be(2);
|
||||
expect(errorSpy.callCount).to.be(1);
|
||||
done();
|
||||
@@ -219,5 +269,4 @@ describe('ol.source.TileImage', function() {
|
||||
tile.load();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -2,27 +2,23 @@ import Source from '../../../../src/ol/source/Source.js';
|
||||
import TileJSON from '../../../../src/ol/source/TileJSON.js';
|
||||
import {unByKey} from '../../../../src/ol/Observable.js';
|
||||
|
||||
|
||||
describe('ol.source.TileJSON', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('returns a tileJSON source', function() {
|
||||
describe('ol.source.TileJSON', function () {
|
||||
describe('constructor', function () {
|
||||
it('returns a tileJSON source', function () {
|
||||
const source = new TileJSON({
|
||||
url: 'spec/ol/data/tilejson.json'
|
||||
url: 'spec/ol/data/tilejson.json',
|
||||
});
|
||||
expect(source).to.be.a(Source);
|
||||
expect(source).to.be.a(TileJSON);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getTileJSON', function() {
|
||||
|
||||
it('parses the tilejson file', function() {
|
||||
describe('#getTileJSON', function () {
|
||||
it('parses the tilejson file', function () {
|
||||
const source = new TileJSON({
|
||||
url: 'spec/ol/data/tilejson.json'
|
||||
url: 'spec/ol/data/tilejson.json',
|
||||
});
|
||||
source.on('change', function() {
|
||||
source.on('change', function () {
|
||||
if (source.getState() === 'ready') {
|
||||
const tileJSON = source.getTileJSON();
|
||||
expect(tileJSON.name).to.eql('Geography Class');
|
||||
@@ -31,22 +27,15 @@ describe('ol.source.TileJSON', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it ('parses inline TileJSON', function() {
|
||||
it('parses inline TileJSON', function () {
|
||||
const tileJSON = {
|
||||
bounds: [
|
||||
-180,
|
||||
-85.05112877980659,
|
||||
180,
|
||||
85.05112877980659
|
||||
],
|
||||
center: [
|
||||
0,
|
||||
0,
|
||||
4
|
||||
],
|
||||
bounds: [-180, -85.05112877980659, 180, 85.05112877980659],
|
||||
center: [0, 0, 4],
|
||||
created: 1322764050886,
|
||||
description: 'One of the example maps that comes with TileMill - a bright & colorful world map that blends retro and high-tech with its folded paper texture and interactive flag tooltips. ',
|
||||
download: 'https://a.tiles.mapbox.com/v3/mapbox.geography-class.mbtiles',
|
||||
description:
|
||||
'One of the example maps that comes with TileMill - a bright & colorful world map that blends retro and high-tech with its folded paper texture and interactive flag tooltips. ',
|
||||
download:
|
||||
'https://a.tiles.mapbox.com/v3/mapbox.geography-class.mbtiles',
|
||||
embed: 'https://a.tiles.mapbox.com/v3/mapbox.geography-class.html',
|
||||
id: 'mapbox.geography-class',
|
||||
mapbox_logo: true,
|
||||
@@ -60,66 +49,74 @@ describe('ol.source.TileJSON', function() {
|
||||
'https://a.tiles.mapbox.com/v3/mapbox.geography-class/{z}/{x}/{y}.png',
|
||||
'https://b.tiles.mapbox.com/v3/mapbox.geography-class/{z}/{x}/{y}.png',
|
||||
'https://c.tiles.mapbox.com/v3/mapbox.geography-class/{z}/{x}/{y}.png',
|
||||
'https://d.tiles.mapbox.com/v3/mapbox.geography-class/{z}/{x}/{y}.png'
|
||||
'https://d.tiles.mapbox.com/v3/mapbox.geography-class/{z}/{x}/{y}.png',
|
||||
],
|
||||
version: '1.0.0',
|
||||
webpage: 'https://a.tiles.mapbox.com/v3/mapbox.geography-class/page.html'
|
||||
webpage:
|
||||
'https://a.tiles.mapbox.com/v3/mapbox.geography-class/page.html',
|
||||
};
|
||||
const source = new TileJSON({
|
||||
tileJSON: tileJSON
|
||||
tileJSON: tileJSON,
|
||||
});
|
||||
expect(source.getState()).to.be('ready');
|
||||
expect(source.getTileUrlFunction()([0, 0, 0])).to.be('https://a.tiles.mapbox.com/v3/mapbox.geography-class/0/0/0.png');
|
||||
expect(source.getTileUrlFunction()([1, 0, 0])).to.be('https://a.tiles.mapbox.com/v3/mapbox.geography-class/1/0/0.png');
|
||||
expect(source.getTileUrlFunction()([1, 0, 1])).to.be('https://b.tiles.mapbox.com/v3/mapbox.geography-class/1/0/1.png');
|
||||
expect(source.getTileUrlFunction()([1, 1, 0])).to.be('https://c.tiles.mapbox.com/v3/mapbox.geography-class/1/1/0.png');
|
||||
expect(source.getTileUrlFunction()([1, 1, 1])).to.be('https://d.tiles.mapbox.com/v3/mapbox.geography-class/1/1/1.png');
|
||||
expect(source.getTileUrlFunction()([0, 0, 0])).to.be(
|
||||
'https://a.tiles.mapbox.com/v3/mapbox.geography-class/0/0/0.png'
|
||||
);
|
||||
expect(source.getTileUrlFunction()([1, 0, 0])).to.be(
|
||||
'https://a.tiles.mapbox.com/v3/mapbox.geography-class/1/0/0.png'
|
||||
);
|
||||
expect(source.getTileUrlFunction()([1, 0, 1])).to.be(
|
||||
'https://b.tiles.mapbox.com/v3/mapbox.geography-class/1/0/1.png'
|
||||
);
|
||||
expect(source.getTileUrlFunction()([1, 1, 0])).to.be(
|
||||
'https://c.tiles.mapbox.com/v3/mapbox.geography-class/1/1/0.png'
|
||||
);
|
||||
expect(source.getTileUrlFunction()([1, 1, 1])).to.be(
|
||||
'https://d.tiles.mapbox.com/v3/mapbox.geography-class/1/1/1.png'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getState', function() {
|
||||
|
||||
it('returns error on HTTP 404', function() {
|
||||
describe('#getState', function () {
|
||||
it('returns error on HTTP 404', function () {
|
||||
const source = new TileJSON({
|
||||
url: 'invalid.jsonp'
|
||||
url: 'invalid.jsonp',
|
||||
});
|
||||
source.on('change', function() {
|
||||
source.on('change', function () {
|
||||
expect(source.getState()).to.eql('error');
|
||||
expect(source.getTileJSON()).to.eql(null);
|
||||
});
|
||||
});
|
||||
|
||||
it('returns error on CORS issues', function() {
|
||||
it('returns error on CORS issues', function () {
|
||||
const source = new TileJSON({
|
||||
url: 'http://example.com'
|
||||
url: 'http://example.com',
|
||||
});
|
||||
source.on('change', function() {
|
||||
source.on('change', function () {
|
||||
expect(source.getState()).to.eql('error');
|
||||
expect(source.getTileJSON()).to.eql(null);
|
||||
});
|
||||
});
|
||||
|
||||
it('returns error on JSON parsing issues', function() {
|
||||
it('returns error on JSON parsing issues', function () {
|
||||
const source = new TileJSON({
|
||||
url: '/'
|
||||
url: '/',
|
||||
});
|
||||
source.on('change', function() {
|
||||
source.on('change', function () {
|
||||
expect(source.getState()).to.eql('error');
|
||||
expect(source.getTileJSON()).to.eql(null);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('tileUrlFunction', function() {
|
||||
|
||||
describe('tileUrlFunction', function () {
|
||||
let source, tileGrid;
|
||||
|
||||
beforeEach(function(done) {
|
||||
beforeEach(function (done) {
|
||||
source = new TileJSON({
|
||||
url: 'spec/ol/data/tilejson.json'
|
||||
url: 'spec/ol/data/tilejson.json',
|
||||
});
|
||||
const key = source.on('change', function() {
|
||||
const key = source.on('change', function () {
|
||||
if (source.getState() === 'ready') {
|
||||
unByKey(key);
|
||||
tileGrid = source.getTileGrid();
|
||||
@@ -128,42 +125,45 @@ describe('ol.source.TileJSON', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('uses the correct tile coordinates', function() {
|
||||
|
||||
it('uses the correct tile coordinates', function () {
|
||||
const coordinate = [829330.2064098881, 5933916.615134273];
|
||||
const regex = /\/([0-9]*\/[0-9]*\/[0-9]*)\.png$/;
|
||||
let tileUrl;
|
||||
|
||||
tileUrl = source.tileUrlFunction(
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 0));
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 0)
|
||||
);
|
||||
expect(tileUrl.match(regex)[1]).to.eql('0/0/0');
|
||||
|
||||
tileUrl = source.tileUrlFunction(
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 1));
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 1)
|
||||
);
|
||||
expect(tileUrl.match(regex)[1]).to.eql('1/1/0');
|
||||
|
||||
tileUrl = source.tileUrlFunction(
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 2));
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 2)
|
||||
);
|
||||
expect(tileUrl.match(regex)[1]).to.eql('2/2/1');
|
||||
|
||||
tileUrl = source.tileUrlFunction(
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 3));
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 3)
|
||||
);
|
||||
expect(tileUrl.match(regex)[1]).to.eql('3/4/2');
|
||||
|
||||
tileUrl = source.tileUrlFunction(
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 4));
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 4)
|
||||
);
|
||||
expect(tileUrl.match(regex)[1]).to.eql('4/8/5');
|
||||
|
||||
tileUrl = source.tileUrlFunction(
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 5));
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 5)
|
||||
);
|
||||
expect(tileUrl.match(regex)[1]).to.eql('5/16/11');
|
||||
|
||||
tileUrl = source.tileUrlFunction(
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 6));
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 6)
|
||||
);
|
||||
expect(tileUrl.match(regex)[1]).to.eql('6/33/22');
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -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']);
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import {get as getProjection} from '../../../../src/ol/proj.js';
|
||||
import UrlTile from '../../../../src/ol/source/UrlTile.js';
|
||||
import {createXYZ} from '../../../../src/ol/tilegrid.js';
|
||||
import {get as getProjection} from '../../../../src/ol/proj.js';
|
||||
|
||||
|
||||
describe('ol.source.UrlTile', function() {
|
||||
|
||||
describe('#setUrl()', function() {
|
||||
it('sets the URL for the source', function() {
|
||||
describe('ol.source.UrlTile', function () {
|
||||
describe('#setUrl()', function () {
|
||||
it('sets the URL for the source', function () {
|
||||
const source = new UrlTile({});
|
||||
|
||||
const url = 'https://example.com/';
|
||||
@@ -15,7 +13,7 @@ describe('ol.source.UrlTile', function() {
|
||||
expect(source.getUrls()).to.eql([url]);
|
||||
});
|
||||
|
||||
it('updates the key for the source', function() {
|
||||
it('updates the key for the source', function () {
|
||||
const source = new UrlTile({});
|
||||
|
||||
const url = 'https://example.com/';
|
||||
@@ -25,27 +23,27 @@ describe('ol.source.UrlTile', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setUrls()', function() {
|
||||
it('sets the URL for the source', function() {
|
||||
describe('#setUrls()', function () {
|
||||
it('sets the URL for the source', function () {
|
||||
const source = new UrlTile({});
|
||||
|
||||
const urls = [
|
||||
'https://a.example.com/',
|
||||
'https://b.example.com/',
|
||||
'https://c.example.com/'
|
||||
'https://c.example.com/',
|
||||
];
|
||||
source.setUrls(urls);
|
||||
|
||||
expect(source.getUrls()).to.eql(urls);
|
||||
});
|
||||
|
||||
it('updates the key for the source', function() {
|
||||
it('updates the key for the source', function () {
|
||||
const source = new UrlTile({});
|
||||
|
||||
const urls = [
|
||||
'https://a.example.com/',
|
||||
'https://b.example.com/',
|
||||
'https://c.example.com/'
|
||||
'https://c.example.com/',
|
||||
];
|
||||
source.setUrls(urls);
|
||||
|
||||
@@ -53,10 +51,10 @@ describe('ol.source.UrlTile', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('url option', function() {
|
||||
it('expands url template', function() {
|
||||
describe('url option', function () {
|
||||
it('expands url template', function () {
|
||||
const tileSource = new UrlTile({
|
||||
url: '{1-3}'
|
||||
url: '{1-3}',
|
||||
});
|
||||
|
||||
const urls = tileSource.getUrls();
|
||||
@@ -64,150 +62,149 @@ describe('ol.source.UrlTile', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('tileUrlFunction', function() {
|
||||
|
||||
describe('tileUrlFunction', function () {
|
||||
let tileSource, tileGrid;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
tileSource = new UrlTile({
|
||||
projection: 'EPSG:3857',
|
||||
tileGrid: createXYZ({maxZoom: 6}),
|
||||
url: '{z}/{x}/{y}',
|
||||
wrapX: true
|
||||
wrapX: true,
|
||||
});
|
||||
tileGrid = tileSource.getTileGrid();
|
||||
});
|
||||
|
||||
it('returns the expected URL', function() {
|
||||
|
||||
it('returns the expected URL', function () {
|
||||
const coordinate = [829330.2064098881, 5933916.615134273];
|
||||
let tileUrl;
|
||||
|
||||
tileUrl = tileSource.tileUrlFunction(
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 0));
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 0)
|
||||
);
|
||||
expect(tileUrl).to.eql('0/0/0');
|
||||
|
||||
tileUrl = tileSource.tileUrlFunction(
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 1));
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 1)
|
||||
);
|
||||
expect(tileUrl).to.eql('1/1/0');
|
||||
|
||||
tileUrl = tileSource.tileUrlFunction(
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 2));
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 2)
|
||||
);
|
||||
expect(tileUrl).to.eql('2/2/1');
|
||||
|
||||
tileUrl = tileSource.tileUrlFunction(
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 3));
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 3)
|
||||
);
|
||||
expect(tileUrl).to.eql('3/4/2');
|
||||
|
||||
tileUrl = tileSource.tileUrlFunction(
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 4));
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 4)
|
||||
);
|
||||
expect(tileUrl).to.eql('4/8/5');
|
||||
|
||||
tileUrl = tileSource.tileUrlFunction(
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 5));
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 5)
|
||||
);
|
||||
expect(tileUrl).to.eql('5/16/11');
|
||||
|
||||
tileUrl = tileSource.tileUrlFunction(
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 6));
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 6)
|
||||
);
|
||||
expect(tileUrl).to.eql('6/33/22');
|
||||
|
||||
});
|
||||
|
||||
describe('wrap x', function() {
|
||||
|
||||
it('returns the expected URL', function() {
|
||||
describe('wrap x', function () {
|
||||
it('returns the expected URL', function () {
|
||||
const projection = tileSource.getProjection();
|
||||
let tileUrl = tileSource.tileUrlFunction(
|
||||
tileSource.getTileCoordForTileUrlFunction([6, -31, 22], projection));
|
||||
tileSource.getTileCoordForTileUrlFunction([6, -31, 22], projection)
|
||||
);
|
||||
expect(tileUrl).to.eql('6/33/22');
|
||||
|
||||
tileUrl = tileSource.tileUrlFunction(
|
||||
tileSource.getTileCoordForTileUrlFunction([6, 33, 22], projection));
|
||||
tileSource.getTileCoordForTileUrlFunction([6, 33, 22], projection)
|
||||
);
|
||||
expect(tileUrl).to.eql('6/33/22');
|
||||
|
||||
tileUrl = tileSource.tileUrlFunction(
|
||||
tileSource.getTileCoordForTileUrlFunction([6, 97, 22], projection));
|
||||
tileSource.getTileCoordForTileUrlFunction([6, 97, 22], projection)
|
||||
);
|
||||
expect(tileUrl).to.eql('6/33/22');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('crop y', function() {
|
||||
|
||||
it('returns the expected URL', function() {
|
||||
describe('crop y', function () {
|
||||
it('returns the expected URL', function () {
|
||||
const projection = tileSource.getProjection();
|
||||
let tileUrl = tileSource.tileUrlFunction(
|
||||
tileSource.getTileCoordForTileUrlFunction([6, 33, -1], projection));
|
||||
tileSource.getTileCoordForTileUrlFunction([6, 33, -1], projection)
|
||||
);
|
||||
expect(tileUrl).to.be(undefined);
|
||||
|
||||
tileUrl = tileSource.tileUrlFunction(
|
||||
tileSource.getTileCoordForTileUrlFunction([6, 33, 22], projection));
|
||||
tileSource.getTileCoordForTileUrlFunction([6, 33, 22], projection)
|
||||
);
|
||||
expect(tileUrl).to.eql('6/33/22');
|
||||
|
||||
tileUrl = tileSource.tileUrlFunction(
|
||||
tileSource.getTileCoordForTileUrlFunction([6, 33, 64], projection));
|
||||
tileSource.getTileCoordForTileUrlFunction([6, 33, 64], projection)
|
||||
);
|
||||
expect(tileUrl).to.be(undefined);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getUrls', function() {
|
||||
|
||||
describe('#getUrls', function () {
|
||||
let sourceOptions;
|
||||
let source;
|
||||
const url = 'http://geo.nls.uk/maps/towns/glasgow1857/{z}/{x}/{-y}.png';
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
sourceOptions = {
|
||||
tileGrid: createXYZ({
|
||||
extent: getProjection('EPSG:4326').getExtent()
|
||||
})
|
||||
extent: getProjection('EPSG:4326').getExtent(),
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
describe('using a "url" option', function() {
|
||||
beforeEach(function() {
|
||||
describe('using a "url" option', function () {
|
||||
beforeEach(function () {
|
||||
sourceOptions.url = url;
|
||||
source = new UrlTile(sourceOptions);
|
||||
});
|
||||
|
||||
it('returns the XYZ URL', function() {
|
||||
it('returns the XYZ URL', function () {
|
||||
const urls = source.getUrls();
|
||||
expect(urls).to.be.eql([url]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('using a "urls" option', function() {
|
||||
beforeEach(function() {
|
||||
describe('using a "urls" option', function () {
|
||||
beforeEach(function () {
|
||||
sourceOptions.urls = ['some_xyz_url1', 'some_xyz_url2'];
|
||||
source = new UrlTile(sourceOptions);
|
||||
});
|
||||
|
||||
it('returns the XYZ URLs', function() {
|
||||
it('returns the XYZ URLs', function () {
|
||||
const urls = source.getUrls();
|
||||
expect(urls).to.be.eql(['some_xyz_url1', 'some_xyz_url2']);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('using a "tileUrlFunction"', function() {
|
||||
beforeEach(function() {
|
||||
sourceOptions.tileUrlFunction = function() {
|
||||
describe('using a "tileUrlFunction"', function () {
|
||||
beforeEach(function () {
|
||||
sourceOptions.tileUrlFunction = function () {
|
||||
return 'some_xyz_url';
|
||||
};
|
||||
source = new UrlTile(sourceOptions);
|
||||
});
|
||||
|
||||
it('returns null', function() {
|
||||
it('returns null', function () {
|
||||
const urls = source.getUrls();
|
||||
expect(urls).to.be(null);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,70 +1,69 @@
|
||||
import {get as getProjection, transformExtent, fromLonLat} from '../../../../src/ol/proj.js';
|
||||
import TileGrid from '../../../../src/ol/tilegrid/TileGrid.js';
|
||||
import TileSource from '../../../../src/ol/source/Tile.js';
|
||||
import UTFGrid, {CustomTile} from '../../../../src/ol/source/UTFGrid.js';
|
||||
import TileGrid from '../../../../src/ol/tilegrid/TileGrid.js';
|
||||
|
||||
|
||||
describe('ol.source.UTFGrid', function() {
|
||||
import {
|
||||
fromLonLat,
|
||||
get as getProjection,
|
||||
transformExtent,
|
||||
} from '../../../../src/ol/proj.js';
|
||||
|
||||
describe('ol.source.UTFGrid', function () {
|
||||
const url = 'spec/ol/data/utfgrid.json';
|
||||
let tileJson = null;
|
||||
|
||||
// Load and parse the UTFGrid fixture
|
||||
before(function(done) {
|
||||
before(function (done) {
|
||||
const client = new XMLHttpRequest();
|
||||
client.addEventListener('load', function() {
|
||||
client.addEventListener('load', function () {
|
||||
tileJson = JSON.parse(this.responseText);
|
||||
done();
|
||||
});
|
||||
client.addEventListener('error', function() {
|
||||
client.addEventListener('error', function () {
|
||||
done(new Error('Failed to fetch ' + url));
|
||||
});
|
||||
client.open('GET', url);
|
||||
client.send();
|
||||
});
|
||||
|
||||
after(function() {
|
||||
after(function () {
|
||||
tileJson = null;
|
||||
});
|
||||
|
||||
function getUTFGrid() {
|
||||
return new UTFGrid({
|
||||
url: url
|
||||
url: url,
|
||||
});
|
||||
}
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('needs to be constructed with url option', function() {
|
||||
|
||||
describe('constructor', function () {
|
||||
it('needs to be constructed with url option', function () {
|
||||
const source = new UTFGrid({url: url});
|
||||
expect(source).to.be.an(UTFGrid);
|
||||
expect(source).to.be.an(TileSource);
|
||||
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
// no options: will throw
|
||||
return new UTFGrid();
|
||||
}).to.throwException();
|
||||
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
// no url-option: will throw
|
||||
return new UTFGrid({});
|
||||
}).to.throwException();
|
||||
|
||||
expect(getUTFGrid()).to.be.an(UTFGrid);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('change event (ready)', function() {
|
||||
it('is fired when the source is ready', function(done) {
|
||||
describe('change event (ready)', function () {
|
||||
it('is fired when the source is ready', function (done) {
|
||||
const source = new UTFGrid({
|
||||
url: url
|
||||
url: url,
|
||||
});
|
||||
expect(source.getState()).to.be('loading');
|
||||
expect(source.tileGrid).to.be(null);
|
||||
|
||||
source.on('change', function(event) {
|
||||
source.on('change', function (event) {
|
||||
if (source.getState() === 'ready') {
|
||||
expect(source.tileGrid).to.be.an(TileGrid);
|
||||
done();
|
||||
@@ -73,15 +72,15 @@ describe('ol.source.UTFGrid', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('change event (error)', function(done) {
|
||||
it('is fired when the source fails to initialize', function(done) {
|
||||
describe('change event (error)', function (done) {
|
||||
it('is fired when the source fails to initialize', function (done) {
|
||||
const source = new UTFGrid({
|
||||
url: 'Bogus UTFGrid URL'
|
||||
url: 'Bogus UTFGrid URL',
|
||||
});
|
||||
expect(source.getState()).to.be('loading');
|
||||
expect(source.tileGrid).to.be(null);
|
||||
|
||||
source.on('change', function(event) {
|
||||
source.on('change', function (event) {
|
||||
if (source.getState() === 'error') {
|
||||
expect(source.tileGrid).to.be(null);
|
||||
done();
|
||||
@@ -90,9 +89,8 @@ describe('ol.source.UTFGrid', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#handleTileJSONResponse', function() {
|
||||
|
||||
it('sets up a tileGrid', function() {
|
||||
describe('#handleTileJSONResponse', function () {
|
||||
it('sets up a tileGrid', function () {
|
||||
const source = getUTFGrid();
|
||||
expect(source.getTileGrid()).to.be(null);
|
||||
// call the handleTileJSONResponse method with our
|
||||
@@ -104,7 +102,7 @@ describe('ol.source.UTFGrid', function() {
|
||||
expect(tileGrid).to.be.an(TileGrid);
|
||||
});
|
||||
|
||||
it('sets up a tilegrid with expected extent', function() {
|
||||
it('sets up a tilegrid with expected extent', function () {
|
||||
const source = getUTFGrid();
|
||||
// call the handleTileJSONResponse method with our
|
||||
// locally available tileJson (from `before`)
|
||||
@@ -117,7 +115,9 @@ describe('ol.source.UTFGrid', function() {
|
||||
const proj3857 = getProjection('EPSG:3857');
|
||||
const expectedExtent4326 = tileJson.bounds;
|
||||
const expectedExtent3857 = transformExtent(
|
||||
expectedExtent4326, proj4326, proj3857
|
||||
expectedExtent4326,
|
||||
proj4326,
|
||||
proj3857
|
||||
);
|
||||
expect(extent).to.eql(proj3857.getExtent());
|
||||
expect(extent[0]).to.roughlyEqual(expectedExtent3857[0], 1e-8);
|
||||
@@ -126,7 +126,7 @@ describe('ol.source.UTFGrid', function() {
|
||||
expect(extent[3]).to.roughlyEqual(expectedExtent3857[3], 1e-8);
|
||||
});
|
||||
|
||||
it('sets up a tilegrid with expected minZoom', function() {
|
||||
it('sets up a tilegrid with expected minZoom', function () {
|
||||
const source = getUTFGrid();
|
||||
// call the handleTileJSONResponse method with our
|
||||
// locally available tileJson (from `before`)
|
||||
@@ -137,7 +137,7 @@ describe('ol.source.UTFGrid', function() {
|
||||
expect(minZoom).to.eql(tileJson.minzoom);
|
||||
});
|
||||
|
||||
it('sets up a tilegrid with expected maxZoom', function() {
|
||||
it('sets up a tilegrid with expected maxZoom', function () {
|
||||
const source = getUTFGrid();
|
||||
// call the handleTileJSONResponse method with our
|
||||
// locally available tileJson (from `before`)
|
||||
@@ -148,7 +148,7 @@ describe('ol.source.UTFGrid', function() {
|
||||
expect(maxZoom).to.eql(tileJson.maxzoom);
|
||||
});
|
||||
|
||||
it('sets up a template', function() {
|
||||
it('sets up a template', function () {
|
||||
const source = getUTFGrid();
|
||||
expect(source.getTemplate()).to.be(undefined);
|
||||
|
||||
@@ -161,7 +161,7 @@ describe('ol.source.UTFGrid', function() {
|
||||
expect(template).to.be(tileJson.template);
|
||||
});
|
||||
|
||||
it('sets up correct attribution', function() {
|
||||
it('sets up correct attribution', function () {
|
||||
const source = getUTFGrid();
|
||||
expect(source.getAttributions()).to.be(null);
|
||||
|
||||
@@ -174,7 +174,7 @@ describe('ol.source.UTFGrid', function() {
|
||||
expect(typeof attributions).to.be('function');
|
||||
});
|
||||
|
||||
it('sets correct state', function() {
|
||||
it('sets correct state', function () {
|
||||
const source = getUTFGrid();
|
||||
expect(source.getState()).to.be('loading');
|
||||
|
||||
@@ -184,10 +184,9 @@ describe('ol.source.UTFGrid', function() {
|
||||
|
||||
expect(source.getState()).to.be('ready');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#forDataAtCoordinateAndResolution', function() {
|
||||
describe('#forDataAtCoordinateAndResolution', function () {
|
||||
let source = null;
|
||||
const bonn3857 = fromLonLat([7.099814, 50.733992]);
|
||||
const noState3857 = [0, 0];
|
||||
@@ -198,23 +197,23 @@ describe('ol.source.UTFGrid', function() {
|
||||
// grid for one tile (1/1/0) and store the result in a variable. This allows
|
||||
// us to overwrite getTile in a way that removes the dependency on an
|
||||
// external service. See below in the `beforeEach`-method.
|
||||
before(function(done) {
|
||||
before(function (done) {
|
||||
const client = new XMLHttpRequest();
|
||||
client.addEventListener('load', function() {
|
||||
client.addEventListener('load', function () {
|
||||
gridJson110 = JSON.parse(this.responseText);
|
||||
done();
|
||||
});
|
||||
client.addEventListener('error', function() {
|
||||
client.addEventListener('error', function () {
|
||||
done(new Error('Failed to fetch local grid.json'));
|
||||
});
|
||||
client.open('GET', 'spec/ol/data/mapbox-geography-class-1-1-0.grid.json');
|
||||
client.send();
|
||||
});
|
||||
after(function() {
|
||||
after(function () {
|
||||
gridJson110 = null;
|
||||
});
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
source = getUTFGrid();
|
||||
// call the handleTileJSONResponse method with our
|
||||
// locally available tileJson (from `before`)
|
||||
@@ -223,29 +222,35 @@ describe('ol.source.UTFGrid', function() {
|
||||
// Override getTile method to not depend on the external service. The
|
||||
// signature of the method is kept the same, but the returned tile will
|
||||
// always be for [1, 1, 0].
|
||||
source.getTile = function(z, x, y, pixelRatio, projection) {
|
||||
source.getTile = function (z, x, y, pixelRatio, projection) {
|
||||
const tileCoord = [1, 1, 0]; // overwritten to match our stored JSON
|
||||
const urlTileCoord =
|
||||
this.getTileCoordForTileUrlFunction(tileCoord, projection);
|
||||
const tileUrl = this.tileUrlFunction_(urlTileCoord, pixelRatio, projection);
|
||||
const urlTileCoord = this.getTileCoordForTileUrlFunction(
|
||||
tileCoord,
|
||||
projection
|
||||
);
|
||||
const tileUrl = this.tileUrlFunction_(
|
||||
urlTileCoord,
|
||||
pixelRatio,
|
||||
projection
|
||||
);
|
||||
const tile = new CustomTile(
|
||||
tileCoord,
|
||||
tileUrl !== undefined ? 0 : 4, // IDLE : EMPTY
|
||||
tileUrl !== undefined ? tileUrl : '',
|
||||
this.tileGrid.getTileCoordExtent(tileCoord),
|
||||
true); // always preemptive, so loading doesn't happen automatically
|
||||
true
|
||||
); // always preemptive, so loading doesn't happen automatically
|
||||
// manually call handleLoad_ with our local JSON data
|
||||
tile.handleLoad_(gridJson110);
|
||||
return tile;
|
||||
};
|
||||
|
||||
});
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
source = null;
|
||||
});
|
||||
|
||||
it('calls callback with data if found', function(done) {
|
||||
const callback = function(data) {
|
||||
it('calls callback with data if found', function (done) {
|
||||
const callback = function (data) {
|
||||
expect(arguments).to.have.length(1);
|
||||
expect(data).to.not.be(null);
|
||||
expect('admin' in data).to.be(true);
|
||||
@@ -253,21 +258,25 @@ describe('ol.source.UTFGrid', function() {
|
||||
done();
|
||||
};
|
||||
source.forDataAtCoordinateAndResolution(
|
||||
bonn3857, resolutionZoom1, callback, true
|
||||
bonn3857,
|
||||
resolutionZoom1,
|
||||
callback,
|
||||
true
|
||||
);
|
||||
});
|
||||
|
||||
it('calls callback with `null` if not found', function(done) {
|
||||
const callback = function(data) {
|
||||
it('calls callback with `null` if not found', function (done) {
|
||||
const callback = function (data) {
|
||||
expect(arguments).to.have.length(1);
|
||||
expect(data).to.be(null);
|
||||
done();
|
||||
};
|
||||
source.forDataAtCoordinateAndResolution(
|
||||
noState3857, resolutionZoom1, callback, true
|
||||
noState3857,
|
||||
resolutionZoom1,
|
||||
callback,
|
||||
true
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,65 +1,59 @@
|
||||
import {listen} from '../../../../src/ol/events.js';
|
||||
import Collection from '../../../../src/ol/Collection.js';
|
||||
import Feature from '../../../../src/ol/Feature.js';
|
||||
import Map from '../../../../src/ol/Map.js';
|
||||
import View from '../../../../src/ol/View.js';
|
||||
import Point from '../../../../src/ol/geom/Point.js';
|
||||
import LineString from '../../../../src/ol/geom/LineString.js';
|
||||
import VectorLayer from '../../../../src/ol/layer/Vector.js';
|
||||
import {bbox as bboxStrategy} from '../../../../src/ol/loadingstrategy.js';
|
||||
import {get as getProjection, transformExtent, fromLonLat} from '../../../../src/ol/proj.js';
|
||||
import VectorSource from '../../../../src/ol/source/Vector.js';
|
||||
import GeoJSON from '../../../../src/ol/format/GeoJSON.js';
|
||||
import LineString from '../../../../src/ol/geom/LineString.js';
|
||||
import Map from '../../../../src/ol/Map.js';
|
||||
import Point from '../../../../src/ol/geom/Point.js';
|
||||
import VectorLayer from '../../../../src/ol/layer/Vector.js';
|
||||
import VectorSource from '../../../../src/ol/source/Vector.js';
|
||||
import View from '../../../../src/ol/View.js';
|
||||
import {bbox as bboxStrategy} from '../../../../src/ol/loadingstrategy.js';
|
||||
import {
|
||||
fromLonLat,
|
||||
get as getProjection,
|
||||
transformExtent,
|
||||
} from '../../../../src/ol/proj.js';
|
||||
import {getUid} from '../../../../src/ol/util.js';
|
||||
import {listen} from '../../../../src/ol/events.js';
|
||||
|
||||
|
||||
describe('ol.source.Vector', function() {
|
||||
|
||||
describe('ol.source.Vector', function () {
|
||||
let pointFeature;
|
||||
let infiniteExtent;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
pointFeature = new Feature(new Point([0, 0]));
|
||||
infiniteExtent = [-Infinity, -Infinity, Infinity, Infinity];
|
||||
});
|
||||
|
||||
describe('when empty', function() {
|
||||
|
||||
describe('when empty', function () {
|
||||
let vectorSource;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
vectorSource = new VectorSource();
|
||||
});
|
||||
|
||||
describe('#forEachFeatureInExtent', function() {
|
||||
|
||||
it('does not call the callback', function() {
|
||||
describe('#forEachFeatureInExtent', function () {
|
||||
it('does not call the callback', function () {
|
||||
const f = sinon.spy();
|
||||
vectorSource.forEachFeatureInExtent(infiniteExtent, f);
|
||||
expect(f.called).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getFeaturesInExtent', function() {
|
||||
|
||||
it('returns an empty array', function() {
|
||||
describe('#getFeaturesInExtent', function () {
|
||||
it('returns an empty array', function () {
|
||||
const features = vectorSource.getFeaturesInExtent(infiniteExtent);
|
||||
expect(features).to.be.an(Array);
|
||||
expect(features).to.be.empty();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#isEmpty', function() {
|
||||
|
||||
it('returns true', function() {
|
||||
describe('#isEmpty', function () {
|
||||
it('returns true', function () {
|
||||
expect(vectorSource.isEmpty()).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#addFeature', function() {
|
||||
|
||||
it('can add a single point feature', function() {
|
||||
describe('#addFeature', function () {
|
||||
it('can add a single point feature', function () {
|
||||
vectorSource.addFeature(pointFeature);
|
||||
const features = vectorSource.getFeaturesInExtent(infiniteExtent);
|
||||
expect(features).to.be.an(Array);
|
||||
@@ -67,14 +61,14 @@ describe('ol.source.Vector', function() {
|
||||
expect(features[0]).to.be(pointFeature);
|
||||
});
|
||||
|
||||
it('fires a change event', function() {
|
||||
it('fires a change event', function () {
|
||||
const listener = sinon.spy();
|
||||
listen(vectorSource, 'change', listener);
|
||||
vectorSource.addFeature(pointFeature);
|
||||
expect(listener.called).to.be(true);
|
||||
});
|
||||
|
||||
it('adds same id features only once', function() {
|
||||
it('adds same id features only once', function () {
|
||||
const source = new VectorSource();
|
||||
const feature1 = new Feature();
|
||||
feature1.setId('1');
|
||||
@@ -84,78 +78,79 @@ describe('ol.source.Vector', function() {
|
||||
source.addFeature(feature2);
|
||||
expect(source.getFeatures().length).to.be(1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#hasFeature', function() {
|
||||
|
||||
it('returns true for added feature without id', function() {
|
||||
describe('#hasFeature', function () {
|
||||
it('returns true for added feature without id', function () {
|
||||
const feature = new Feature();
|
||||
vectorSource.addFeature(feature);
|
||||
expect(vectorSource.hasFeature(feature)).to.be(true);
|
||||
});
|
||||
|
||||
it('returns true for added feature with id', function() {
|
||||
it('returns true for added feature with id', function () {
|
||||
const feature = new Feature();
|
||||
feature.setId('1');
|
||||
vectorSource.addFeature(feature);
|
||||
expect(vectorSource.hasFeature(feature)).to.be(true);
|
||||
});
|
||||
|
||||
it('return false for removed feature', function() {
|
||||
it('return false for removed feature', function () {
|
||||
const feature = new Feature();
|
||||
vectorSource.addFeature(feature);
|
||||
vectorSource.removeFeature(feature);
|
||||
expect(vectorSource.hasFeature(feature)).to.be(false);
|
||||
});
|
||||
|
||||
it('returns false for non-added feature', function() {
|
||||
it('returns false for non-added feature', function () {
|
||||
const feature = new Feature();
|
||||
expect(vectorSource.hasFeature(feature)).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('when populated with 3 features', function() {
|
||||
|
||||
describe('when populated with 3 features', function () {
|
||||
const features = [];
|
||||
let vectorSource;
|
||||
beforeEach(function() {
|
||||
features.push(new Feature(new LineString([[0, 0], [10, 10]])));
|
||||
beforeEach(function () {
|
||||
features.push(
|
||||
new Feature(
|
||||
new LineString([
|
||||
[0, 0],
|
||||
[10, 10],
|
||||
])
|
||||
)
|
||||
);
|
||||
features.push(new Feature(new Point([0, 10])));
|
||||
features.push(new Feature(new Point([10, 5])));
|
||||
vectorSource = new VectorSource({
|
||||
features: features
|
||||
features: features,
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getClosestFeatureToCoordinate', function() {
|
||||
|
||||
it('returns the expected feature', function() {
|
||||
describe('#getClosestFeatureToCoordinate', function () {
|
||||
it('returns the expected feature', function () {
|
||||
const feature = vectorSource.getClosestFeatureToCoordinate([1, 9]);
|
||||
expect(feature).to.be(features[1]);
|
||||
});
|
||||
|
||||
it('returns the expected feature when a filter is used', function() {
|
||||
const feature = vectorSource.getClosestFeatureToCoordinate([1, 9], function(feature) {
|
||||
return feature.getGeometry().getType() == 'LineString';
|
||||
});
|
||||
it('returns the expected feature when a filter is used', function () {
|
||||
const feature = vectorSource.getClosestFeatureToCoordinate(
|
||||
[1, 9],
|
||||
function (feature) {
|
||||
return feature.getGeometry().getType() == 'LineString';
|
||||
}
|
||||
);
|
||||
expect(feature).to.be(features[0]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('clear and refresh', function() {
|
||||
|
||||
describe('clear and refresh', function () {
|
||||
let map, source, spy;
|
||||
beforeEach(function(done) {
|
||||
beforeEach(function (done) {
|
||||
source = new VectorSource({
|
||||
format: new GeoJSON(),
|
||||
url: 'spec/ol/source/vectorsource/single-feature.json'
|
||||
url: 'spec/ol/source/vectorsource/single-feature.json',
|
||||
});
|
||||
const target = document.createElement('div');
|
||||
target.style.width = '100px';
|
||||
@@ -165,21 +160,21 @@ describe('ol.source.Vector', function() {
|
||||
target: target,
|
||||
layers: [
|
||||
new VectorLayer({
|
||||
source: source
|
||||
})
|
||||
source: source,
|
||||
}),
|
||||
],
|
||||
view: new View({
|
||||
center: [0, 0],
|
||||
zoom: 0
|
||||
})
|
||||
zoom: 0,
|
||||
}),
|
||||
});
|
||||
map.once('rendercomplete', function() {
|
||||
map.once('rendercomplete', function () {
|
||||
spy = sinon.spy(source, 'loader_');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
if (spy) {
|
||||
source.loader_.restore();
|
||||
}
|
||||
@@ -187,9 +182,9 @@ describe('ol.source.Vector', function() {
|
||||
map.setTarget(null);
|
||||
});
|
||||
|
||||
it('#refresh() reloads from server', function(done) {
|
||||
it('#refresh() reloads from server', function (done) {
|
||||
expect(source.getFeatures()).to.have.length(1);
|
||||
map.once('rendercomplete', function() {
|
||||
map.once('rendercomplete', function () {
|
||||
expect(source.getFeatures()).to.have.length(1);
|
||||
expect(spy.callCount).to.be(1);
|
||||
done();
|
||||
@@ -197,9 +192,9 @@ describe('ol.source.Vector', function() {
|
||||
source.refresh();
|
||||
});
|
||||
|
||||
it('#clear() removes all features from the source', function(done) {
|
||||
it('#clear() removes all features from the source', function (done) {
|
||||
expect(source.getFeatures()).to.have.length(1);
|
||||
map.once('rendercomplete', function() {
|
||||
map.once('rendercomplete', function () {
|
||||
expect(source.getFeatures()).to.have.length(0);
|
||||
expect(spy.callCount).to.be(0);
|
||||
done();
|
||||
@@ -207,14 +202,20 @@ describe('ol.source.Vector', function() {
|
||||
source.clear();
|
||||
});
|
||||
|
||||
it('After #setUrl(), refresh() loads from the new url', function(done) {
|
||||
it('After #setUrl(), refresh() loads from the new url', function (done) {
|
||||
source.loader_.restore();
|
||||
spy = undefined;
|
||||
expect(source.getFeatures()).to.have.length(1);
|
||||
const oldCoordinates = source.getFeatures()[0].getGeometry().getCoordinates();
|
||||
map.on('rendercomplete', function() {
|
||||
const oldCoordinates = source
|
||||
.getFeatures()[0]
|
||||
.getGeometry()
|
||||
.getCoordinates();
|
||||
map.on('rendercomplete', function () {
|
||||
expect(source.getFeatures()).to.have.length(1);
|
||||
const newCoordinates = source.getFeatures()[0].getGeometry().getCoordinates();
|
||||
const newCoordinates = source
|
||||
.getFeatures()[0]
|
||||
.getGeometry()
|
||||
.getCoordinates();
|
||||
expect(newCoordinates).to.not.eql(oldCoordinates);
|
||||
done();
|
||||
});
|
||||
@@ -223,26 +224,23 @@ describe('ol.source.Vector', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('when populated with 10 random points and a null', function() {
|
||||
|
||||
describe('when populated with 10 random points and a null', function () {
|
||||
let features;
|
||||
let vectorSource;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
features = [];
|
||||
let i;
|
||||
for (i = 0; i < 10; ++i) {
|
||||
features[i] =
|
||||
new Feature(new Point([Math.random(), Math.random()]));
|
||||
features[i] = new Feature(new Point([Math.random(), Math.random()]));
|
||||
}
|
||||
features.push(new Feature(null));
|
||||
vectorSource = new VectorSource({
|
||||
features: features
|
||||
features: features,
|
||||
});
|
||||
});
|
||||
|
||||
describe('#clear', function() {
|
||||
|
||||
it('removes all features using fast path', function() {
|
||||
describe('#clear', function () {
|
||||
it('removes all features using fast path', function () {
|
||||
const removeFeatureSpy = sinon.spy();
|
||||
listen(vectorSource, 'removefeature', removeFeatureSpy);
|
||||
const clearSourceSpy = sinon.spy();
|
||||
@@ -256,7 +254,7 @@ describe('ol.source.Vector', function() {
|
||||
expect(clearSourceSpy.callCount).to.be(1);
|
||||
});
|
||||
|
||||
it('removes all features using slow path', function() {
|
||||
it('removes all features using slow path', function () {
|
||||
const removeFeatureSpy = sinon.spy();
|
||||
listen(vectorSource, 'removefeature', removeFeatureSpy);
|
||||
const clearSourceSpy = sinon.spy();
|
||||
@@ -269,149 +267,138 @@ describe('ol.source.Vector', function() {
|
||||
expect(clearSourceSpy.called).to.be(true);
|
||||
expect(clearSourceSpy.callCount).to.be(1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#forEachFeatureInExtent', function() {
|
||||
|
||||
it('is called the expected number of times', function() {
|
||||
describe('#forEachFeatureInExtent', function () {
|
||||
it('is called the expected number of times', function () {
|
||||
const f = sinon.spy();
|
||||
vectorSource.forEachFeatureInExtent(infiniteExtent, f);
|
||||
expect(f.callCount).to.be(10);
|
||||
});
|
||||
|
||||
it('allows breaking out', function() {
|
||||
it('allows breaking out', function () {
|
||||
let count = 0;
|
||||
const result = vectorSource.forEachFeatureInExtent(infiniteExtent,
|
||||
function(f) {
|
||||
const result = vectorSource.forEachFeatureInExtent(
|
||||
infiniteExtent,
|
||||
function (f) {
|
||||
return ++count == 5;
|
||||
});
|
||||
}
|
||||
);
|
||||
expect(result).to.be(true);
|
||||
expect(count).to.be(5);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getFeaturesInExtent', function() {
|
||||
|
||||
it('returns the expected number of features', function() {
|
||||
expect(vectorSource.getFeaturesInExtent(infiniteExtent)).
|
||||
to.have.length(10);
|
||||
describe('#getFeaturesInExtent', function () {
|
||||
it('returns the expected number of features', function () {
|
||||
expect(vectorSource.getFeaturesInExtent(infiniteExtent)).to.have.length(
|
||||
10
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#isEmpty', function() {
|
||||
|
||||
it('returns false', function() {
|
||||
describe('#isEmpty', function () {
|
||||
it('returns false', function () {
|
||||
expect(vectorSource.isEmpty()).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#removeFeature', function() {
|
||||
|
||||
it('works as expected', function() {
|
||||
describe('#removeFeature', function () {
|
||||
it('works as expected', function () {
|
||||
let i;
|
||||
for (i = features.length - 1; i >= 0; --i) {
|
||||
vectorSource.removeFeature(features[i]);
|
||||
expect(vectorSource.getFeaturesInExtent(infiniteExtent)).
|
||||
have.length(i);
|
||||
expect(vectorSource.getFeaturesInExtent(infiniteExtent)).have.length(
|
||||
i
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it('fires a change event', function() {
|
||||
it('fires a change event', function () {
|
||||
const listener = sinon.spy();
|
||||
listen(vectorSource, 'change', listener);
|
||||
vectorSource.removeFeature(features[0]);
|
||||
expect(listener.called).to.be(true);
|
||||
});
|
||||
|
||||
it('fires a removefeature event', function() {
|
||||
it('fires a removefeature event', function () {
|
||||
const listener = sinon.spy();
|
||||
listen(vectorSource, 'removefeature', listener);
|
||||
vectorSource.removeFeature(features[0]);
|
||||
expect(listener.called).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('modifying a feature\'s geometry', function() {
|
||||
|
||||
it('keeps the R-Tree index up to date', function() {
|
||||
expect(vectorSource.getFeaturesInExtent([0, 0, 1, 1])).
|
||||
to.have.length(10);
|
||||
describe("modifying a feature's geometry", function () {
|
||||
it('keeps the R-Tree index up to date', function () {
|
||||
expect(vectorSource.getFeaturesInExtent([0, 0, 1, 1])).to.have.length(
|
||||
10
|
||||
);
|
||||
features[0].getGeometry().setCoordinates([100, 100]);
|
||||
expect(vectorSource.getFeaturesInExtent([0, 0, 1, 1])).
|
||||
to.have.length(9);
|
||||
expect(vectorSource.getFeaturesInExtent([0, 0, 1, 1])).to.have.length(
|
||||
9
|
||||
);
|
||||
features[0].getGeometry().setCoordinates([0.5, 0.5]);
|
||||
expect(vectorSource.getFeaturesInExtent([0, 0, 1, 1])).
|
||||
to.have.length(10);
|
||||
expect(vectorSource.getFeaturesInExtent([0, 0, 1, 1])).to.have.length(
|
||||
10
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('setting a features geometry', function() {
|
||||
|
||||
it('keeps the R-Tree index up to date', function() {
|
||||
expect(vectorSource.getFeaturesInExtent([0, 0, 1, 1])).
|
||||
to.have.length(10);
|
||||
describe('setting a features geometry', function () {
|
||||
it('keeps the R-Tree index up to date', function () {
|
||||
expect(vectorSource.getFeaturesInExtent([0, 0, 1, 1])).to.have.length(
|
||||
10
|
||||
);
|
||||
features[0].setGeometry(new Point([100, 100]));
|
||||
expect(vectorSource.getFeaturesInExtent([0, 0, 1, 1])).
|
||||
to.have.length(9);
|
||||
expect(vectorSource.getFeaturesInExtent([0, 0, 1, 1])).to.have.length(
|
||||
9
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('tracking changes to features', function() {
|
||||
|
||||
describe('tracking changes to features', function () {
|
||||
let vectorSource;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
vectorSource = new VectorSource();
|
||||
});
|
||||
|
||||
it('keeps its index up-to-date', function() {
|
||||
it('keeps its index up-to-date', function () {
|
||||
const feature = new Feature(new Point([1, 1]));
|
||||
vectorSource.addFeature(feature);
|
||||
expect(vectorSource.getFeaturesInExtent([0, 0, 2, 2])).
|
||||
to.eql([feature]);
|
||||
expect(vectorSource.getFeaturesInExtent([0, 0, 2, 2])).to.eql([feature]);
|
||||
feature.getGeometry().setCoordinates([3, 3]);
|
||||
expect(vectorSource.getFeaturesInExtent([0, 0, 2, 2])).
|
||||
to.be.empty();
|
||||
expect(vectorSource.getFeaturesInExtent([2, 2, 4, 4])).
|
||||
to.eql([feature]);
|
||||
expect(vectorSource.getFeaturesInExtent([0, 0, 2, 2])).to.be.empty();
|
||||
expect(vectorSource.getFeaturesInExtent([2, 2, 4, 4])).to.eql([feature]);
|
||||
});
|
||||
|
||||
it('handles features with null geometries', function() {
|
||||
it('handles features with null geometries', function () {
|
||||
const feature = new Feature(null);
|
||||
vectorSource.addFeature(feature);
|
||||
expect(vectorSource.getFeatures()).to.eql([feature]);
|
||||
});
|
||||
|
||||
it('handles features with geometries changing from null', function() {
|
||||
it('handles features with geometries changing from null', function () {
|
||||
const feature = new Feature(null);
|
||||
vectorSource.addFeature(feature);
|
||||
expect(vectorSource.getFeatures()).to.eql([feature]);
|
||||
feature.setGeometry(new Point([1, 1]));
|
||||
expect(vectorSource.getFeaturesInExtent([0, 0, 2, 2])).
|
||||
to.eql([feature]);
|
||||
expect(vectorSource.getFeaturesInExtent([0, 0, 2, 2])).to.eql([feature]);
|
||||
expect(vectorSource.getFeatures()).to.eql([feature]);
|
||||
});
|
||||
|
||||
it('handles features with geometries changing to null', function() {
|
||||
it('handles features with geometries changing to null', function () {
|
||||
const feature = new Feature(new Point([1, 1]));
|
||||
vectorSource.addFeature(feature);
|
||||
expect(vectorSource.getFeatures()).to.eql([feature]);
|
||||
expect(vectorSource.getFeaturesInExtent([0, 0, 2, 2])).
|
||||
to.eql([feature]);
|
||||
expect(vectorSource.getFeaturesInExtent([0, 0, 2, 2])).to.eql([feature]);
|
||||
feature.setGeometry(null);
|
||||
expect(vectorSource.getFeaturesInExtent([0, 0, 2, 2])).to.be.empty();
|
||||
expect(vectorSource.getFeatures()).to.eql([feature]);
|
||||
});
|
||||
|
||||
it('fires a change event when setting a feature\'s property', function() {
|
||||
it("fires a change event when setting a feature's property", function () {
|
||||
const feature = new Feature(new Point([1, 1]));
|
||||
vectorSource.addFeature(feature);
|
||||
const listener = sinon.spy();
|
||||
@@ -420,33 +407,32 @@ describe('ol.source.Vector', function() {
|
||||
expect(listener.called).to.be(true);
|
||||
});
|
||||
|
||||
it('fires a changefeature event when updating a feature', function() {
|
||||
it('fires a changefeature event when updating a feature', function () {
|
||||
const feature = new Feature(new Point([1, 1]));
|
||||
vectorSource.addFeature(feature);
|
||||
const listener = sinon.spy(function(event) {
|
||||
const listener = sinon.spy(function (event) {
|
||||
expect(event.feature).to.be(feature);
|
||||
});
|
||||
vectorSource.on('changefeature', listener);
|
||||
feature.setStyle(null);
|
||||
expect(listener.called).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getFeatureById()', function() {
|
||||
describe('#getFeatureById()', function () {
|
||||
let source;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
source = new VectorSource();
|
||||
});
|
||||
|
||||
it('returns a feature by id', function() {
|
||||
it('returns a feature by id', function () {
|
||||
const feature = new Feature();
|
||||
feature.setId('foo');
|
||||
source.addFeature(feature);
|
||||
expect(source.getFeatureById('foo')).to.be(feature);
|
||||
});
|
||||
|
||||
it('returns a feature by id (set after add)', function() {
|
||||
it('returns a feature by id (set after add)', function () {
|
||||
const feature = new Feature();
|
||||
source.addFeature(feature);
|
||||
expect(source.getFeatureById('foo')).to.be(null);
|
||||
@@ -454,14 +440,14 @@ describe('ol.source.Vector', function() {
|
||||
expect(source.getFeatureById('foo')).to.be(feature);
|
||||
});
|
||||
|
||||
it('returns null when no feature is found', function() {
|
||||
it('returns null when no feature is found', function () {
|
||||
const feature = new Feature();
|
||||
feature.setId('foo');
|
||||
source.addFeature(feature);
|
||||
expect(source.getFeatureById('bar')).to.be(null);
|
||||
});
|
||||
|
||||
it('returns null after removing feature', function() {
|
||||
it('returns null after removing feature', function () {
|
||||
const feature = new Feature();
|
||||
feature.setId('foo');
|
||||
source.addFeature(feature);
|
||||
@@ -470,7 +456,7 @@ describe('ol.source.Vector', function() {
|
||||
expect(source.getFeatureById('foo')).to.be(null);
|
||||
});
|
||||
|
||||
it('returns null after unsetting id', function() {
|
||||
it('returns null after unsetting id', function () {
|
||||
const feature = new Feature();
|
||||
feature.setId('foo');
|
||||
source.addFeature(feature);
|
||||
@@ -479,7 +465,7 @@ describe('ol.source.Vector', function() {
|
||||
expect(source.getFeatureById('foo')).to.be(null);
|
||||
});
|
||||
|
||||
it('returns null after clear', function() {
|
||||
it('returns null after clear', function () {
|
||||
const feature = new Feature();
|
||||
feature.setId('foo');
|
||||
source.addFeature(feature);
|
||||
@@ -488,13 +474,13 @@ describe('ol.source.Vector', function() {
|
||||
expect(source.getFeatureById('foo')).to.be(null);
|
||||
});
|
||||
|
||||
it('returns null when no features are indexed', function() {
|
||||
it('returns null when no features are indexed', function () {
|
||||
expect(source.getFeatureById('foo')).to.be(null);
|
||||
source.addFeature(new Feature());
|
||||
expect(source.getFeatureById('foo')).to.be(null);
|
||||
});
|
||||
|
||||
it('returns correct feature after add/remove/add', function() {
|
||||
it('returns correct feature after add/remove/add', function () {
|
||||
expect(source.getFeatureById('foo')).to.be(null);
|
||||
const first = new Feature();
|
||||
first.setId('foo');
|
||||
@@ -508,7 +494,7 @@ describe('ol.source.Vector', function() {
|
||||
expect(source.getFeatureById('foo')).to.be(second);
|
||||
});
|
||||
|
||||
it('returns correct feature after add/change', function() {
|
||||
it('returns correct feature after add/change', function () {
|
||||
expect(source.getFeatureById('foo')).to.be(null);
|
||||
const feature = new Feature();
|
||||
feature.setId('foo');
|
||||
@@ -518,29 +504,28 @@ describe('ol.source.Vector', function() {
|
||||
expect(source.getFeatureById('foo')).to.be(null);
|
||||
expect(source.getFeatureById('bar')).to.be(feature);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getFeatureByUid()', function() {
|
||||
describe('#getFeatureByUid()', function () {
|
||||
let source;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
source = new VectorSource();
|
||||
});
|
||||
|
||||
it('returns a feature with an id', function() {
|
||||
it('returns a feature with an id', function () {
|
||||
const feature = new Feature();
|
||||
feature.setId('abcd');
|
||||
source.addFeature(feature);
|
||||
expect(source.getFeatureByUid(getUid(feature))).to.be(feature);
|
||||
});
|
||||
|
||||
it('returns a feature without id', function() {
|
||||
it('returns a feature without id', function () {
|
||||
const feature = new Feature();
|
||||
source.addFeature(feature);
|
||||
expect(source.getFeatureByUid(getUid(feature))).to.be(feature);
|
||||
});
|
||||
|
||||
it('returns null when no feature is found', function() {
|
||||
it('returns null when no feature is found', function () {
|
||||
const feature = new Feature();
|
||||
feature.setId('abcd');
|
||||
source.addFeature(feature);
|
||||
@@ -548,7 +533,7 @@ describe('ol.source.Vector', function() {
|
||||
expect(source.getFeatureByUid(wrongId)).to.be(null);
|
||||
});
|
||||
|
||||
it('returns null after removing feature', function() {
|
||||
it('returns null after removing feature', function () {
|
||||
const feature = new Feature();
|
||||
feature.setId('abcd');
|
||||
source.addFeature(feature);
|
||||
@@ -558,7 +543,7 @@ describe('ol.source.Vector', function() {
|
||||
expect(source.getFeatureByUid(uid)).to.be(null);
|
||||
});
|
||||
|
||||
it('returns null after clear', function() {
|
||||
it('returns null after clear', function () {
|
||||
const feature = new Feature();
|
||||
feature.setId('abcd');
|
||||
source.addFeature(feature);
|
||||
@@ -568,29 +553,29 @@ describe('ol.source.Vector', function() {
|
||||
expect(source.getFeatureByUid(uid)).to.be(null);
|
||||
});
|
||||
|
||||
it('returns null when no features are present', function() {
|
||||
it('returns null when no features are present', function () {
|
||||
expect(source.getFeatureByUid('abcd')).to.be(null);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#loadFeatures', function() {
|
||||
|
||||
describe('with the "bbox" strategy', function() {
|
||||
|
||||
|
||||
it('requests the view extent plus render buffer', function(done) {
|
||||
describe('#loadFeatures', function () {
|
||||
describe('with the "bbox" strategy', function () {
|
||||
it('requests the view extent plus render buffer', function (done) {
|
||||
const center = [-97.6114, 38.8403];
|
||||
const source = new VectorSource({
|
||||
strategy: bboxStrategy,
|
||||
loader: function(extent) {
|
||||
setTimeout(function() {
|
||||
const lonLatExtent = transformExtent(extent, 'EPSG:3857', 'EPSG:4326');
|
||||
loader: function (extent) {
|
||||
setTimeout(function () {
|
||||
const lonLatExtent = transformExtent(
|
||||
extent,
|
||||
'EPSG:3857',
|
||||
'EPSG:4326'
|
||||
);
|
||||
expect(lonLatExtent[0]).to.roughlyEqual(-99.259349218, 1e-9);
|
||||
expect(lonLatExtent[2]).to.roughlyEqual(-95.963450781, 1e-9);
|
||||
done();
|
||||
}, 0);
|
||||
}
|
||||
},
|
||||
});
|
||||
const div = document.createElement('div');
|
||||
div.style.width = '100px';
|
||||
@@ -600,79 +585,92 @@ describe('ol.source.Vector', function() {
|
||||
target: div,
|
||||
layers: [
|
||||
new VectorLayer({
|
||||
source: source
|
||||
})
|
||||
source: source,
|
||||
}),
|
||||
],
|
||||
view: new View({
|
||||
center: fromLonLat(center),
|
||||
zoom: 7
|
||||
})
|
||||
zoom: 7,
|
||||
}),
|
||||
});
|
||||
map.renderSync();
|
||||
map.setTarget(null);
|
||||
document.body.removeChild(div);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with no loader and the "all" strategy', function() {
|
||||
|
||||
it('stores the infinity extent in the Rtree', function() {
|
||||
describe('with no loader and the "all" strategy', function () {
|
||||
it('stores the infinity extent in the Rtree', function () {
|
||||
const source = new VectorSource();
|
||||
source.loadFeatures([-10000, -10000, 10000, 10000], 1,
|
||||
getProjection('EPSG:3857'));
|
||||
source.loadFeatures(
|
||||
[-10000, -10000, 10000, 10000],
|
||||
1,
|
||||
getProjection('EPSG:3857')
|
||||
);
|
||||
const loadedExtents = source.loadedExtentsRtree_.getAll();
|
||||
expect(loadedExtents).to.have.length(1);
|
||||
expect(loadedExtents[0].extent).to.eql(
|
||||
[-Infinity, -Infinity, Infinity, Infinity]);
|
||||
expect(loadedExtents[0].extent).to.eql([
|
||||
-Infinity,
|
||||
-Infinity,
|
||||
Infinity,
|
||||
Infinity,
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with setLoader', function() {
|
||||
|
||||
it('it will change the loader function', function() {
|
||||
describe('with setLoader', function () {
|
||||
it('it will change the loader function', function () {
|
||||
let count1 = 0;
|
||||
const loader1 = function(bbox, resolution, projection) {
|
||||
const loader1 = function (bbox, resolution, projection) {
|
||||
count1++;
|
||||
};
|
||||
let count2 = 0;
|
||||
const loader2 = function(bbox, resolution, projection) {
|
||||
const loader2 = function (bbox, resolution, projection) {
|
||||
count2++;
|
||||
};
|
||||
const source = new VectorSource({loader: loader1});
|
||||
source.loadFeatures([-10000, -10000, 10000, 10000], 1,
|
||||
getProjection('EPSG:3857'));
|
||||
source.loadFeatures(
|
||||
[-10000, -10000, 10000, 10000],
|
||||
1,
|
||||
getProjection('EPSG:3857')
|
||||
);
|
||||
source.setLoader(loader2);
|
||||
source.refresh();
|
||||
source.loadFeatures([-10000, -10000, 10000, 10000], 1,
|
||||
getProjection('EPSG:3857'));
|
||||
source.loadFeatures(
|
||||
[-10000, -10000, 10000, 10000],
|
||||
1,
|
||||
getProjection('EPSG:3857')
|
||||
);
|
||||
expect(count1).to.eql(1);
|
||||
expect(count2).to.eql(1);
|
||||
});
|
||||
|
||||
it('removes extents with #removeLoadedExtent()', function(done) {
|
||||
it('removes extents with #removeLoadedExtent()', function (done) {
|
||||
const source = new VectorSource();
|
||||
source.setLoader(function(bbox, resolution, projection) {
|
||||
setTimeout(function() {
|
||||
source.setLoader(function (bbox, resolution, projection) {
|
||||
setTimeout(function () {
|
||||
expect(source.loadedExtentsRtree_.getAll()).to.have.length(1);
|
||||
source.removeLoadedExtent(bbox);
|
||||
expect(source.loadedExtentsRtree_.getAll()).to.have.length(0);
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
source.loadFeatures([-10000, -10000, 10000, 10000], 1, getProjection('EPSG:3857'));
|
||||
source.loadFeatures(
|
||||
[-10000, -10000, 10000, 10000],
|
||||
1,
|
||||
getProjection('EPSG:3857')
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('the feature id index', function() {
|
||||
describe('the feature id index', function () {
|
||||
let source;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
source = new VectorSource();
|
||||
});
|
||||
|
||||
it('ignores features with the same id', function() {
|
||||
it('ignores features with the same id', function () {
|
||||
const feature = new Feature();
|
||||
feature.setId('foo');
|
||||
source.addFeature(feature);
|
||||
@@ -683,7 +681,7 @@ describe('ol.source.Vector', function() {
|
||||
expect(source.getFeatureById('foo')).to.be(feature);
|
||||
});
|
||||
|
||||
it('allows changing feature and set the same id', function() {
|
||||
it('allows changing feature and set the same id', function () {
|
||||
const foo = new Feature();
|
||||
foo.setId('foo');
|
||||
source.addFeature(foo);
|
||||
@@ -693,57 +691,55 @@ describe('ol.source.Vector', function() {
|
||||
bar.setId('foo');
|
||||
expect(source.getFeatureById('foo')).to.be(bar);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('the undefined feature id index', function() {
|
||||
describe('the undefined feature id index', function () {
|
||||
let source;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
source = new VectorSource();
|
||||
});
|
||||
|
||||
it('disallows adding the same feature twice', function() {
|
||||
it('disallows adding the same feature twice', function () {
|
||||
const feature = new Feature();
|
||||
source.addFeature(feature);
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
source.addFeature(feature);
|
||||
}).to.throwException();
|
||||
});
|
||||
});
|
||||
|
||||
describe('with useSpatialIndex set to false', function() {
|
||||
describe('with useSpatialIndex set to false', function () {
|
||||
let source;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
source = new VectorSource({useSpatialIndex: false});
|
||||
});
|
||||
|
||||
it('returns a features collection', function() {
|
||||
it('returns a features collection', function () {
|
||||
expect(source.getFeaturesCollection()).to.be.a(Collection);
|
||||
});
|
||||
|
||||
it('#forEachFeatureInExtent loops through all features', function() {
|
||||
it('#forEachFeatureInExtent loops through all features', function () {
|
||||
source.addFeatures([new Feature(), new Feature()]);
|
||||
const spy = sinon.spy();
|
||||
source.forEachFeatureInExtent([0, 0, 0, 0], spy);
|
||||
expect(spy.callCount).to.be(2);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with a collection of features', function() {
|
||||
describe('with a collection of features', function () {
|
||||
let collection, source;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
source = new VectorSource({
|
||||
useSpatialIndex: false
|
||||
useSpatialIndex: false,
|
||||
});
|
||||
collection = source.getFeaturesCollection();
|
||||
});
|
||||
|
||||
it('creates a features collection', function() {
|
||||
it('creates a features collection', function () {
|
||||
expect(source.getFeaturesCollection()).to.not.be(null);
|
||||
});
|
||||
|
||||
it('adding/removing features keeps the collection in sync', function() {
|
||||
it('adding/removing features keeps the collection in sync', function () {
|
||||
const feature = new Feature();
|
||||
source.addFeature(feature);
|
||||
expect(collection.getLength()).to.be(1);
|
||||
@@ -751,7 +747,7 @@ describe('ol.source.Vector', function() {
|
||||
expect(collection.getLength()).to.be(0);
|
||||
});
|
||||
|
||||
it('#clear() features keeps the collection in sync', function() {
|
||||
it('#clear() features keeps the collection in sync', function () {
|
||||
const feature = new Feature();
|
||||
source.addFeatures([feature]);
|
||||
expect(collection.getLength()).to.be(1);
|
||||
@@ -763,7 +759,7 @@ describe('ol.source.Vector', function() {
|
||||
expect(collection.getLength()).to.be(0);
|
||||
});
|
||||
|
||||
it('keeps the source\'s features in sync with the collection', function() {
|
||||
it("keeps the source's features in sync with the collection", function () {
|
||||
const feature = new Feature();
|
||||
collection.push(feature);
|
||||
expect(source.getFeatures().length).to.be(1);
|
||||
@@ -775,9 +771,9 @@ describe('ol.source.Vector', function() {
|
||||
expect(source.getFeatures().length).to.be(0);
|
||||
});
|
||||
|
||||
it('prevents adding two features with a duplicate id in the collection', function() {
|
||||
it('prevents adding two features with a duplicate id in the collection', function () {
|
||||
source = new VectorSource({
|
||||
features: new Collection()
|
||||
features: new Collection(),
|
||||
});
|
||||
const feature1 = new Feature();
|
||||
feature1.setId('1');
|
||||
@@ -790,20 +786,20 @@ describe('ol.source.Vector', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('with a collection of features plus spatial index', function() {
|
||||
describe('with a collection of features plus spatial index', function () {
|
||||
let collection, source;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
collection = new Collection();
|
||||
source = new VectorSource({
|
||||
features: collection
|
||||
features: collection,
|
||||
});
|
||||
});
|
||||
|
||||
it('#getFeaturesCollection returns the configured collection', function() {
|
||||
it('#getFeaturesCollection returns the configured collection', function () {
|
||||
expect(source.getFeaturesCollection()).to.equal(collection);
|
||||
});
|
||||
|
||||
it('adding/removing features keeps the collection in sync', function() {
|
||||
it('adding/removing features keeps the collection in sync', function () {
|
||||
const feature = new Feature();
|
||||
source.addFeature(feature);
|
||||
expect(collection.getLength()).to.be(1);
|
||||
@@ -811,7 +807,7 @@ describe('ol.source.Vector', function() {
|
||||
expect(collection.getLength()).to.be(0);
|
||||
});
|
||||
|
||||
it('#clear() features keeps the collection in sync', function() {
|
||||
it('#clear() features keeps the collection in sync', function () {
|
||||
const feature = new Feature();
|
||||
source.addFeatures([feature]);
|
||||
expect(collection.getLength()).to.be(1);
|
||||
@@ -823,7 +819,7 @@ describe('ol.source.Vector', function() {
|
||||
expect(collection.getLength()).to.be(0);
|
||||
});
|
||||
|
||||
it('keeps the source\'s features in sync with the collection', function() {
|
||||
it("keeps the source's features in sync with the collection", function () {
|
||||
const feature = new Feature();
|
||||
collection.push(feature);
|
||||
expect(source.getFeatures().length).to.be(1);
|
||||
@@ -834,7 +830,5 @@ describe('ol.source.Vector', function() {
|
||||
collection.clear();
|
||||
expect(source.getFeatures().length).to.be(0);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,73 +1,76 @@
|
||||
import Map from '../../../../src/ol/Map.js';
|
||||
import View from '../../../../src/ol/View.js';
|
||||
import VectorRenderTile from '../../../../src/ol/VectorRenderTile.js';
|
||||
import VectorTile from '../../../../src/ol/VectorTile.js';
|
||||
import Feature from '../../../../src/ol/Feature.js';
|
||||
import GeoJSON from '../../../../src/ol/format/GeoJSON.js';
|
||||
import MVT from '../../../../src/ol/format/MVT.js';
|
||||
import VectorTileLayer from '../../../../src/ol/layer/VectorTile.js';
|
||||
import {get as getProjection, get} from '../../../../src/ol/proj.js';
|
||||
import VectorTileSource from '../../../../src/ol/source/VectorTile.js';
|
||||
import {createXYZ} from '../../../../src/ol/tilegrid.js';
|
||||
import Map from '../../../../src/ol/Map.js';
|
||||
import TileGrid from '../../../../src/ol/tilegrid/TileGrid.js';
|
||||
import {listen, unlistenByKey} from '../../../../src/ol/events.js';
|
||||
import TileState from '../../../../src/ol/TileState.js';
|
||||
import {getCenter} from '../../../../src/ol/extent.js';
|
||||
import {unByKey} from '../../../../src/ol/Observable.js';
|
||||
import Feature from '../../../../src/ol/Feature.js';
|
||||
import VectorRenderTile from '../../../../src/ol/VectorRenderTile.js';
|
||||
import VectorTile from '../../../../src/ol/VectorTile.js';
|
||||
import VectorTileLayer from '../../../../src/ol/layer/VectorTile.js';
|
||||
import VectorTileSource from '../../../../src/ol/source/VectorTile.js';
|
||||
import View from '../../../../src/ol/View.js';
|
||||
import {createXYZ} from '../../../../src/ol/tilegrid.js';
|
||||
import {fromExtent} from '../../../../src/ol/geom/Polygon.js';
|
||||
import {get, get as getProjection} from '../../../../src/ol/proj.js';
|
||||
import {getCenter} from '../../../../src/ol/extent.js';
|
||||
import {listen, unlistenByKey} from '../../../../src/ol/events.js';
|
||||
import {unByKey} from '../../../../src/ol/Observable.js';
|
||||
|
||||
describe('ol.source.VectorTile', function() {
|
||||
|
||||
describe('ol.source.VectorTile', function () {
|
||||
let format, source;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
format = new MVT();
|
||||
source = new VectorTileSource({
|
||||
format: format,
|
||||
url: 'spec/ol/data/{z}-{x}-{y}.vector.pbf'
|
||||
url: 'spec/ol/data/{z}-{x}-{y}.vector.pbf',
|
||||
});
|
||||
});
|
||||
|
||||
describe('constructor', function() {
|
||||
it('sets the format on the instance', function() {
|
||||
describe('constructor', function () {
|
||||
it('sets the format on the instance', function () {
|
||||
expect(source.format_).to.equal(format);
|
||||
});
|
||||
|
||||
it('sets the default zDirection on the instance', function() {
|
||||
it('sets the default zDirection on the instance', function () {
|
||||
expect(source.zDirection).to.be(1);
|
||||
});
|
||||
|
||||
it('uses ol.VectorTile as default tileClass', function() {
|
||||
it('uses ol.VectorTile as default tileClass', function () {
|
||||
expect(source.tileClass).to.equal(VectorTile);
|
||||
});
|
||||
|
||||
it('creates a 512 XYZ tilegrid by default', function() {
|
||||
it('creates a 512 XYZ tilegrid by default', function () {
|
||||
const tileGrid = createXYZ({tileSize: 512});
|
||||
expect(source.tileGrid.tileSize_).to.equal(tileGrid.tileSize_);
|
||||
expect(source.tileGrid.extent_).to.equal(tileGrid.extent_);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getTile()', function() {
|
||||
|
||||
it('creates a tile with the correct tile class', function() {
|
||||
describe('#getTile()', function () {
|
||||
it('creates a tile with the correct tile class', function () {
|
||||
const tile = source.getTile(0, 0, 0, 1, getProjection('EPSG:3857'));
|
||||
expect(tile).to.be.a(VectorRenderTile);
|
||||
expect(tile.getTileCoord()).to.eql([0, 0, 0]);
|
||||
expect(source.getTile(0, 0, 0, 1, getProjection('EPSG:3857')))
|
||||
.to.equal(tile);
|
||||
expect(source.getTile(0, 0, 0, 1, getProjection('EPSG:3857'))).to.equal(
|
||||
tile
|
||||
);
|
||||
});
|
||||
|
||||
it('loads source tiles', function(done) {
|
||||
it('loads source tiles', function (done) {
|
||||
const source = new VectorTileSource({
|
||||
format: new GeoJSON(),
|
||||
url: 'spec/ol/data/point.json'
|
||||
url: 'spec/ol/data/point.json',
|
||||
});
|
||||
const tile = source.getTile(0, 0, 0, 1, source.getProjection());
|
||||
|
||||
tile.load();
|
||||
const key = listen(tile, 'change', function(e) {
|
||||
const key = listen(tile, 'change', function (e) {
|
||||
if (tile.getState() === TileState.LOADED) {
|
||||
const sourceTile = source.getSourceTiles(1, source.getProjection(), tile)[0];
|
||||
const sourceTile = source.getSourceTiles(
|
||||
1,
|
||||
source.getProjection(),
|
||||
tile
|
||||
)[0];
|
||||
expect(sourceTile.getFeatures().length).to.be.greaterThan(0);
|
||||
unlistenByKey(key);
|
||||
done();
|
||||
@@ -75,64 +78,70 @@ describe('ol.source.VectorTile', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('handles empty tiles', function() {
|
||||
it('handles empty tiles', function () {
|
||||
const source = new VectorTileSource({
|
||||
format: new GeoJSON(),
|
||||
url: ''
|
||||
url: '',
|
||||
});
|
||||
const tile = source.getTile(0, 0, 0, 1, source.getProjection());
|
||||
expect(tile.getState()).to.be(TileState.EMPTY);
|
||||
});
|
||||
|
||||
it('creates empty tiles outside the source extent', function() {
|
||||
it('creates empty tiles outside the source extent', function () {
|
||||
const fullExtent = get('EPSG:3857').getExtent();
|
||||
const source = new VectorTileSource({
|
||||
extent: [fullExtent[0], fullExtent[1], 0, 0]
|
||||
extent: [fullExtent[0], fullExtent[1], 0, 0],
|
||||
});
|
||||
const tile = source.getTile(1, 1, 1, 1, source.getProjection());
|
||||
expect(tile.getState()).to.be(TileState.EMPTY);
|
||||
});
|
||||
|
||||
it('creates empty tiles outside the world extent when wrapX === false', function() {
|
||||
it('creates empty tiles outside the world extent when wrapX === false', function () {
|
||||
const source = new VectorTileSource({
|
||||
wrapX: false
|
||||
wrapX: false,
|
||||
});
|
||||
const tile = source.getTile(0, -1, 0, 1, source.getProjection());
|
||||
expect(tile.getState()).to.be(TileState.EMPTY);
|
||||
});
|
||||
|
||||
it('creates empty tiles when the tileUrlFunction returns undefined', function() {
|
||||
it('creates empty tiles when the tileUrlFunction returns undefined', function () {
|
||||
const source = new VectorTileSource({
|
||||
tileUrlFunction: function(tileCoord) {
|
||||
tileUrlFunction: function (tileCoord) {
|
||||
return;
|
||||
}
|
||||
},
|
||||
});
|
||||
const tile = source.getTile(1, 1, 1, 1, source.getProjection());
|
||||
expect(tile.getState()).to.be(TileState.EMPTY);
|
||||
});
|
||||
|
||||
it('creates non-empty tiles outside the world extent when wrapX === true', function() {
|
||||
it('creates non-empty tiles outside the world extent when wrapX === true', function () {
|
||||
const source = new VectorTileSource({
|
||||
url: '{z}/{x}/{y}.pbf'
|
||||
url: '{z}/{x}/{y}.pbf',
|
||||
});
|
||||
const tile = source.getTile(0, -1, 0, 1, source.getProjection());
|
||||
expect(tile.getState()).to.be(TileState.IDLE);
|
||||
});
|
||||
|
||||
it('creates non-empty tiles for overzoomed resolutions', function() {
|
||||
it('creates non-empty tiles for overzoomed resolutions', function () {
|
||||
const source = new VectorTileSource({
|
||||
url: '{z}/{x}/{y}.pbf',
|
||||
tileLoadFunction: function(tile) {
|
||||
tile.setLoader(function() {});
|
||||
tileLoadFunction: function (tile) {
|
||||
tile.setLoader(function () {});
|
||||
},
|
||||
maxZoom: 16
|
||||
maxZoom: 16,
|
||||
});
|
||||
const tile = source.getTile(24, 9119385, 5820434, 1, source.getProjection());
|
||||
const tile = source.getTile(
|
||||
24,
|
||||
9119385,
|
||||
5820434,
|
||||
1,
|
||||
source.getProjection()
|
||||
);
|
||||
tile.load();
|
||||
expect(tile.getState()).to.be(TileState.LOADING);
|
||||
});
|
||||
|
||||
it('creates new tile when source key changes', function() {
|
||||
it('creates new tile when source key changes', function () {
|
||||
source.setKey('key1');
|
||||
const tile1 = source.getTile(0, 0, 0, 1, getProjection('EPSG:3857'));
|
||||
const tile2 = source.getTile(0, 0, 0, 1, getProjection('EPSG:3857'));
|
||||
@@ -142,24 +151,31 @@ describe('ol.source.VectorTile', function() {
|
||||
expect(tile1.key).to.be('key1');
|
||||
expect(tile3.key).to.be('key2');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getTileGridForProjection', function() {
|
||||
it('creates a tile grid with the source tile grid\'s tile size', function() {
|
||||
const tileGrid = source.getTileGridForProjection(getProjection('EPSG:3857'));
|
||||
describe('#getTileGridForProjection', function () {
|
||||
it("creates a tile grid with the source tile grid's tile size", function () {
|
||||
const tileGrid = source.getTileGridForProjection(
|
||||
getProjection('EPSG:3857')
|
||||
);
|
||||
expect(tileGrid.getTileSize(0)).to.be(512);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Tile load events', function() {
|
||||
it('triggers tileloadstart and tileloadend with ol.VectorTile', function(done) {
|
||||
const tile = source.getTile(14, 8938, 5680, 1, getProjection('EPSG:3857'));
|
||||
describe('Tile load events', function () {
|
||||
it('triggers tileloadstart and tileloadend with ol.VectorTile', function (done) {
|
||||
const tile = source.getTile(
|
||||
14,
|
||||
8938,
|
||||
5680,
|
||||
1,
|
||||
getProjection('EPSG:3857')
|
||||
);
|
||||
let started = false;
|
||||
source.on('tileloadstart', function() {
|
||||
source.on('tileloadstart', function () {
|
||||
started = true;
|
||||
});
|
||||
source.on('tileloadend', function(e) {
|
||||
source.on('tileloadend', function (e) {
|
||||
expect(started).to.be(true);
|
||||
expect(e.tile).to.be.a(VectorTile);
|
||||
expect(e.tile.getFeatures().length).to.be(1327);
|
||||
@@ -169,12 +185,10 @@ describe('ol.source.VectorTile', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('different source and render tile grids', function() {
|
||||
|
||||
describe('different source and render tile grids', function () {
|
||||
let source, map, loaded, requested, target;
|
||||
|
||||
beforeEach(function() {
|
||||
|
||||
beforeEach(function () {
|
||||
loaded = [];
|
||||
requested = 0;
|
||||
|
||||
@@ -186,19 +200,39 @@ describe('ol.source.VectorTile', function() {
|
||||
}
|
||||
|
||||
function tileLoadFunction(tile, src) {
|
||||
tile.setLoader(function() {});
|
||||
tile.setLoader(function () {});
|
||||
loaded.push(src);
|
||||
}
|
||||
|
||||
const extent = [665584.2026596286, 7033250.839875697, 667162.0221431496, 7035280.378636755];
|
||||
const extent = [
|
||||
665584.2026596286,
|
||||
7033250.839875697,
|
||||
667162.0221431496,
|
||||
7035280.378636755,
|
||||
];
|
||||
|
||||
source = new VectorTileSource({
|
||||
tileGrid: new TileGrid({
|
||||
origin: [218128, 6126002],
|
||||
resolutions: [4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 0.5]
|
||||
resolutions: [
|
||||
4096,
|
||||
2048,
|
||||
1024,
|
||||
512,
|
||||
256,
|
||||
128,
|
||||
64,
|
||||
32,
|
||||
16,
|
||||
8,
|
||||
4,
|
||||
2,
|
||||
1,
|
||||
0.5,
|
||||
],
|
||||
}),
|
||||
tileUrlFunction: tileUrlFunction,
|
||||
tileLoadFunction: tileLoadFunction
|
||||
tileLoadFunction: tileLoadFunction,
|
||||
});
|
||||
|
||||
target = document.createElement('div');
|
||||
@@ -210,34 +244,32 @@ describe('ol.source.VectorTile', function() {
|
||||
layers: [
|
||||
new VectorTileLayer({
|
||||
extent: extent,
|
||||
source: source
|
||||
})
|
||||
source: source,
|
||||
}),
|
||||
],
|
||||
target: target,
|
||||
view: new View({
|
||||
zoom: 11,
|
||||
center: [666373.1624999996, 7034265.3572]
|
||||
})
|
||||
center: [666373.1624999996, 7034265.3572],
|
||||
}),
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
document.body.removeChild(target);
|
||||
});
|
||||
|
||||
it('loads available tiles', function(done) {
|
||||
it('loads available tiles', function (done) {
|
||||
map.renderSync();
|
||||
setTimeout(function() {
|
||||
setTimeout(function () {
|
||||
expect(requested).to.be.greaterThan(1);
|
||||
expect(loaded).to.eql(['5/13/-29']);
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('does not fill up the tile queue', function(done) {
|
||||
it('does not fill up the tile queue', function (done) {
|
||||
const target = document.createElement('div');
|
||||
target.style.width = '100px';
|
||||
target.style.height = '100px';
|
||||
@@ -247,29 +279,28 @@ describe('ol.source.VectorTile', function() {
|
||||
'spec/ol/data/14-8938-5680.vector.pbf?num=0&coord={z},{x},{y}',
|
||||
'spec/ol/data/14-8938-5680.vector.pbf?num=1&coord={z},{x},{y}',
|
||||
'spec/ol/data/14-8938-5680.vector.pbf?num=2&coord={z},{x},{y}',
|
||||
'spec/ol/data/14-8938-5680.vector.pbf?num=3&coord={z},{x},{y}'
|
||||
'spec/ol/data/14-8938-5680.vector.pbf?num=3&coord={z},{x},{y}',
|
||||
];
|
||||
|
||||
const source = new VectorTileSource({
|
||||
format: new MVT(),
|
||||
url: urls[0]
|
||||
url: urls[0],
|
||||
});
|
||||
|
||||
const map = new Map({
|
||||
target: target,
|
||||
layers: [
|
||||
new VectorTileLayer({
|
||||
source: source
|
||||
})
|
||||
source: source,
|
||||
}),
|
||||
],
|
||||
view: new View({
|
||||
center: [0, 0],
|
||||
zoom: 0
|
||||
})
|
||||
zoom: 0,
|
||||
}),
|
||||
});
|
||||
map.renderSync();
|
||||
|
||||
|
||||
const max = urls.length + 3;
|
||||
let count = 0;
|
||||
let tile = source.getTile(0, 0, 0, 1, map.getView().getProjection());
|
||||
@@ -279,7 +310,7 @@ describe('ol.source.VectorTile', function() {
|
||||
}
|
||||
e.target.removeEventListener('change', onTileChange);
|
||||
|
||||
map.once('rendercomplete', function() {
|
||||
map.once('rendercomplete', function () {
|
||||
expect(map.tileQueue_.getTilesLoading()).to.be(0);
|
||||
|
||||
++count;
|
||||
@@ -294,26 +325,28 @@ describe('ol.source.VectorTile', function() {
|
||||
tile = source.getTile(0, 0, 0, 1, map.getView().getProjection());
|
||||
tile.addEventListener('change', onTileChange);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('interim tile handling', function() {
|
||||
|
||||
describe('interim tile handling', function () {
|
||||
let map, source, target;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
target = document.createElement('div');
|
||||
target.style.width = '100px';
|
||||
target.style.height = '100px';
|
||||
document.body.appendChild(target);
|
||||
const extent = [1824704.739223726, 6141868.096770482, 1827150.7241288517, 6144314.081675608];
|
||||
const extent = [
|
||||
1824704.739223726,
|
||||
6141868.096770482,
|
||||
1827150.7241288517,
|
||||
6144314.081675608,
|
||||
];
|
||||
source = new VectorTileSource({
|
||||
format: new MVT(),
|
||||
url: 'spec/ol/data/14-8938-5680.vector.pbf',
|
||||
minZoom: 14,
|
||||
maxZoom: 14
|
||||
maxZoom: 14,
|
||||
});
|
||||
map = new Map({
|
||||
pixelRatio: 1,
|
||||
@@ -321,31 +354,47 @@ describe('ol.source.VectorTile', function() {
|
||||
layers: [
|
||||
new VectorTileLayer({
|
||||
extent: extent,
|
||||
source: source
|
||||
})
|
||||
source: source,
|
||||
}),
|
||||
],
|
||||
view: new View({
|
||||
center: getCenter(extent),
|
||||
zoom: 15
|
||||
})
|
||||
zoom: 15,
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
map.setTarget(null);
|
||||
document.body.removeChild(target);
|
||||
});
|
||||
|
||||
it('re-renders when source changes', function(done) {
|
||||
map.once('rendercomplete', function() {
|
||||
const key = map.on('rendercomplete', function() {
|
||||
const tile = source.getTile(14, 8938, 5680, 1, map.getView().getProjection());
|
||||
expect(tile.getKey()).to.be('spec/ol/data/14-8938-5680.vector.pbf?new/14,8938,5680');
|
||||
it('re-renders when source changes', function (done) {
|
||||
map.once('rendercomplete', function () {
|
||||
const key = map.on('rendercomplete', function () {
|
||||
const tile = source.getTile(
|
||||
14,
|
||||
8938,
|
||||
5680,
|
||||
1,
|
||||
map.getView().getProjection()
|
||||
);
|
||||
expect(tile.getKey()).to.be(
|
||||
'spec/ol/data/14-8938-5680.vector.pbf?new/14,8938,5680'
|
||||
);
|
||||
expect(tile.interimTile).to.be.a(VectorRenderTile);
|
||||
expect(tile.interimTile.getKey()).to.be('spec/ol/data/14-8938-5680.vector.pbf/14,8938,5680');
|
||||
const sourceTiles = source.getSourceTiles(1, map.getView().getProjection(), tile);
|
||||
expect(tile.interimTile.getKey()).to.be(
|
||||
'spec/ol/data/14-8938-5680.vector.pbf/14,8938,5680'
|
||||
);
|
||||
const sourceTiles = source.getSourceTiles(
|
||||
1,
|
||||
map.getView().getProjection(),
|
||||
tile
|
||||
);
|
||||
if (sourceTiles) {
|
||||
expect(sourceTiles[0].getKey()).to.be('spec/ol/data/14-8938-5680.vector.pbf?new');
|
||||
expect(sourceTiles[0].getKey()).to.be(
|
||||
'spec/ol/data/14-8938-5680.vector.pbf?new'
|
||||
);
|
||||
unByKey(key);
|
||||
done();
|
||||
}
|
||||
@@ -353,24 +402,24 @@ describe('ol.source.VectorTile', function() {
|
||||
source.setUrl('spec/ol/data/14-8938-5680.vector.pbf?new');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('getFeatuersInExtent', function() {
|
||||
|
||||
describe('getFeatuersInExtent', function () {
|
||||
let map, source, target;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
source = new VectorTileSource({
|
||||
maxZoom: 15,
|
||||
tileSize: 256,
|
||||
url: '{z}/{x}/{y}',
|
||||
tileLoadFunction: function(tile) {
|
||||
const extent = source.getTileGrid().getTileCoordExtent(tile.tileCoord);
|
||||
tileLoadFunction: function (tile) {
|
||||
const extent = source
|
||||
.getTileGrid()
|
||||
.getTileCoordExtent(tile.tileCoord);
|
||||
const feature = new Feature(fromExtent(extent));
|
||||
feature.set('z', tile.tileCoord[0]);
|
||||
tile.setFeatures([feature]);
|
||||
}
|
||||
},
|
||||
});
|
||||
target = document.createElement('div');
|
||||
target.style.width = '100px';
|
||||
@@ -380,36 +429,36 @@ describe('ol.source.VectorTile', function() {
|
||||
target: target,
|
||||
layers: [
|
||||
new VectorTileLayer({
|
||||
source: source
|
||||
})
|
||||
source: source,
|
||||
}),
|
||||
],
|
||||
view: new View({
|
||||
center: [0, 0],
|
||||
zoom: 0
|
||||
})
|
||||
zoom: 0,
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
map.setTarget(null);
|
||||
document.body.removeChild(target);
|
||||
});
|
||||
|
||||
it('returns an empty array when no tiles are in the cache', function() {
|
||||
it('returns an empty array when no tiles are in the cache', function () {
|
||||
source.tileCache.clear();
|
||||
const extent = map.getView().calculateExtent(map.getSize());
|
||||
expect(source.getFeaturesInExtent(extent).length).to.be(0);
|
||||
});
|
||||
|
||||
it('returns features in extent for the last rendered z', function(done) {
|
||||
it('returns features in extent for the last rendered z', function (done) {
|
||||
map.getView().setZoom(15);
|
||||
map.once('rendercomplete', function() {
|
||||
map.once('rendercomplete', function () {
|
||||
const extent = map.getView().calculateExtent(map.getSize());
|
||||
const features = source.getFeaturesInExtent(extent);
|
||||
expect(features.length).to.be(4);
|
||||
expect(features[0].get('z')).to.be(15);
|
||||
map.getView().setZoom(0);
|
||||
map.once('rendercomplete', function() {
|
||||
map.once('rendercomplete', function () {
|
||||
const extent = map.getView().calculateExtent(map.getSize());
|
||||
const features = source.getFeaturesInExtent(extent);
|
||||
expect(features.length).to.be(1);
|
||||
@@ -419,5 +468,4 @@ describe('ol.source.VectorTile', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
import Projection from '../../../../src/ol/proj/Projection.js';
|
||||
import WMTS, {optionsFromCapabilities} from '../../../../src/ol/source/WMTS.js';
|
||||
import WMTSCapabilities from '../../../../src/ol/format/WMTSCapabilities.js';
|
||||
import WMTSTileGrid from '../../../../src/ol/tilegrid/WMTS.js';
|
||||
import {getBottomLeft, getTopRight} from '../../../../src/ol/extent.js';
|
||||
import {get as getProjection} from '../../../../src/ol/proj.js';
|
||||
import Projection from '../../../../src/ol/proj/Projection.js';
|
||||
import WMTSTileGrid from '../../../../src/ol/tilegrid/WMTS.js';
|
||||
import WMTS, {optionsFromCapabilities} from '../../../../src/ol/source/WMTS.js';
|
||||
|
||||
|
||||
describe('ol.source.WMTS', function() {
|
||||
|
||||
describe('when creating options from capabilities', function() {
|
||||
describe('ol.source.WMTS', function () {
|
||||
describe('when creating options from capabilities', function () {
|
||||
const parser = new WMTSCapabilities();
|
||||
let capabilities, content;
|
||||
before(function(done) {
|
||||
afterLoadText('spec/ol/format/wmts/ogcsample.xml', function(xml) {
|
||||
before(function (done) {
|
||||
afterLoadText('spec/ol/format/wmts/ogcsample.xml', function (xml) {
|
||||
try {
|
||||
content = xml;
|
||||
capabilities = parser.read(xml);
|
||||
@@ -23,136 +21,141 @@ describe('ol.source.WMTS', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('returns null if the layer was not found in the capabilities', function() {
|
||||
it('returns null if the layer was not found in the capabilities', function () {
|
||||
const options = optionsFromCapabilities(capabilities, {
|
||||
layer: 'invalid'
|
||||
layer: 'invalid',
|
||||
});
|
||||
|
||||
expect(options).to.be(null);
|
||||
});
|
||||
|
||||
it('passes the crossOrigin option', function() {
|
||||
it('passes the crossOrigin option', function () {
|
||||
const options = optionsFromCapabilities(capabilities, {
|
||||
layer: 'BlueMarbleNextGeneration',
|
||||
matrixSet: 'google3857',
|
||||
crossOrigin: ''
|
||||
crossOrigin: '',
|
||||
});
|
||||
|
||||
expect(options.crossOrigin).to.be.eql('');
|
||||
});
|
||||
|
||||
it('can create KVP options from spec/ol/format/wmts/ogcsample.xml',
|
||||
function() {
|
||||
const options = optionsFromCapabilities(
|
||||
capabilities,
|
||||
{layer: 'BlueMarbleNextGeneration', matrixSet: 'google3857'});
|
||||
|
||||
expect(options.urls).to.be.an('array');
|
||||
expect(options.urls).to.have.length(1);
|
||||
expect(options.urls[0]).to.be.eql(
|
||||
'http://www.maps.bob/cgi-bin/MiraMon5_0.cgi?');
|
||||
|
||||
expect(options.layer).to.be.eql('BlueMarbleNextGeneration');
|
||||
|
||||
expect(options.matrixSet).to.be.eql('google3857');
|
||||
|
||||
expect(options.format).to.be.eql('image/jpeg');
|
||||
|
||||
expect(options.projection).to.be.a(Projection);
|
||||
expect(options.projection).to.be.eql(getProjection('EPSG:3857'));
|
||||
|
||||
expect(options.requestEncoding).to.be.eql('KVP');
|
||||
|
||||
expect(options.tileGrid).to.be.a(WMTSTileGrid);
|
||||
|
||||
expect(options.style).to.be.eql('DarkBlue');
|
||||
|
||||
expect(options.dimensions).to.eql({Time: '20110805'});
|
||||
|
||||
expect(options.crossOrigin).to.be(undefined);
|
||||
|
||||
it('can create KVP options from spec/ol/format/wmts/ogcsample.xml', function () {
|
||||
const options = optionsFromCapabilities(capabilities, {
|
||||
layer: 'BlueMarbleNextGeneration',
|
||||
matrixSet: 'google3857',
|
||||
});
|
||||
|
||||
it('can create REST options from spec/ol/format/wmts/ogcsample.xml',
|
||||
function() {
|
||||
const options = optionsFromCapabilities(capabilities, {
|
||||
layer: 'BlueMarbleNextGeneration',
|
||||
matrixSet: 'google3857',
|
||||
requestEncoding: 'REST'
|
||||
});
|
||||
expect(options.urls).to.be.an('array');
|
||||
expect(options.urls).to.have.length(1);
|
||||
expect(options.urls[0]).to.be.eql(
|
||||
'http://www.maps.bob/cgi-bin/MiraMon5_0.cgi?'
|
||||
);
|
||||
|
||||
expect(options.urls).to.be.an('array');
|
||||
expect(options.urls).to.have.length(1);
|
||||
expect(options.urls[0]).to.be.eql(
|
||||
'http://www.example.com/wmts/coastlines/{TileMatrix}/{TileRow}/{TileCol}.png');
|
||||
expect(options.layer).to.be.eql('BlueMarbleNextGeneration');
|
||||
|
||||
expect(options.layer).to.be.eql('BlueMarbleNextGeneration');
|
||||
expect(options.matrixSet).to.be.eql('google3857');
|
||||
|
||||
expect(options.matrixSet).to.be.eql('google3857');
|
||||
expect(options.format).to.be.eql('image/jpeg');
|
||||
|
||||
expect(options.format).to.be.eql('image/png');
|
||||
expect(options.projection).to.be.a(Projection);
|
||||
expect(options.projection).to.be.eql(getProjection('EPSG:3857'));
|
||||
|
||||
expect(options.projection).to.be.a(Projection);
|
||||
expect(options.projection).to.be.eql(getProjection('EPSG:3857'));
|
||||
expect(options.requestEncoding).to.be.eql('KVP');
|
||||
|
||||
expect(options.requestEncoding).to.be.eql('REST');
|
||||
expect(options.tileGrid).to.be.a(WMTSTileGrid);
|
||||
|
||||
expect(options.tileGrid).to.be.a(WMTSTileGrid);
|
||||
expect(options.style).to.be.eql('DarkBlue');
|
||||
|
||||
expect(options.style).to.be.eql('DarkBlue');
|
||||
expect(options.dimensions).to.eql({Time: '20110805'});
|
||||
|
||||
expect(options.dimensions).to.eql({Time: '20110805'});
|
||||
expect(options.crossOrigin).to.be(undefined);
|
||||
});
|
||||
|
||||
it('can create REST options from spec/ol/format/wmts/ogcsample.xml', function () {
|
||||
const options = optionsFromCapabilities(capabilities, {
|
||||
layer: 'BlueMarbleNextGeneration',
|
||||
matrixSet: 'google3857',
|
||||
requestEncoding: 'REST',
|
||||
});
|
||||
|
||||
it('can find a MatrixSet by SRS identifier', function() {
|
||||
expect(options.urls).to.be.an('array');
|
||||
expect(options.urls).to.have.length(1);
|
||||
expect(options.urls[0]).to.be.eql(
|
||||
'http://www.example.com/wmts/coastlines/{TileMatrix}/{TileRow}/{TileCol}.png'
|
||||
);
|
||||
|
||||
expect(options.layer).to.be.eql('BlueMarbleNextGeneration');
|
||||
|
||||
expect(options.matrixSet).to.be.eql('google3857');
|
||||
|
||||
expect(options.format).to.be.eql('image/png');
|
||||
|
||||
expect(options.projection).to.be.a(Projection);
|
||||
expect(options.projection).to.be.eql(getProjection('EPSG:3857'));
|
||||
|
||||
expect(options.requestEncoding).to.be.eql('REST');
|
||||
|
||||
expect(options.tileGrid).to.be.a(WMTSTileGrid);
|
||||
|
||||
expect(options.style).to.be.eql('DarkBlue');
|
||||
|
||||
expect(options.dimensions).to.eql({Time: '20110805'});
|
||||
});
|
||||
|
||||
it('can find a MatrixSet by SRS identifier', function () {
|
||||
const options = optionsFromCapabilities(capabilities, {
|
||||
layer: 'BlueMarbleNextGeneration',
|
||||
projection: 'EPSG:3857',
|
||||
requestEncoding: 'REST'
|
||||
requestEncoding: 'REST',
|
||||
});
|
||||
|
||||
expect(options.matrixSet).to.be.eql('google3857');
|
||||
expect(options.projection.getCode()).to.be.eql('EPSG:3857');
|
||||
});
|
||||
|
||||
it('can find a MatrixSet by equivalent SRS identifier', function() {
|
||||
it('can find a MatrixSet by equivalent SRS identifier', function () {
|
||||
const options = optionsFromCapabilities(capabilities, {
|
||||
layer: 'BlueMarbleNextGeneration',
|
||||
projection: 'EPSG:900913',
|
||||
requestEncoding: 'REST'
|
||||
requestEncoding: 'REST',
|
||||
});
|
||||
|
||||
expect(options.matrixSet).to.be.eql('google3857');
|
||||
expect(options.projection.getCode()).to.be.eql('EPSG:900913');
|
||||
});
|
||||
|
||||
it('can find the default MatrixSet', function() {
|
||||
it('can find the default MatrixSet', function () {
|
||||
const options = optionsFromCapabilities(capabilities, {
|
||||
layer: 'BlueMarbleNextGeneration',
|
||||
requestEncoding: 'REST'
|
||||
requestEncoding: 'REST',
|
||||
});
|
||||
|
||||
expect(options.matrixSet).to.be.eql('BigWorldPixel');
|
||||
expect(options.projection.getCode()).to.be.eql('urn:ogc:def:crs:OGC:1.3:CRS84');
|
||||
expect(options.projection.getCode()).to.be.eql(
|
||||
'urn:ogc:def:crs:OGC:1.3:CRS84'
|
||||
);
|
||||
});
|
||||
|
||||
it('uses the projection of the default MatrixSet if the config\'s projection is not supported', function() {
|
||||
it("uses the projection of the default MatrixSet if the config's projection is not supported", function () {
|
||||
const options = optionsFromCapabilities(capabilities, {
|
||||
layer: 'BlueMarbleNextGeneration',
|
||||
projection: new Projection({
|
||||
code: 'EPSG:2056',
|
||||
units: 'm'
|
||||
})
|
||||
units: 'm',
|
||||
}),
|
||||
});
|
||||
|
||||
expect(options.matrixSet).to.be.eql('BigWorldPixel');
|
||||
expect(options.projection.getCode()).to.be.eql('urn:ogc:def:crs:OGC:1.3:CRS84');
|
||||
expect(options.projection.getCode()).to.be.eql(
|
||||
'urn:ogc:def:crs:OGC:1.3:CRS84'
|
||||
);
|
||||
});
|
||||
|
||||
it('uses extent of tile matrix instead of projection extent', function() {
|
||||
const options = optionsFromCapabilities(capabilities,
|
||||
{layer: 'BlueMarbleNextGeneration', matrixSet: 'google3857subset'});
|
||||
it('uses extent of tile matrix instead of projection extent', function () {
|
||||
const options = optionsFromCapabilities(capabilities, {
|
||||
layer: 'BlueMarbleNextGeneration',
|
||||
matrixSet: 'google3857subset',
|
||||
});
|
||||
|
||||
// Since google3857subset defines subset of space defined by the google3857 matrix set:
|
||||
// - top left corner: -10000000, 10000000
|
||||
@@ -176,100 +179,136 @@ describe('ol.source.WMTS', function() {
|
||||
expect(Math.round(projTopRight[1])).to.be.eql(20037508);
|
||||
});
|
||||
|
||||
it('doesn\'t fail if the GetCap doesn\'t contains Constraint tags', function() {
|
||||
const tmpXml = content.replace(/<ows:Constraint[\s\S]*?<\/ows:Constraint>/g, '');
|
||||
it("doesn't fail if the GetCap doesn't contains Constraint tags", function () {
|
||||
const tmpXml = content.replace(
|
||||
/<ows:Constraint[\s\S]*?<\/ows:Constraint>/g,
|
||||
''
|
||||
);
|
||||
const tmpCapabilities = parser.read(tmpXml);
|
||||
expect(tmpCapabilities['OperationsMetadata']['GetTile']['DCP']['HTTP']['Get'][0]['Constraint']).to.be(undefined);
|
||||
const options = optionsFromCapabilities(tmpCapabilities,
|
||||
{layer: 'BlueMarbleNextGeneration', matrixSet: 'google3857'});
|
||||
expect(
|
||||
tmpCapabilities['OperationsMetadata']['GetTile']['DCP']['HTTP'][
|
||||
'Get'
|
||||
][0]['Constraint']
|
||||
).to.be(undefined);
|
||||
const options = optionsFromCapabilities(tmpCapabilities, {
|
||||
layer: 'BlueMarbleNextGeneration',
|
||||
matrixSet: 'google3857',
|
||||
});
|
||||
expect(options.layer).to.be.eql('BlueMarbleNextGeneration');
|
||||
expect(options.matrixSet).to.be.eql('google3857');
|
||||
});
|
||||
|
||||
it('set KVP as default request encoding if the GetCap doesn\'t contains Constraint and ResourceUrl tags', function() {
|
||||
let tmpXml = content.replace(/<ows:Constraint[\s\S]*?<\/ows:Constraint>/g, '');
|
||||
it("set KVP as default request encoding if the GetCap doesn't contains Constraint and ResourceUrl tags", function () {
|
||||
let tmpXml = content.replace(
|
||||
/<ows:Constraint[\s\S]*?<\/ows:Constraint>/g,
|
||||
''
|
||||
);
|
||||
tmpXml = tmpXml.replace(/<ResourceURL[\s\S]*?"\/>/g, '');
|
||||
|
||||
const tmpCapabilities = parser.read(tmpXml);
|
||||
expect(tmpCapabilities['OperationsMetadata']['GetTile']['DCP']['HTTP']['Get'][0]['Constraint']).to.be(undefined);
|
||||
expect(tmpCapabilities['Contents']['Layer'][0]['ResourceURL']).to.be(undefined);
|
||||
const options = optionsFromCapabilities(tmpCapabilities,
|
||||
{layer: 'BlueMarbleNextGeneration', matrixSet: 'google3857'});
|
||||
expect(
|
||||
tmpCapabilities['OperationsMetadata']['GetTile']['DCP']['HTTP'][
|
||||
'Get'
|
||||
][0]['Constraint']
|
||||
).to.be(undefined);
|
||||
expect(tmpCapabilities['Contents']['Layer'][0]['ResourceURL']).to.be(
|
||||
undefined
|
||||
);
|
||||
const options = optionsFromCapabilities(tmpCapabilities, {
|
||||
layer: 'BlueMarbleNextGeneration',
|
||||
matrixSet: 'google3857',
|
||||
});
|
||||
expect(options.layer).to.be.eql('BlueMarbleNextGeneration');
|
||||
expect(options.matrixSet).to.be.eql('google3857');
|
||||
expect(options.urls).to.be.an('array');
|
||||
expect(options.urls).to.have.length(1);
|
||||
expect(options.urls[0]).to.be.eql('http://www.maps.bob/cgi-bin/MiraMon5_0.cgi?');
|
||||
expect(options.urls[0]).to.be.eql(
|
||||
'http://www.maps.bob/cgi-bin/MiraMon5_0.cgi?'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when creating tileUrlFunction', function() {
|
||||
describe('when creating tileUrlFunction', function () {
|
||||
const defaultTileGrid = new WMTSTileGrid({
|
||||
origin: [-20037508.342789244, 20037508.342789244],
|
||||
resolutions: [559082264.029 * 0.28E-3,
|
||||
279541132.015 * 0.28E-3,
|
||||
139770566.007 * 0.28E-3],
|
||||
matrixIds: [0, 1, 2]
|
||||
resolutions: [
|
||||
559082264.029 * 0.28e-3,
|
||||
279541132.015 * 0.28e-3,
|
||||
139770566.007 * 0.28e-3,
|
||||
],
|
||||
matrixIds: [0, 1, 2],
|
||||
});
|
||||
|
||||
it('can replace lowercase REST parameters',
|
||||
function() {
|
||||
const source = new WMTS({
|
||||
layer: 'layer',
|
||||
style: 'default',
|
||||
urls: ['http://host/{layer}/{style}/{tilematrixset}/{TileMatrix}/{TileCol}/{TileRow}.jpg'],
|
||||
matrixSet: 'EPSG:3857',
|
||||
requestEncoding: 'REST',
|
||||
tileGrid: defaultTileGrid
|
||||
});
|
||||
|
||||
const projection = getProjection('EPSG:3857');
|
||||
const url = source.tileUrlFunction(
|
||||
source.getTileCoordForTileUrlFunction([1, 1, 1]), 1, projection);
|
||||
expect(url).to.be.eql('http://host/layer/default/EPSG:3857/1/1/1.jpg');
|
||||
it('can replace lowercase REST parameters', function () {
|
||||
const source = new WMTS({
|
||||
layer: 'layer',
|
||||
style: 'default',
|
||||
urls: [
|
||||
'http://host/{layer}/{style}/{tilematrixset}/{TileMatrix}/{TileCol}/{TileRow}.jpg',
|
||||
],
|
||||
matrixSet: 'EPSG:3857',
|
||||
requestEncoding: 'REST',
|
||||
tileGrid: defaultTileGrid,
|
||||
});
|
||||
|
||||
it('can replace camelcase REST parameters',
|
||||
function() {
|
||||
const source = new WMTS({
|
||||
layer: 'layer',
|
||||
style: 'default',
|
||||
urls: ['http://host/{Layer}/{Style}/{tilematrixset}/{TileMatrix}/{TileCol}/{TileRow}.jpg'],
|
||||
matrixSet: 'EPSG:3857',
|
||||
requestEncoding: 'REST',
|
||||
tileGrid: defaultTileGrid
|
||||
});
|
||||
const projection = getProjection('EPSG:3857');
|
||||
const url = source.tileUrlFunction(
|
||||
source.getTileCoordForTileUrlFunction([1, 1, 1]),
|
||||
1,
|
||||
projection
|
||||
);
|
||||
expect(url).to.be.eql('http://host/layer/default/EPSG:3857/1/1/1.jpg');
|
||||
});
|
||||
|
||||
const projection = getProjection('EPSG:3857');
|
||||
const url = source.tileUrlFunction(
|
||||
source.getTileCoordForTileUrlFunction([1, 1, 1]), 1, projection);
|
||||
expect(url).to.be.eql('http://host/layer/default/EPSG:3857/1/1/1.jpg');
|
||||
it('can replace camelcase REST parameters', function () {
|
||||
const source = new WMTS({
|
||||
layer: 'layer',
|
||||
style: 'default',
|
||||
urls: [
|
||||
'http://host/{Layer}/{Style}/{tilematrixset}/{TileMatrix}/{TileCol}/{TileRow}.jpg',
|
||||
],
|
||||
matrixSet: 'EPSG:3857',
|
||||
requestEncoding: 'REST',
|
||||
tileGrid: defaultTileGrid,
|
||||
});
|
||||
|
||||
it('can replace dimensions',
|
||||
function() {
|
||||
const source = new WMTS({
|
||||
layer: 'layer',
|
||||
style: 'default',
|
||||
dimensions: {'Time': 42},
|
||||
urls: ['http://host/{Layer}/{Style}/{Time}/{tilematrixset}/{TileMatrix}/{TileCol}/{TileRow}.jpg'],
|
||||
matrixSet: 'EPSG:3857',
|
||||
requestEncoding: 'REST',
|
||||
tileGrid: defaultTileGrid
|
||||
});
|
||||
const projection = getProjection('EPSG:3857');
|
||||
const url = source.tileUrlFunction(
|
||||
source.getTileCoordForTileUrlFunction([1, 1, 1]),
|
||||
1,
|
||||
projection
|
||||
);
|
||||
expect(url).to.be.eql('http://host/layer/default/EPSG:3857/1/1/1.jpg');
|
||||
});
|
||||
|
||||
const projection = getProjection('EPSG:3857');
|
||||
const url = source.tileUrlFunction(
|
||||
source.getTileCoordForTileUrlFunction([1, 1, 1]), 1, projection);
|
||||
expect(url).to.be.eql('http://host/layer/default/42/EPSG:3857/1/1/1.jpg');
|
||||
it('can replace dimensions', function () {
|
||||
const source = new WMTS({
|
||||
layer: 'layer',
|
||||
style: 'default',
|
||||
dimensions: {'Time': 42},
|
||||
urls: [
|
||||
'http://host/{Layer}/{Style}/{Time}/{tilematrixset}/{TileMatrix}/{TileCol}/{TileRow}.jpg',
|
||||
],
|
||||
matrixSet: 'EPSG:3857',
|
||||
requestEncoding: 'REST',
|
||||
tileGrid: defaultTileGrid,
|
||||
});
|
||||
|
||||
const projection = getProjection('EPSG:3857');
|
||||
const url = source.tileUrlFunction(
|
||||
source.getTileCoordForTileUrlFunction([1, 1, 1]),
|
||||
1,
|
||||
projection
|
||||
);
|
||||
expect(url).to.be.eql('http://host/layer/default/42/EPSG:3857/1/1/1.jpg');
|
||||
});
|
||||
});
|
||||
|
||||
describe('when creating options from Esri capabilities', function() {
|
||||
describe('when creating options from Esri capabilities', function () {
|
||||
const parser = new WMTSCapabilities();
|
||||
let capabilities;
|
||||
before(function(done) {
|
||||
afterLoadText('spec/ol/format/wmts/arcgis.xml', function(xml) {
|
||||
before(function (done) {
|
||||
afterLoadText('spec/ol/format/wmts/arcgis.xml', function (xml) {
|
||||
try {
|
||||
capabilities = parser.read(xml);
|
||||
} catch (e) {
|
||||
@@ -279,86 +318,84 @@ describe('ol.source.WMTS', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('can create KVP options from spec/ol/format/wmts/arcgis.xml',
|
||||
function() {
|
||||
const options = optionsFromCapabilities(
|
||||
capabilities, {
|
||||
layer: 'Demographics_USA_Population_Density',
|
||||
requestEncoding: 'KVP',
|
||||
matrixSet: 'default028mm'
|
||||
});
|
||||
|
||||
expect(options.urls).to.be.an('array');
|
||||
expect(options.urls).to.have.length(1);
|
||||
expect(options.urls[0]).to.be.eql(
|
||||
'https://services.arcgisonline.com/arcgis/rest/services/' +
|
||||
'Demographics/USA_Population_Density/MapServer/WMTS?');
|
||||
it('can create KVP options from spec/ol/format/wmts/arcgis.xml', function () {
|
||||
const options = optionsFromCapabilities(capabilities, {
|
||||
layer: 'Demographics_USA_Population_Density',
|
||||
requestEncoding: 'KVP',
|
||||
matrixSet: 'default028mm',
|
||||
});
|
||||
|
||||
it('can create REST options from spec/ol/format/wmts/arcgis.xml',
|
||||
function() {
|
||||
const options = optionsFromCapabilities(
|
||||
capabilities, {
|
||||
layer: 'Demographics_USA_Population_Density',
|
||||
matrixSet: 'default028mm'
|
||||
});
|
||||
expect(options.urls).to.be.an('array');
|
||||
expect(options.urls).to.have.length(1);
|
||||
expect(options.urls[0]).to.be.eql(
|
||||
'https://services.arcgisonline.com/arcgis/rest/services/' +
|
||||
'Demographics/USA_Population_Density/MapServer/WMTS?'
|
||||
);
|
||||
});
|
||||
|
||||
expect(options.urls).to.be.an('array');
|
||||
expect(options.urls).to.have.length(1);
|
||||
expect(options.urls[0]).to.be.eql(
|
||||
'https://services.arcgisonline.com/arcgis/rest/services/' +
|
||||
'Demographics/USA_Population_Density/MapServer/WMTS/' +
|
||||
'tile/1.0.0/Demographics_USA_Population_Density/' +
|
||||
'{Style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.png');
|
||||
it('can create REST options from spec/ol/format/wmts/arcgis.xml', function () {
|
||||
const options = optionsFromCapabilities(capabilities, {
|
||||
layer: 'Demographics_USA_Population_Density',
|
||||
matrixSet: 'default028mm',
|
||||
});
|
||||
|
||||
expect(options.urls).to.be.an('array');
|
||||
expect(options.urls).to.have.length(1);
|
||||
expect(options.urls[0]).to.be.eql(
|
||||
'https://services.arcgisonline.com/arcgis/rest/services/' +
|
||||
'Demographics/USA_Population_Density/MapServer/WMTS/' +
|
||||
'tile/1.0.0/Demographics_USA_Population_Density/' +
|
||||
'{Style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.png'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setUrls()', function() {
|
||||
it('sets the URL for the source', function() {
|
||||
describe('#setUrls()', function () {
|
||||
it('sets the URL for the source', function () {
|
||||
const source = new WMTS({});
|
||||
|
||||
const urls = [
|
||||
'https://a.example.com/',
|
||||
'https://b.example.com/',
|
||||
'https://c.example.com/'
|
||||
'https://c.example.com/',
|
||||
];
|
||||
source.setUrls(urls);
|
||||
|
||||
expect(source.getUrls()).to.eql(urls);
|
||||
});
|
||||
|
||||
it('updates the key for the source', function() {
|
||||
it('updates the key for the source', function () {
|
||||
const source = new WMTS({});
|
||||
|
||||
const urls = [
|
||||
'https://a.example.com/',
|
||||
'https://b.example.com/',
|
||||
'https://c.example.com/'
|
||||
'https://c.example.com/',
|
||||
];
|
||||
source.setUrls(urls);
|
||||
|
||||
expect(source.getKey()).to.eql(urls.join('\n'));
|
||||
});
|
||||
|
||||
it('generates the correct tileUrlFunction during application of setUrl()', function() {
|
||||
it('generates the correct tileUrlFunction during application of setUrl()', function () {
|
||||
const projection = getProjection('EPSG:3857');
|
||||
const source = new WMTS({
|
||||
projection: projection,
|
||||
requestEncoding: 'REST',
|
||||
urls: [
|
||||
'http://1.example.com/{TileMatrix}/{TileRow}/{TileCol}.jpeg',
|
||||
'http://2.example.com/{TileMatrix}/{TileRow}/{TileCol}.jpeg'
|
||||
'http://2.example.com/{TileMatrix}/{TileRow}/{TileCol}.jpeg',
|
||||
],
|
||||
tileGrid: new WMTSTileGrid({
|
||||
matrixIds: [0, 1, 2, 3, 4, 5, 6, 7],
|
||||
origin: [2690000, 1285000],
|
||||
resolutions: [4000, 3750, 3500, 3250, 3000, 2750, 2500, 2250]
|
||||
})
|
||||
resolutions: [4000, 3750, 3500, 3250, 3000, 2750, 2500, 2250],
|
||||
}),
|
||||
});
|
||||
|
||||
const urls = [
|
||||
'https://a.example.com/{TileMatrix}/{TileRow}/{TileCol}.jpg',
|
||||
'https://b.example.com/{TileMatrix}/{TileRow}/{TileCol}.jpg'
|
||||
'https://b.example.com/{TileMatrix}/{TileRow}/{TileCol}.jpg',
|
||||
];
|
||||
source.setUrls(urls);
|
||||
const tileUrl1 = source.tileUrlFunction([2, 9, -5], 1, projection);
|
||||
@@ -366,10 +403,10 @@ describe('ol.source.WMTS', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('url option', function() {
|
||||
it('expands url template', function() {
|
||||
describe('url option', function () {
|
||||
it('expands url template', function () {
|
||||
const tileSource = new WMTS({
|
||||
url: '{1-3}'
|
||||
url: '{1-3}',
|
||||
});
|
||||
|
||||
const urls = tileSource.getUrls();
|
||||
@@ -377,12 +414,11 @@ describe('ol.source.WMTS', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getUrls', function() {
|
||||
|
||||
describe('#getUrls', function () {
|
||||
let sourceOptions;
|
||||
let source;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
sourceOptions = {
|
||||
layer: 'layer',
|
||||
style: 'default',
|
||||
@@ -391,44 +427,40 @@ describe('ol.source.WMTS', function() {
|
||||
tileGrid: new WMTSTileGrid({
|
||||
origin: [0, 0],
|
||||
resolutions: [],
|
||||
matrixIds: []
|
||||
})
|
||||
matrixIds: [],
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
describe('using a "url" option', function() {
|
||||
beforeEach(function() {
|
||||
describe('using a "url" option', function () {
|
||||
beforeEach(function () {
|
||||
sourceOptions.url = 'some_wmts_url';
|
||||
source = new WMTS(sourceOptions);
|
||||
});
|
||||
|
||||
it('returns the WMTS URLs', function() {
|
||||
it('returns the WMTS URLs', function () {
|
||||
const urls = source.getUrls();
|
||||
expect(urls).to.be.eql(['some_wmts_url']);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('using a "urls" option', function() {
|
||||
beforeEach(function() {
|
||||
describe('using a "urls" option', function () {
|
||||
beforeEach(function () {
|
||||
sourceOptions.urls = ['some_wmts_url1', 'some_wmts_url2'];
|
||||
source = new WMTS(sourceOptions);
|
||||
});
|
||||
|
||||
it('returns the WMTS URLs', function() {
|
||||
it('returns the WMTS URLs', function () {
|
||||
const urls = source.getUrls();
|
||||
expect(urls).to.be.eql(['some_wmts_url1', 'some_wmts_url2']);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getRequestEncoding', function() {
|
||||
|
||||
describe('#getRequestEncoding', function () {
|
||||
let source;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
source = new WMTS({
|
||||
layer: 'layer',
|
||||
style: 'default',
|
||||
@@ -437,16 +469,14 @@ describe('ol.source.WMTS', function() {
|
||||
tileGrid: new WMTSTileGrid({
|
||||
origin: [0, 0],
|
||||
resolutions: [],
|
||||
matrixIds: []
|
||||
})
|
||||
matrixIds: [],
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
it('returns the request encoding', function() {
|
||||
it('returns the request encoding', function () {
|
||||
const requestEncoding = source.getRequestEncoding();
|
||||
expect(requestEncoding).to.be.eql('REST');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
import TileSource from '../../../../src/ol/source/Tile.js';
|
||||
import TileLayer from '../../../../src/ol/layer/Tile.js';
|
||||
import Map from '../../../../src/ol/Map.js';
|
||||
import TileImage from '../../../../src/ol/source/TileImage.js';
|
||||
import TileLayer from '../../../../src/ol/layer/Tile.js';
|
||||
import TileSource from '../../../../src/ol/source/Tile.js';
|
||||
import UrlTile from '../../../../src/ol/source/UrlTile.js';
|
||||
import View from '../../../../src/ol/View.js';
|
||||
import XYZ from '../../../../src/ol/source/XYZ.js';
|
||||
import {createXYZ} from '../../../../src/ol/tilegrid.js';
|
||||
import View from '../../../../src/ol/View.js';
|
||||
import Map from '../../../../src/ol/Map.js';
|
||||
|
||||
|
||||
describe('ol.source.XYZ', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('can be constructed without options', function() {
|
||||
describe('ol.source.XYZ', function () {
|
||||
describe('constructor', function () {
|
||||
it('can be constructed without options', function () {
|
||||
const source = new XYZ();
|
||||
expect(source).to.be.an(XYZ);
|
||||
expect(source).to.be.an(TileImage);
|
||||
@@ -20,190 +17,188 @@ describe('ol.source.XYZ', function() {
|
||||
expect(source).to.be.an(TileSource);
|
||||
});
|
||||
|
||||
it('can be constructed with a custom zDirection', function() {
|
||||
it('can be constructed with a custom zDirection', function () {
|
||||
const source = new XYZ({
|
||||
zDirection: -1
|
||||
zDirection: -1,
|
||||
});
|
||||
expect(source.zDirection).to.be(-1);
|
||||
});
|
||||
|
||||
it('can be constructed with a custom tile grid', function() {
|
||||
it('can be constructed with a custom tile grid', function () {
|
||||
const tileGrid = createXYZ();
|
||||
const tileSource = new XYZ({
|
||||
tileGrid: tileGrid
|
||||
tileGrid: tileGrid,
|
||||
});
|
||||
expect(tileSource.getTileGrid()).to.be(tileGrid);
|
||||
});
|
||||
|
||||
it('can be constructed with a custom tile size', function() {
|
||||
it('can be constructed with a custom tile size', function () {
|
||||
const tileSource = new XYZ({
|
||||
tileSize: 512
|
||||
tileSize: 512,
|
||||
});
|
||||
expect(tileSource.getTileGrid().getTileSize(0)).to.be(512);
|
||||
});
|
||||
|
||||
it('can be constructed with a custom min zoom', function() {
|
||||
it('can be constructed with a custom min zoom', function () {
|
||||
const tileSource = new XYZ({
|
||||
minZoom: 2
|
||||
minZoom: 2,
|
||||
});
|
||||
expect(tileSource.getTileGrid().getMinZoom()).to.be(2);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('tileUrlFunction', function() {
|
||||
|
||||
describe('tileUrlFunction', function () {
|
||||
let xyzTileSource, tileGrid;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
xyzTileSource = new XYZ({
|
||||
maxZoom: 6,
|
||||
url: '{z}/{x}/{y}'
|
||||
url: '{z}/{x}/{y}',
|
||||
});
|
||||
tileGrid = xyzTileSource.getTileGrid();
|
||||
});
|
||||
|
||||
it('returns the expected URL', function() {
|
||||
|
||||
it('returns the expected URL', function () {
|
||||
const coordinate = [829330.2064098881, 5933916.615134273];
|
||||
let tileUrl;
|
||||
|
||||
tileUrl = xyzTileSource.tileUrlFunction(
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 0));
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 0)
|
||||
);
|
||||
expect(tileUrl).to.eql('0/0/0');
|
||||
|
||||
tileUrl = xyzTileSource.tileUrlFunction(
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 1));
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 1)
|
||||
);
|
||||
expect(tileUrl).to.eql('1/1/0');
|
||||
|
||||
tileUrl = xyzTileSource.tileUrlFunction(
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 2));
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 2)
|
||||
);
|
||||
expect(tileUrl).to.eql('2/2/1');
|
||||
|
||||
tileUrl = xyzTileSource.tileUrlFunction(
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 3));
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 3)
|
||||
);
|
||||
expect(tileUrl).to.eql('3/4/2');
|
||||
|
||||
tileUrl = xyzTileSource.tileUrlFunction(
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 4));
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 4)
|
||||
);
|
||||
expect(tileUrl).to.eql('4/8/5');
|
||||
|
||||
tileUrl = xyzTileSource.tileUrlFunction(
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 5));
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 5)
|
||||
);
|
||||
expect(tileUrl).to.eql('5/16/11');
|
||||
|
||||
tileUrl = xyzTileSource.tileUrlFunction(
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 6));
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 6)
|
||||
);
|
||||
expect(tileUrl).to.eql('6/33/22');
|
||||
|
||||
});
|
||||
|
||||
describe('wrap x', function() {
|
||||
|
||||
it('returns the expected URL', function() {
|
||||
describe('wrap x', function () {
|
||||
it('returns the expected URL', function () {
|
||||
const projection = xyzTileSource.getProjection();
|
||||
let tileUrl = xyzTileSource.tileUrlFunction(
|
||||
xyzTileSource.getTileCoordForTileUrlFunction([6, -31, 22], projection));
|
||||
xyzTileSource.getTileCoordForTileUrlFunction([6, -31, 22], projection)
|
||||
);
|
||||
expect(tileUrl).to.eql('6/33/22');
|
||||
|
||||
tileUrl = xyzTileSource.tileUrlFunction(
|
||||
xyzTileSource.getTileCoordForTileUrlFunction([6, 33, 22], projection));
|
||||
xyzTileSource.getTileCoordForTileUrlFunction([6, 33, 22], projection)
|
||||
);
|
||||
expect(tileUrl).to.eql('6/33/22');
|
||||
|
||||
tileUrl = xyzTileSource.tileUrlFunction(
|
||||
xyzTileSource.getTileCoordForTileUrlFunction([6, 97, 22], projection));
|
||||
xyzTileSource.getTileCoordForTileUrlFunction([6, 97, 22], projection)
|
||||
);
|
||||
expect(tileUrl).to.eql('6/33/22');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('crop y', function() {
|
||||
|
||||
it('returns the expected URL', function() {
|
||||
describe('crop y', function () {
|
||||
it('returns the expected URL', function () {
|
||||
const projection = xyzTileSource.getProjection();
|
||||
let tileUrl = xyzTileSource.tileUrlFunction(
|
||||
xyzTileSource.getTileCoordForTileUrlFunction([6, 33, -1], projection));
|
||||
xyzTileSource.getTileCoordForTileUrlFunction([6, 33, -1], projection)
|
||||
);
|
||||
expect(tileUrl).to.be(undefined);
|
||||
|
||||
tileUrl = xyzTileSource.tileUrlFunction(
|
||||
xyzTileSource.getTileCoordForTileUrlFunction([6, 33, 22], projection));
|
||||
xyzTileSource.getTileCoordForTileUrlFunction([6, 33, 22], projection)
|
||||
);
|
||||
expect(tileUrl).to.eql('6/33/22');
|
||||
|
||||
tileUrl = xyzTileSource.tileUrlFunction(
|
||||
xyzTileSource.getTileCoordForTileUrlFunction([6, 33, 64], projection));
|
||||
xyzTileSource.getTileCoordForTileUrlFunction([6, 33, 64], projection)
|
||||
);
|
||||
expect(tileUrl).to.be(undefined);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getUrls', function() {
|
||||
|
||||
describe('#getUrls', function () {
|
||||
let sourceOptions;
|
||||
let source;
|
||||
const url = 'http://geo.nls.uk/maps/towns/glasgow1857/{z}/{x}/{-y}.png';
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
sourceOptions = {
|
||||
projection: 'EPSG:4326'
|
||||
projection: 'EPSG:4326',
|
||||
};
|
||||
});
|
||||
|
||||
describe('using a "url" option', function() {
|
||||
beforeEach(function() {
|
||||
describe('using a "url" option', function () {
|
||||
beforeEach(function () {
|
||||
sourceOptions.url = url;
|
||||
source = new XYZ(sourceOptions);
|
||||
});
|
||||
|
||||
it('returns the XYZ URL', function() {
|
||||
it('returns the XYZ URL', function () {
|
||||
const urls = source.getUrls();
|
||||
expect(urls).to.be.eql([url]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('using a "urls" option', function() {
|
||||
beforeEach(function() {
|
||||
describe('using a "urls" option', function () {
|
||||
beforeEach(function () {
|
||||
sourceOptions.urls = ['some_xyz_url1', 'some_xyz_url2'];
|
||||
source = new XYZ(sourceOptions);
|
||||
});
|
||||
|
||||
it('returns the XYZ URLs', function() {
|
||||
it('returns the XYZ URLs', function () {
|
||||
const urls = source.getUrls();
|
||||
expect(urls).to.be.eql(['some_xyz_url1', 'some_xyz_url2']);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('using a "tileUrlFunction"', function() {
|
||||
beforeEach(function() {
|
||||
sourceOptions.tileUrlFunction = function() {
|
||||
describe('using a "tileUrlFunction"', function () {
|
||||
beforeEach(function () {
|
||||
sourceOptions.tileUrlFunction = function () {
|
||||
return 'some_xyz_url';
|
||||
};
|
||||
source = new XYZ(sourceOptions);
|
||||
});
|
||||
|
||||
it('returns null', function() {
|
||||
it('returns null', function () {
|
||||
const urls = source.getUrls();
|
||||
expect(urls).to.be(null);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('clear and refresh', function() {
|
||||
|
||||
describe('clear and refresh', function () {
|
||||
let map, source;
|
||||
let callCount = 0;
|
||||
beforeEach(function(done) {
|
||||
beforeEach(function (done) {
|
||||
source = new XYZ({
|
||||
url: 'spec/ol/data/osm-{z}-{x}-{y}.png',
|
||||
tileLoadFunction: function(image, src) {
|
||||
tileLoadFunction: function (image, src) {
|
||||
++callCount;
|
||||
image.getImage().src = src;
|
||||
}
|
||||
},
|
||||
});
|
||||
const target = document.createElement('div');
|
||||
target.style.width = '100px';
|
||||
@@ -213,43 +208,41 @@ describe('ol.source.XYZ', function() {
|
||||
target: target,
|
||||
layers: [
|
||||
new TileLayer({
|
||||
source: source
|
||||
})
|
||||
source: source,
|
||||
}),
|
||||
],
|
||||
view: new View({
|
||||
center: [0, 0],
|
||||
zoom: 0
|
||||
})
|
||||
zoom: 0,
|
||||
}),
|
||||
});
|
||||
map.once('rendercomplete', function() {
|
||||
map.once('rendercomplete', function () {
|
||||
callCount = 0;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
document.body.removeChild(map.getTargetElement());
|
||||
map.setTarget(null);
|
||||
});
|
||||
|
||||
it('#refresh() reloads from server', function(done) {
|
||||
map.once('rendercomplete', function() {
|
||||
it('#refresh() reloads from server', function (done) {
|
||||
map.once('rendercomplete', function () {
|
||||
expect(callCount).to.be(1);
|
||||
done();
|
||||
});
|
||||
source.refresh();
|
||||
});
|
||||
|
||||
it('#clear() clears the tile cache', function(done) {
|
||||
map.once('rendercomplete', function() {
|
||||
it('#clear() clears the tile cache', function (done) {
|
||||
map.once('rendercomplete', function () {
|
||||
done(new Error('should not re-render'));
|
||||
});
|
||||
source.clear();
|
||||
setTimeout(function() {
|
||||
setTimeout(function () {
|
||||
done();
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,151 +1,148 @@
|
||||
import Projection from '../../../../src/ol/proj/Projection.js';
|
||||
import TileGrid from '../../../../src/ol/tilegrid/TileGrid.js';
|
||||
import Zoomify, {CustomTile} from '../../../../src/ol/source/Zoomify.js';
|
||||
import {DEFAULT_TILE_SIZE} from '../../../../src/ol/tilegrid/common.js';
|
||||
import {listen} from '../../../../src/ol/events.js';
|
||||
import Projection from '../../../../src/ol/proj/Projection.js';
|
||||
import Zoomify, {CustomTile} from '../../../../src/ol/source/Zoomify.js';
|
||||
import TileGrid from '../../../../src/ol/tilegrid/TileGrid.js';
|
||||
|
||||
|
||||
describe('ol.source.Zoomify', function() {
|
||||
describe('ol.source.Zoomify', function () {
|
||||
const w = 1024;
|
||||
const h = 512;
|
||||
const size = [w, h];
|
||||
const zoomifyUrl = 'spec/ol/source/images/zoomify/{TileGroup}/{z}-{x}-{y}.jpg';
|
||||
const zoomifyUrl =
|
||||
'spec/ol/source/images/zoomify/{TileGroup}/{z}-{x}-{y}.jpg';
|
||||
const iipUrl = 'spec/ol/source/images/zoomify?JTL={z},{tileIndex}';
|
||||
const proj = new Projection({
|
||||
code: 'ZOOMIFY',
|
||||
units: 'pixels',
|
||||
extent: [0, 0, w, h]
|
||||
extent: [0, 0, w, h],
|
||||
});
|
||||
function getZoomifySource() {
|
||||
return new Zoomify({
|
||||
url: zoomifyUrl,
|
||||
size: size
|
||||
size: size,
|
||||
});
|
||||
}
|
||||
function getZoomifySourceWithExtentInFirstQuadrant() {
|
||||
return new Zoomify({
|
||||
url: zoomifyUrl,
|
||||
size: size,
|
||||
extent: [0, 0, size[0], size[1]]
|
||||
extent: [0, 0, size[0], size[1]],
|
||||
});
|
||||
}
|
||||
function getIIPSource() {
|
||||
return new Zoomify({
|
||||
url: iipUrl,
|
||||
size: size
|
||||
size: size,
|
||||
});
|
||||
}
|
||||
function getZoomifySourceWith1024pxTiles() {
|
||||
return new Zoomify({
|
||||
url: zoomifyUrl,
|
||||
size: size,
|
||||
tileSize: 1024
|
||||
tileSize: 1024,
|
||||
});
|
||||
}
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('requires config "size" and "url"', function() {
|
||||
describe('constructor', function () {
|
||||
it('requires config "size" and "url"', function () {
|
||||
let source;
|
||||
|
||||
// undefined config object
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
source = new Zoomify();
|
||||
}).to.throwException();
|
||||
|
||||
// empty object as config object
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
source = new Zoomify({});
|
||||
}).to.throwException();
|
||||
|
||||
// passing "url" in config object
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
source = new Zoomify({
|
||||
url: 'some-url'
|
||||
url: 'some-url',
|
||||
});
|
||||
}).to.throwException();
|
||||
|
||||
// passing "size" in config object
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
source = new Zoomify({
|
||||
size: [47, 11]
|
||||
size: [47, 11],
|
||||
});
|
||||
}).to.throwException();
|
||||
|
||||
// passing "size" and "url" in config object
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
source = new Zoomify({
|
||||
url: '',
|
||||
size: [47, 11]
|
||||
size: [47, 11],
|
||||
});
|
||||
}).to.not.throwException();
|
||||
// we got a source
|
||||
expect(source).to.be.a(Zoomify);
|
||||
|
||||
// also test our helper methods from above
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
source = getZoomifySource();
|
||||
}).to.not.throwException();
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
source = getIIPSource();
|
||||
}).to.not.throwException();
|
||||
// we got a source
|
||||
expect(source).to.be.a(Zoomify);
|
||||
});
|
||||
|
||||
it('does not need "tierSizeCalculation" option', function() {
|
||||
expect(function() {
|
||||
new Zoomify({
|
||||
url: '',
|
||||
size: [47, 11]
|
||||
});
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
it('accepts "tierSizeCalculation" option "default"', function() {
|
||||
expect(function() {
|
||||
it('does not need "tierSizeCalculation" option', function () {
|
||||
expect(function () {
|
||||
new Zoomify({
|
||||
url: '',
|
||||
size: [47, 11],
|
||||
tierSizeCalculation: 'default'
|
||||
});
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
it('accepts "tierSizeCalculation" option "truncated"', function() {
|
||||
expect(function() {
|
||||
it('accepts "tierSizeCalculation" option "default"', function () {
|
||||
expect(function () {
|
||||
new Zoomify({
|
||||
url: '',
|
||||
size: [47, 11],
|
||||
tierSizeCalculation: 'truncated'
|
||||
tierSizeCalculation: 'default',
|
||||
});
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
it('throws on unexpected "tierSizeCalculation" ', function() {
|
||||
it('accepts "tierSizeCalculation" option "truncated"', function () {
|
||||
expect(function () {
|
||||
new Zoomify({
|
||||
url: '',
|
||||
size: [47, 11],
|
||||
tierSizeCalculation: 'truncated',
|
||||
});
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
it('throws on unexpected "tierSizeCalculation" ', function () {
|
||||
// passing unknown string will throw
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
new Zoomify({
|
||||
url: '',
|
||||
size: [47, 11],
|
||||
tierSizeCalculation: 'ace-of-spades'
|
||||
tierSizeCalculation: 'ace-of-spades',
|
||||
});
|
||||
}).to.throwException();
|
||||
});
|
||||
|
||||
it('creates a tileGrid for both protocols', function() {
|
||||
it('creates a tileGrid for both protocols', function () {
|
||||
const sources = [getZoomifySource(), getIIPSource()];
|
||||
for (let i = 0; i < sources.length; i++) {
|
||||
const tileGrid = sources[i].getTileGrid();
|
||||
expect(tileGrid).to.be.a(TileGrid);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('generated tileGrid', function() {
|
||||
|
||||
it('has expected extent', function() {
|
||||
describe('generated tileGrid', function () {
|
||||
it('has expected extent', function () {
|
||||
const sources = [getZoomifySource(), getIIPSource()];
|
||||
for (let i = 0; i < sources.length; i++) {
|
||||
const tileGrid = sources[i].getTileGrid();
|
||||
@@ -154,7 +151,7 @@ describe('ol.source.Zoomify', function() {
|
||||
}
|
||||
});
|
||||
|
||||
it('has expected origin', function() {
|
||||
it('has expected origin', function () {
|
||||
const sources = [getZoomifySource(), getIIPSource()];
|
||||
for (let i = 0; i < sources.length; i++) {
|
||||
const tileGrid = sources[i].getTileGrid();
|
||||
@@ -163,7 +160,7 @@ describe('ol.source.Zoomify', function() {
|
||||
}
|
||||
});
|
||||
|
||||
it('has expected resolutions', function() {
|
||||
it('has expected resolutions', function () {
|
||||
const sources = [getZoomifySource(), getIIPSource()];
|
||||
for (let i = 0; i < sources.length; i++) {
|
||||
const tileGrid = sources[i].getTileGrid();
|
||||
@@ -172,7 +169,7 @@ describe('ol.source.Zoomify', function() {
|
||||
}
|
||||
});
|
||||
|
||||
it('has expected tileSize', function() {
|
||||
it('has expected tileSize', function () {
|
||||
const sources = [getZoomifySource(), getZoomifySourceWith1024pxTiles()];
|
||||
const expectedTileSizes = [DEFAULT_TILE_SIZE, 1024];
|
||||
for (let i = 0; i < sources.length; i++) {
|
||||
@@ -181,11 +178,14 @@ describe('ol.source.Zoomify', function() {
|
||||
}
|
||||
});
|
||||
|
||||
it('has expected extent', function() {
|
||||
const sources = [getZoomifySource(), getZoomifySourceWithExtentInFirstQuadrant()];
|
||||
it('has expected extent', function () {
|
||||
const sources = [
|
||||
getZoomifySource(),
|
||||
getZoomifySourceWithExtentInFirstQuadrant(),
|
||||
];
|
||||
const expectedExtents = [
|
||||
[0, -size[1], size[0], 0],
|
||||
[0, 0, size[0], size[1]]
|
||||
[0, 0, size[0], size[1]],
|
||||
];
|
||||
for (let i = 0; i < sources.length; i++) {
|
||||
const tileGrid = sources[i].getTileGrid();
|
||||
@@ -193,27 +193,28 @@ describe('ol.source.Zoomify', function() {
|
||||
}
|
||||
});
|
||||
|
||||
it('has expected origin', function() {
|
||||
const sources = [getZoomifySource(), getZoomifySourceWithExtentInFirstQuadrant()];
|
||||
it('has expected origin', function () {
|
||||
const sources = [
|
||||
getZoomifySource(),
|
||||
getZoomifySourceWithExtentInFirstQuadrant(),
|
||||
];
|
||||
const expectedOrigins = [
|
||||
[0, 0],
|
||||
[0, size[1]]
|
||||
[0, size[1]],
|
||||
];
|
||||
for (let i = 0; i < sources.length; i++) {
|
||||
const tileGrid = sources[i].getTileGrid();
|
||||
expect(tileGrid.getOrigin()).to.eql(expectedOrigins[i]);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('tierSizeCalculation configuration', function() {
|
||||
|
||||
it('influences resolutions', function() {
|
||||
describe('tierSizeCalculation configuration', function () {
|
||||
it('influences resolutions', function () {
|
||||
// not configured at all
|
||||
const source = new Zoomify({
|
||||
url: zoomifyUrl,
|
||||
size: [513, 256]
|
||||
size: [513, 256],
|
||||
});
|
||||
const tileGrid = source.getTileGrid();
|
||||
|
||||
@@ -221,7 +222,7 @@ describe('ol.source.Zoomify', function() {
|
||||
const sourceDefault = new Zoomify({
|
||||
url: zoomifyUrl,
|
||||
size: [513, 256],
|
||||
tierSizeCalculation: 'default'
|
||||
tierSizeCalculation: 'default',
|
||||
});
|
||||
const tileGridDefault = sourceDefault.getTileGrid();
|
||||
|
||||
@@ -229,7 +230,7 @@ describe('ol.source.Zoomify', function() {
|
||||
const sourceTruncated = new Zoomify({
|
||||
url: zoomifyUrl,
|
||||
size: [513, 256],
|
||||
tierSizeCalculation: 'truncated'
|
||||
tierSizeCalculation: 'truncated',
|
||||
});
|
||||
const tileGridTruncated = sourceTruncated.getTileGrid();
|
||||
|
||||
@@ -237,65 +238,91 @@ describe('ol.source.Zoomify', function() {
|
||||
expect(tileGridDefault.getResolutions()).to.eql([4, 2, 1]);
|
||||
expect(tileGridTruncated.getResolutions()).to.eql([2, 1]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('generated tileUrlFunction for zoomify protocol', function() {
|
||||
|
||||
it('creates an expected tileUrlFunction with zoomify template', function() {
|
||||
describe('generated tileUrlFunction for zoomify protocol', function () {
|
||||
it('creates an expected tileUrlFunction with zoomify template', function () {
|
||||
const source = getZoomifySource();
|
||||
const tileUrlFunction = source.getTileUrlFunction();
|
||||
// zoomlevel 0
|
||||
expect(tileUrlFunction([0, 0, 0])).to.eql('spec/ol/source/images/zoomify/TileGroup0/0-0-0.jpg');
|
||||
expect(tileUrlFunction([0, 0, 0])).to.eql(
|
||||
'spec/ol/source/images/zoomify/TileGroup0/0-0-0.jpg'
|
||||
);
|
||||
// zoomlevel 1
|
||||
expect(tileUrlFunction([1, 0, 0])).to.eql('spec/ol/source/images/zoomify/TileGroup0/1-0-0.jpg');
|
||||
expect(tileUrlFunction([1, 1, 0])).to.eql('spec/ol/source/images/zoomify/TileGroup0/1-1-0.jpg');
|
||||
expect(tileUrlFunction([1, 0, 1])).to.eql('spec/ol/source/images/zoomify/TileGroup0/1-0-1.jpg');
|
||||
expect(tileUrlFunction([1, 1, 1])).to.eql('spec/ol/source/images/zoomify/TileGroup0/1-1-1.jpg');
|
||||
expect(tileUrlFunction([1, 0, 0])).to.eql(
|
||||
'spec/ol/source/images/zoomify/TileGroup0/1-0-0.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([1, 1, 0])).to.eql(
|
||||
'spec/ol/source/images/zoomify/TileGroup0/1-1-0.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([1, 0, 1])).to.eql(
|
||||
'spec/ol/source/images/zoomify/TileGroup0/1-0-1.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([1, 1, 1])).to.eql(
|
||||
'spec/ol/source/images/zoomify/TileGroup0/1-1-1.jpg'
|
||||
);
|
||||
});
|
||||
it('creates an expected tileUrlFunction with IIP template', function() {
|
||||
it('creates an expected tileUrlFunction with IIP template', function () {
|
||||
const source = getIIPSource();
|
||||
const tileUrlFunction = source.getTileUrlFunction();
|
||||
// zoomlevel 0
|
||||
expect(tileUrlFunction([0, 0, 0])).to.eql('spec/ol/source/images/zoomify?JTL=0,0');
|
||||
expect(tileUrlFunction([0, 0, 0])).to.eql(
|
||||
'spec/ol/source/images/zoomify?JTL=0,0'
|
||||
);
|
||||
// zoomlevel 1
|
||||
expect(tileUrlFunction([1, 0, 0])).to.eql('spec/ol/source/images/zoomify?JTL=1,0');
|
||||
expect(tileUrlFunction([1, 1, 0])).to.eql('spec/ol/source/images/zoomify?JTL=1,1');
|
||||
expect(tileUrlFunction([1, 0, 1])).to.eql('spec/ol/source/images/zoomify?JTL=1,2');
|
||||
expect(tileUrlFunction([1, 1, 1])).to.eql('spec/ol/source/images/zoomify?JTL=1,3');
|
||||
expect(tileUrlFunction([1, 0, 0])).to.eql(
|
||||
'spec/ol/source/images/zoomify?JTL=1,0'
|
||||
);
|
||||
expect(tileUrlFunction([1, 1, 0])).to.eql(
|
||||
'spec/ol/source/images/zoomify?JTL=1,1'
|
||||
);
|
||||
expect(tileUrlFunction([1, 0, 1])).to.eql(
|
||||
'spec/ol/source/images/zoomify?JTL=1,2'
|
||||
);
|
||||
expect(tileUrlFunction([1, 1, 1])).to.eql(
|
||||
'spec/ol/source/images/zoomify?JTL=1,3'
|
||||
);
|
||||
});
|
||||
|
||||
it('creates an expected tileUrlFunction without template', function() {
|
||||
it('creates an expected tileUrlFunction without template', function () {
|
||||
const source = new Zoomify({
|
||||
url: 'spec/ol/source/images/zoomify/',
|
||||
size: size
|
||||
size: size,
|
||||
});
|
||||
const tileUrlFunction = source.getTileUrlFunction();
|
||||
// zoomlevel 0
|
||||
expect(tileUrlFunction([0, 0, 0])).to.eql('spec/ol/source/images/zoomify/TileGroup0/0-0-0.jpg');
|
||||
expect(tileUrlFunction([0, 0, 0])).to.eql(
|
||||
'spec/ol/source/images/zoomify/TileGroup0/0-0-0.jpg'
|
||||
);
|
||||
// zoomlevel 1
|
||||
expect(tileUrlFunction([1, 0, 0])).to.eql('spec/ol/source/images/zoomify/TileGroup0/1-0-0.jpg');
|
||||
expect(tileUrlFunction([1, 1, 0])).to.eql('spec/ol/source/images/zoomify/TileGroup0/1-1-0.jpg');
|
||||
expect(tileUrlFunction([1, 0, 1])).to.eql('spec/ol/source/images/zoomify/TileGroup0/1-0-1.jpg');
|
||||
expect(tileUrlFunction([1, 1, 1])).to.eql('spec/ol/source/images/zoomify/TileGroup0/1-1-1.jpg');
|
||||
expect(tileUrlFunction([1, 0, 0])).to.eql(
|
||||
'spec/ol/source/images/zoomify/TileGroup0/1-0-0.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([1, 1, 0])).to.eql(
|
||||
'spec/ol/source/images/zoomify/TileGroup0/1-1-0.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([1, 0, 1])).to.eql(
|
||||
'spec/ol/source/images/zoomify/TileGroup0/1-0-1.jpg'
|
||||
);
|
||||
expect(tileUrlFunction([1, 1, 1])).to.eql(
|
||||
'spec/ol/source/images/zoomify/TileGroup0/1-1-1.jpg'
|
||||
);
|
||||
});
|
||||
it('returns undefined if no tileCoord passed', function() {
|
||||
it('returns undefined if no tileCoord passed', function () {
|
||||
const source = getZoomifySource();
|
||||
const tileUrlFunction = source.getTileUrlFunction();
|
||||
expect(tileUrlFunction()).to.be(undefined);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('uses a custom tileClass', function() {
|
||||
|
||||
it('returns expected tileClass instances via "getTile"', function() {
|
||||
describe('uses a custom tileClass', function () {
|
||||
it('returns expected tileClass instances via "getTile"', function () {
|
||||
const source = getZoomifySource();
|
||||
const tile = source.getTile(0, 0, 0, 1, proj);
|
||||
expect(tile).to.be.a(CustomTile);
|
||||
});
|
||||
|
||||
it('"tile.getImage" returns and caches an unloaded image', function() {
|
||||
it('"tile.getImage" returns and caches an unloaded image', function () {
|
||||
const source = getZoomifySource();
|
||||
|
||||
const tile = source.getTile(0, 0, 0, 1, proj);
|
||||
@@ -308,13 +335,14 @@ describe('ol.source.Zoomify', function() {
|
||||
expect(img).to.be(img2);
|
||||
});
|
||||
|
||||
it('"tile.getImage" returns and caches a loaded canvas', function(done) {
|
||||
it('"tile.getImage" returns and caches a loaded canvas', function (done) {
|
||||
const source = getZoomifySource();
|
||||
|
||||
const tile = source.getTile(0, 0, 0, 1, proj);
|
||||
|
||||
listen(tile, 'change', function() {
|
||||
if (tile.getState() == 2) { // LOADED
|
||||
listen(tile, 'change', function () {
|
||||
if (tile.getState() == 2) {
|
||||
// LOADED
|
||||
const img = tile.getImage();
|
||||
expect(img).to.be.a(HTMLCanvasElement);
|
||||
|
||||
@@ -327,7 +355,5 @@ describe('ol.source.Zoomify', function() {
|
||||
});
|
||||
tile.load();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user