Merge pull request #7791 from marcjansen/tilecoord-refactor

Named exports from ol/tilecoord
This commit is contained in:
Marc Jansen
2018-02-15 22:01:43 +01:00
committed by GitHub
20 changed files with 97 additions and 116 deletions

View File

@@ -5,7 +5,7 @@ import Layer from '../../../../src/ol/layer/Layer.js';
import TileLayer from '../../../../src/ol/layer/Tile.js';
import LayerRenderer from '../../../../src/ol/renderer/Layer.js';
import XYZ from '../../../../src/ol/source/XYZ.js';
import _ol_tilecoord_ from '../../../../src/ol/tilecoord.js';
import {fromKey} from '../../../../src/ol/tilecoord.js';
describe('ol.renderer.Layer', function() {
@@ -129,13 +129,13 @@ describe('ol.renderer.Layer', function() {
it('accesses tiles from current zoom level last', function(done) {
// expect most recent tile in the cache to be from zoom level 0
const key = source.tileCache.peekFirstKey();
const tileCoord = _ol_tilecoord_.fromKey(key);
const tileCoord = fromKey(key);
expect(tileCoord[0]).to.be(0);
map.once('moveend', function() {
// expect most recent tile in the cache to be from zoom level 4
const key = source.tileCache.peekFirstKey();
const tileCoord = _ol_tilecoord_.fromKey(key);
const tileCoord = fromKey(key);
expect(tileCoord[0]).to.be(4);
done();
});

View File

@@ -1,5 +1,5 @@
import BingMaps from '../../../../src/ol/source/BingMaps.js';
import _ol_tilecoord_ from '../../../../src/ol/tilecoord.js';
import {quadKey} from '../../../../src/ol/tilecoord.js';
import Observable from '../../../../src/ol/Observable.js';
@@ -48,28 +48,28 @@ describe('ol.source.BingMaps', function() {
tileUrl = source.tileUrlFunction(
tileGrid.getTileCoordForCoordAndZ(coordinate, 1), 1, projection);
expect(tileUrl.match(regex)[1]).to.equal(_ol_tilecoord_.quadKey([1, 1, 0]));
expect(tileUrl.match(regex)[1]).to.equal(quadKey([1, 1, 0]));
tileUrl = source.tileUrlFunction(
tileGrid.getTileCoordForCoordAndZ(coordinate, 2), 1, projection);
expect(tileUrl.match(regex)[1]).to.equal(_ol_tilecoord_.quadKey([2, 2, 1]));
expect(tileUrl.match(regex)[1]).to.equal(quadKey([2, 2, 1]));
tileUrl = source.tileUrlFunction(
tileGrid.getTileCoordForCoordAndZ(coordinate, 3), 1, projection);
expect(tileUrl.match(regex)[1]).to.equal(_ol_tilecoord_.quadKey([3, 4, 2]));
expect(tileUrl.match(regex)[1]).to.equal(quadKey([3, 4, 2]));
tileUrl = source.tileUrlFunction(
tileGrid.getTileCoordForCoordAndZ(coordinate, 4), 1, projection);
expect(tileUrl.match(regex)[1]).to.equal(_ol_tilecoord_.quadKey([4, 8, 5]));
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(_ol_tilecoord_.quadKey(
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(_ol_tilecoord_.quadKey(
expect(tileUrl.match(regex)[1]).to.equal(quadKey(
[6, 33, 22]));
});

View File

@@ -5,7 +5,7 @@ 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 TileSource from '../../../../src/ol/source/Tile.js';
import _ol_tilecoord_ from '../../../../src/ol/tilecoord.js';
import {getKeyZXY} from '../../../../src/ol/tilecoord.js';
import TileGrid from '../../../../src/ol/tilegrid/TileGrid.js';
@@ -42,7 +42,7 @@ inherits(MockTile, TileSource);
* @inheritDoc
*/
MockTile.prototype.getTile = function(z, x, y) {
const key = _ol_tilecoord_.getKeyZXY(z, x, y);
const key = getKeyZXY(z, x, y);
if (this.tileCache.containsKey(key)) {
return /** @type {!ol.Tile} */ (this.tileCache.get(key));
} else {

View File

@@ -8,7 +8,7 @@ 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 _ol_tilecoord_ from '../../../../src/ol/tilecoord.js';
import {getKeyZXY} from '../../../../src/ol/tilecoord.js';
import {createXYZ, createForProjection} from '../../../../src/ol/tilegrid.js';
@@ -51,7 +51,7 @@ describe('ol.source.TileImage', function() {
expect(source.getKey()).to.be('');
source.getTileInternal(0, 0, -1, 1, getProjection('EPSG:3857'));
expect(source.tileCache.getCount()).to.be(1);
tile = source.tileCache.get(_ol_tilecoord_.getKeyZXY(0, 0, -1));
tile = source.tileCache.get(getKeyZXY(0, 0, -1));
});
it('gets the tile from the cache', function() {

View File

@@ -1,6 +1,6 @@
import Tile from '../../../src/ol/Tile.js';
import TileCache from '../../../src/ol/TileCache.js';
import _ol_tilecoord_ from '../../../src/ol/tilecoord.js';
import {getKey} from '../../../src/ol/tilecoord.js';
describe('ol.TileCache', function() {
@@ -21,7 +21,7 @@ describe('ol.TileCache', function() {
sinon.spy(tiles[0], 'dispose');
tiles.forEach(function(tile) {
cache.set(_ol_tilecoord_.getKey(tile.tileCoord), tile);
cache.set(getKey(tile.tileCoord), tile);
});
cache.pruneExceptNewestZ();

View File

@@ -1,4 +1,10 @@
import _ol_tilecoord_ from '../../../src/ol/tilecoord.js';
import {
quadKey,
getKey,
fromKey,
hash,
withinExtentAndZ
} from '../../../src/ol/tilecoord.js';
import TileGrid from '../../../src/ol/tilegrid/TileGrid.js';
@@ -16,14 +22,14 @@ describe('ol.TileCoord', function() {
describe('call quadKey', function() {
it('returns expected string', function() {
const tileCoord = [3, 3, 5];
const s = _ol_tilecoord_.quadKey(tileCoord);
const s = quadKey(tileCoord);
expect(s).to.eql('213');
});
});
describe('getKey()', function() {
it('returns a key for a tile coord', function() {
const key = _ol_tilecoord_.getKey([1, 2, 3]);
const key = getKey([1, 2, 3]);
expect(key).to.eql('1/2/3');
});
});
@@ -31,9 +37,9 @@ describe('ol.TileCoord', function() {
describe('fromKey()', function() {
it('returns a tile coord given a key', function() {
const tileCoord = [1, 2, 3];
const key = _ol_tilecoord_.getKey(tileCoord);
const key = getKey(tileCoord);
const returned = _ol_tilecoord_.fromKey(key);
const returned = fromKey(key);
expect(returned).to.eql(tileCoord);
});
});
@@ -42,8 +48,8 @@ describe('ol.TileCoord', function() {
it('produces different hashes for different tile coords', function() {
const tileCoord1 = [3, 2, 1];
const tileCoord2 = [3, 1, 1];
expect(_ol_tilecoord_.hash(tileCoord1)).not.to.eql(
_ol_tilecoord_.hash(tileCoord2));
expect(hash(tileCoord1)).not.to.eql(
hash(tileCoord2));
});
});
@@ -56,9 +62,9 @@ describe('ol.TileCoord', function() {
resolutions: [2, 1],
minZoom: 1
});
expect(_ol_tilecoord_.withinExtentAndZ([0, 0, -1], tileGrid)).to.be(false);
expect(_ol_tilecoord_.withinExtentAndZ([1, 0, -1], tileGrid)).to.be(true);
expect(_ol_tilecoord_.withinExtentAndZ([2, 0, -1], tileGrid)).to.be(false);
expect(withinExtentAndZ([0, 0, -1], tileGrid)).to.be(false);
expect(withinExtentAndZ([1, 0, -1], tileGrid)).to.be(true);
expect(withinExtentAndZ([2, 0, -1], tileGrid)).to.be(false);
});
it('restricts by extent when extent defines tile ranges', function() {
@@ -68,9 +74,9 @@ describe('ol.TileCoord', function() {
tileSize: 10,
resolutions: [1]
});
expect(_ol_tilecoord_.withinExtentAndZ([0, 1, -2], tileGrid)).to.be(true);
expect(_ol_tilecoord_.withinExtentAndZ([0, 2, -1], tileGrid)).to.be(false);
expect(_ol_tilecoord_.withinExtentAndZ([0, 0, -3], tileGrid)).to.be(false);
expect(withinExtentAndZ([0, 1, -2], tileGrid)).to.be(true);
expect(withinExtentAndZ([0, 2, -1], tileGrid)).to.be(false);
expect(withinExtentAndZ([0, 0, -3], tileGrid)).to.be(false);
});
it('restricts by extent when sizes define tile ranges', function() {
@@ -80,12 +86,12 @@ describe('ol.TileCoord', function() {
tileSize: 10,
resolutions: [1]
});
expect(_ol_tilecoord_.withinExtentAndZ([0, 0, 0], tileGrid)).to.be(true);
expect(_ol_tilecoord_.withinExtentAndZ([0, -1, 0], tileGrid)).to.be(false);
expect(_ol_tilecoord_.withinExtentAndZ([0, 0, -1], tileGrid)).to.be(false);
expect(_ol_tilecoord_.withinExtentAndZ([0, 2, 2], tileGrid)).to.be(true);
expect(_ol_tilecoord_.withinExtentAndZ([0, 3, 0], tileGrid)).to.be(false);
expect(_ol_tilecoord_.withinExtentAndZ([0, 0, 3], tileGrid)).to.be(false);
expect(withinExtentAndZ([0, 0, 0], tileGrid)).to.be(true);
expect(withinExtentAndZ([0, -1, 0], tileGrid)).to.be(false);
expect(withinExtentAndZ([0, 0, -1], tileGrid)).to.be(false);
expect(withinExtentAndZ([0, 2, 2], tileGrid)).to.be(true);
expect(withinExtentAndZ([0, 3, 0], tileGrid)).to.be(false);
expect(withinExtentAndZ([0, 0, 3], tileGrid)).to.be(false);
});
it('restricts by extent when sizes (neg y) define tile ranges', function() {
@@ -95,12 +101,12 @@ describe('ol.TileCoord', function() {
tileSize: 10,
resolutions: [1]
});
expect(_ol_tilecoord_.withinExtentAndZ([0, 0, -1], tileGrid)).to.be(true);
expect(_ol_tilecoord_.withinExtentAndZ([0, -1, -1], tileGrid)).to.be(false);
expect(_ol_tilecoord_.withinExtentAndZ([0, 0, 0], tileGrid)).to.be(false);
expect(_ol_tilecoord_.withinExtentAndZ([0, 2, -3], tileGrid)).to.be(true);
expect(_ol_tilecoord_.withinExtentAndZ([0, 3, -1], tileGrid)).to.be(false);
expect(_ol_tilecoord_.withinExtentAndZ([0, 0, -4], tileGrid)).to.be(false);
expect(withinExtentAndZ([0, 0, -1], tileGrid)).to.be(true);
expect(withinExtentAndZ([0, -1, -1], tileGrid)).to.be(false);
expect(withinExtentAndZ([0, 0, 0], tileGrid)).to.be(false);
expect(withinExtentAndZ([0, 2, -3], tileGrid)).to.be(true);
expect(withinExtentAndZ([0, 3, -1], tileGrid)).to.be(false);
expect(withinExtentAndZ([0, 0, -4], tileGrid)).to.be(false);
});
it('does not restrict by extent with no extent or sizes', function() {
@@ -109,13 +115,13 @@ describe('ol.TileCoord', function() {
tileSize: 10,
resolutions: [1]
});
expect(_ol_tilecoord_.withinExtentAndZ([0, Infinity, 0], tileGrid))
expect(withinExtentAndZ([0, Infinity, 0], tileGrid))
.to.be(true);
expect(_ol_tilecoord_.withinExtentAndZ([0, 0, Infinity], tileGrid))
expect(withinExtentAndZ([0, 0, Infinity], tileGrid))
.to.be(true);
expect(_ol_tilecoord_.withinExtentAndZ([0, -Infinity, 0], tileGrid))
expect(withinExtentAndZ([0, -Infinity, 0], tileGrid))
.to.be(true);
expect(_ol_tilecoord_.withinExtentAndZ([0, 0, Infinity], tileGrid))
expect(withinExtentAndZ([0, 0, Infinity], tileGrid))
.to.be(true);
});
});

View File

@@ -1,5 +1,4 @@
import {expandUrl, createFromTemplate, createFromTemplates, createFromTileUrlFunctions} from '../../../src/ol/tileurlfunction.js';
import _ol_tilecoord_ from '../../../src/ol/tilecoord.js';
import {createXYZ} from '../../../src/ol/tilegrid.js';
import TileGrid from '../../../src/ol/tilegrid/TileGrid.js';
@@ -78,32 +77,12 @@ describe('ol.TileUrlFunction', function() {
const tileGrid = createXYZ();
it('creates expected URL', function() {
const templates = [
'http://tile-1/{z}/{x}/{y}',
'http://tile-2/{z}/{x}/{y}',
'http://tile-3/{z}/{x}/{y}'
'http://tile-1/{z}/{x}/{y}'
];
const tileUrlFunction = createFromTemplates(templates, tileGrid);
const tileCoord = [3, 2, -2];
/* eslint-disable openlayers-internal/no-missing-requires */
sinon.stub(_ol_tilecoord_, 'hash').callsFake(function() {
return 3;
});
expect(tileUrlFunction(tileCoord)).to.eql('http://tile-1/3/2/1');
_ol_tilecoord_.hash.restore();
sinon.stub(_ol_tilecoord_, 'hash').callsFake(function() {
return 2;
});
expect(tileUrlFunction(tileCoord)).to.eql('http://tile-3/3/2/1');
_ol_tilecoord_.hash.restore();
sinon.stub(_ol_tilecoord_, 'hash').callsFake(function() {
return 1;
});
expect(tileUrlFunction(tileCoord)).to.eql('http://tile-2/3/2/1');
_ol_tilecoord_.hash.restore();
/* eslint-enable */
});
});