Additional tests, documentation and example
This commit is contained in:
162
test/spec/ol/source/urltilesource.test.js
Normal file
162
test/spec/ol/source/urltilesource.test.js
Normal file
@@ -0,0 +1,162 @@
|
||||
goog.provide('ol.test.source.UrlTile');
|
||||
|
||||
|
||||
describe('ol.source.UrlTile', function() {
|
||||
|
||||
describe('tileUrlFunction', function() {
|
||||
|
||||
var tileSource, tileGrid;
|
||||
|
||||
beforeEach(function() {
|
||||
tileSource = new ol.source.UrlTile({
|
||||
projection: 'EPSG:3857',
|
||||
tileGrid: ol.tilegrid.createXYZ({maxZoom: 6}),
|
||||
url: '{z}/{x}/{y}',
|
||||
wrapX: true
|
||||
});
|
||||
tileGrid = tileSource.getTileGrid();
|
||||
});
|
||||
|
||||
it('returns the expected URL', function() {
|
||||
|
||||
var coordinate = [829330.2064098881, 5933916.615134273];
|
||||
var tileUrl;
|
||||
|
||||
tileUrl = tileSource.tileUrlFunction(
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 0));
|
||||
expect(tileUrl).to.eql('0/0/0');
|
||||
|
||||
tileUrl = tileSource.tileUrlFunction(
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 1));
|
||||
expect(tileUrl).to.eql('1/1/0');
|
||||
|
||||
tileUrl = tileSource.tileUrlFunction(
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 2));
|
||||
expect(tileUrl).to.eql('2/2/1');
|
||||
|
||||
tileUrl = tileSource.tileUrlFunction(
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 3));
|
||||
expect(tileUrl).to.eql('3/4/2');
|
||||
|
||||
tileUrl = tileSource.tileUrlFunction(
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 4));
|
||||
expect(tileUrl).to.eql('4/8/5');
|
||||
|
||||
tileUrl = tileSource.tileUrlFunction(
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 5));
|
||||
expect(tileUrl).to.eql('5/16/11');
|
||||
|
||||
tileUrl = tileSource.tileUrlFunction(
|
||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 6));
|
||||
expect(tileUrl).to.eql('6/33/22');
|
||||
|
||||
});
|
||||
|
||||
describe('wrap x', function() {
|
||||
|
||||
it('returns the expected URL', function() {
|
||||
var projection = tileSource.getProjection();
|
||||
var tileUrl = tileSource.tileUrlFunction(
|
||||
tileSource.getTileCoordForTileUrlFunction(
|
||||
[6, -31, -23], projection));
|
||||
expect(tileUrl).to.eql('6/33/22');
|
||||
|
||||
tileUrl = tileSource.tileUrlFunction(
|
||||
tileSource.getTileCoordForTileUrlFunction(
|
||||
[6, 33, -23], projection));
|
||||
expect(tileUrl).to.eql('6/33/22');
|
||||
|
||||
tileUrl = tileSource.tileUrlFunction(
|
||||
tileSource.getTileCoordForTileUrlFunction(
|
||||
[6, 97, -23], projection));
|
||||
expect(tileUrl).to.eql('6/33/22');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('crop y', function() {
|
||||
|
||||
it('returns the expected URL', function() {
|
||||
var projection = tileSource.getProjection();
|
||||
var tileUrl = tileSource.tileUrlFunction(
|
||||
tileSource.getTileCoordForTileUrlFunction(
|
||||
[6, 33, 0], projection));
|
||||
expect(tileUrl).to.be(undefined);
|
||||
|
||||
tileUrl = tileSource.tileUrlFunction(
|
||||
tileSource.getTileCoordForTileUrlFunction(
|
||||
[6, 33, -23], projection));
|
||||
expect(tileUrl).to.eql('6/33/22');
|
||||
|
||||
tileUrl = tileSource.tileUrlFunction(
|
||||
tileSource.getTileCoordForTileUrlFunction(
|
||||
[6, 33, -65], projection));
|
||||
expect(tileUrl).to.be(undefined);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getUrls', function() {
|
||||
|
||||
var sourceOptions;
|
||||
var source;
|
||||
var url = 'http://geo.nls.uk/maps/towns/glasgow1857/{z}/{x}/{-y}.png';
|
||||
|
||||
beforeEach(function() {
|
||||
sourceOptions = {
|
||||
tileGrid: ol.tilegrid.createXYZ({
|
||||
extent: ol.proj.get('EPSG:4326').getExtent()
|
||||
})
|
||||
};
|
||||
});
|
||||
|
||||
describe('using a "url" option', function() {
|
||||
beforeEach(function() {
|
||||
sourceOptions.url = url;
|
||||
source = new ol.source.UrlTile(sourceOptions);
|
||||
});
|
||||
|
||||
it('returns the XYZ URL', function() {
|
||||
var urls = source.getUrls();
|
||||
expect(urls).to.be.eql([url]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('using a "urls" option', function() {
|
||||
beforeEach(function() {
|
||||
sourceOptions.urls = ['some_xyz_url1', 'some_xyz_url2'];
|
||||
source = new ol.source.UrlTile(sourceOptions);
|
||||
});
|
||||
|
||||
it('returns the XYZ URLs', function() {
|
||||
var urls = source.getUrls();
|
||||
expect(urls).to.be.eql(['some_xyz_url1', 'some_xyz_url2']);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('using a "tileUrlFunction"', function() {
|
||||
beforeEach(function() {
|
||||
sourceOptions.tileUrlFunction = function() {
|
||||
return 'some_xyz_url';
|
||||
};
|
||||
source = new ol.source.UrlTile(sourceOptions);
|
||||
});
|
||||
|
||||
it('returns null', function() {
|
||||
var urls = source.getUrls();
|
||||
expect(urls).to.be(null);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.TileCoord');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.source.UrlTile');
|
||||
43
test/spec/ol/source/vectortilesource.test.js
Normal file
43
test/spec/ol/source/vectortilesource.test.js
Normal file
@@ -0,0 +1,43 @@
|
||||
goog.provide('ol.test.source.VectorTile');
|
||||
|
||||
|
||||
describe('ol.source.VectorTile', function() {
|
||||
|
||||
var format = new ol.format.MVT();
|
||||
var source = new ol.source.VectorTile({
|
||||
format: format,
|
||||
tileGrid: ol.tilegrid.createXYZ(),
|
||||
url: '{z}/{x}/{y}.pbf'
|
||||
});
|
||||
var tile;
|
||||
|
||||
describe('constructor', function() {
|
||||
it('sets the format on the instance', function() {
|
||||
expect(source.format_).to.equal(format);
|
||||
});
|
||||
it('uses ol.VectorTile as default tileClass', function() {
|
||||
expect(source.tileClass).to.equal(ol.VectorTile);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getTile()', function() {
|
||||
it('creates a tile with the correct tile class', function() {
|
||||
tile = source.getTile(0, 0, 0, 1, ol.proj.get('EPSG:3857'));
|
||||
expect(tile).to.be.a(ol.VectorTile);
|
||||
});
|
||||
it('sets the correct tileCoord on the created tile', function() {
|
||||
expect(tile.getTileCoord()).to.eql([0, 0, 0]);
|
||||
});
|
||||
it('fetches tile from cache when requested again', function() {
|
||||
expect(source.getTile(0, 0, 0, 1, ol.proj.get('EPSG:3857')))
|
||||
.to.equal(tile);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
goog.require('ol.VectorTile');
|
||||
goog.require('ol.format.MVT');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.source.VectorTile');
|
||||
Reference in New Issue
Block a user