Merge pull request #7791 from marcjansen/tilecoord-refactor
Named exports from ol/tilecoord
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
import {inherits} from './index.js';
|
||||
import LRUCache from './structs/LRUCache.js';
|
||||
import _ol_tilecoord_ from './tilecoord.js';
|
||||
import {fromKey, getKey} from './tilecoord.js';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
@@ -45,11 +45,11 @@ TileCache.prototype.pruneExceptNewestZ = function() {
|
||||
return;
|
||||
}
|
||||
const key = this.peekFirstKey();
|
||||
const tileCoord = _ol_tilecoord_.fromKey(key);
|
||||
const tileCoord = fromKey(key);
|
||||
const z = tileCoord[0];
|
||||
this.forEach(function(tile) {
|
||||
if (tile.tileCoord[0] !== z) {
|
||||
this.remove(_ol_tilecoord_.getKey(tile.tileCoord));
|
||||
this.remove(getKey(tile.tileCoord));
|
||||
tile.dispose();
|
||||
}
|
||||
}, this);
|
||||
|
||||
@@ -8,7 +8,7 @@ import {jsonp as requestJSONP} from '../net.js';
|
||||
import {get as getProjection, getTransformFromProjections} from '../proj.js';
|
||||
import SourceState from '../source/State.js';
|
||||
import TileImage from '../source/TileImage.js';
|
||||
import _ol_tilecoord_ from '../tilecoord.js';
|
||||
import {createOrUpdate, quadKey} from '../tilecoord.js';
|
||||
import {createXYZ, extentFromProjection} from '../tilegrid.js';
|
||||
|
||||
/**
|
||||
@@ -159,14 +159,12 @@ BingMaps.prototype.handleImageryMetadataResponse = function(response) {
|
||||
if (!tileCoord) {
|
||||
return undefined;
|
||||
} else {
|
||||
_ol_tilecoord_.createOrUpdate(tileCoord[0], tileCoord[1],
|
||||
-tileCoord[2] - 1, quadKeyTileCoord);
|
||||
createOrUpdate(tileCoord[0], tileCoord[1], -tileCoord[2] - 1, quadKeyTileCoord);
|
||||
let url = imageUrl;
|
||||
if (hidpi) {
|
||||
url += '&dpi=d1&device=mobile';
|
||||
}
|
||||
return url.replace('{quadkey}', _ol_tilecoord_.quadKey(
|
||||
quadKeyTileCoord));
|
||||
return url.replace('{quadkey}', quadKey(quadKeyTileCoord));
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@@ -8,7 +8,7 @@ import Event from '../events/Event.js';
|
||||
import {equivalent} from '../proj.js';
|
||||
import {toSize, scale as scaleSize} from '../size.js';
|
||||
import Source from '../source/Source.js';
|
||||
import _ol_tilecoord_ from '../tilecoord.js';
|
||||
import {getKeyZXY, withinExtentAndZ} from '../tilecoord.js';
|
||||
import {wrapX, getForProjection as getTileGridForProjection} from '../tilegrid.js';
|
||||
|
||||
/**
|
||||
@@ -120,7 +120,7 @@ TileSource.prototype.forEachLoadedTile = function(projection, z, tileRange, call
|
||||
let tile, tileCoordKey, loaded;
|
||||
for (let x = tileRange.minX; x <= tileRange.maxX; ++x) {
|
||||
for (let y = tileRange.minY; y <= tileRange.maxY; ++y) {
|
||||
tileCoordKey = _ol_tilecoord_.getKeyZXY(z, x, y);
|
||||
tileCoordKey = getKeyZXY(z, x, y);
|
||||
loaded = false;
|
||||
if (tileCache.containsKey(tileCoordKey)) {
|
||||
tile = /** @type {!ol.Tile} */ (tileCache.get(tileCoordKey));
|
||||
@@ -283,7 +283,7 @@ TileSource.prototype.getTileCoordForTileUrlFunction = function(tileCoord, opt_pr
|
||||
if (this.getWrapX() && projection.isGlobal()) {
|
||||
tileCoord = wrapX(tileGrid, tileCoord, projection);
|
||||
}
|
||||
return _ol_tilecoord_.withinExtentAndZ(tileCoord, tileGrid) ? tileCoord : null;
|
||||
return withinExtentAndZ(tileCoord, tileGrid) ? tileCoord : null;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import {modulo} from '../math.js';
|
||||
import {assign} from '../obj.js';
|
||||
import {toSize, scale as scaleSize} from '../size.js';
|
||||
import TileImage from '../source/TileImage.js';
|
||||
import _ol_tilecoord_ from '../tilecoord.js';
|
||||
import {hash as tileCoordHash} from '../tilecoord.js';
|
||||
import {appendParams} from '../uri.js';
|
||||
|
||||
/**
|
||||
@@ -118,7 +118,7 @@ TileArcGISRest.prototype.getRequestUrl_ = function(tileCoord, tileSize, tileExte
|
||||
if (urls.length == 1) {
|
||||
url = urls[0];
|
||||
} else {
|
||||
const index = modulo(_ol_tilecoord_.hash(tileCoord), urls.length);
|
||||
const index = modulo(tileCoordHash(tileCoord), urls.length);
|
||||
url = urls[index];
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import TileState from '../TileState.js';
|
||||
import {createCanvasContext2D} from '../dom.js';
|
||||
import {toSize} from '../size.js';
|
||||
import TileSource from '../source/Tile.js';
|
||||
import _ol_tilecoord_ from '../tilecoord.js';
|
||||
import {getKeyZXY} from '../tilecoord.js';
|
||||
|
||||
|
||||
/**
|
||||
@@ -106,7 +106,7 @@ inherits(TileDebug, TileSource);
|
||||
* @inheritDoc
|
||||
*/
|
||||
TileDebug.prototype.getTile = function(z, x, y) {
|
||||
const tileCoordKey = _ol_tilecoord_.getKeyZXY(z, x, y);
|
||||
const tileCoordKey = getKeyZXY(z, x, y);
|
||||
if (this.tileCache.containsKey(tileCoordKey)) {
|
||||
return /** @type {!ol.source.LabeledTile} */ (this.tileCache.get(tileCoordKey));
|
||||
} else {
|
||||
|
||||
@@ -11,7 +11,7 @@ import EventType from '../events/EventType.js';
|
||||
import {equivalent, get as getProjection} from '../proj.js';
|
||||
import ReprojTile from '../reproj/Tile.js';
|
||||
import UrlTile from '../source/UrlTile.js';
|
||||
import _ol_tilecoord_ from '../tilecoord.js';
|
||||
import {getKey, getKeyZXY} from '../tilecoord.js';
|
||||
import {getForProjection as getTileGridForProjection} from '../tilegrid.js';
|
||||
|
||||
/**
|
||||
@@ -242,7 +242,7 @@ TileImage.prototype.getTile = function(z, x, y, pixelRatio, projection) {
|
||||
const cache = this.getTileCacheForProjection(projection);
|
||||
const tileCoord = [z, x, y];
|
||||
let tile;
|
||||
const tileCoordKey = _ol_tilecoord_.getKey(tileCoord);
|
||||
const tileCoordKey = getKey(tileCoord);
|
||||
if (cache.containsKey(tileCoordKey)) {
|
||||
tile = /** @type {!ol.Tile} */ (cache.get(tileCoordKey));
|
||||
}
|
||||
@@ -289,7 +289,7 @@ TileImage.prototype.getTile = function(z, x, y, pixelRatio, projection) {
|
||||
*/
|
||||
TileImage.prototype.getTileInternal = function(z, x, y, pixelRatio, projection) {
|
||||
let tile = null;
|
||||
const tileCoordKey = _ol_tilecoord_.getKeyZXY(z, x, y);
|
||||
const tileCoordKey = getKeyZXY(z, x, y);
|
||||
const key = this.getKey();
|
||||
if (!this.tileCache.containsKey(tileCoordKey)) {
|
||||
tile = this.createTile_(z, x, y, pixelRatio, projection, key);
|
||||
|
||||
@@ -13,7 +13,7 @@ import {jsonp as requestJSONP} from '../net.js';
|
||||
import {get as getProjection, getTransformFromProjections} from '../proj.js';
|
||||
import SourceState from '../source/State.js';
|
||||
import TileSource from '../source/Tile.js';
|
||||
import _ol_tilecoord_ from '../tilecoord.js';
|
||||
import {getKeyZXY} from '../tilecoord.js';
|
||||
import {createXYZ, extentFromProjection} from '../tilegrid.js';
|
||||
|
||||
|
||||
@@ -447,7 +447,7 @@ UTFGrid.prototype.handleTileJSONResponse = function(tileJSON) {
|
||||
* @inheritDoc
|
||||
*/
|
||||
UTFGrid.prototype.getTile = function(z, x, y, pixelRatio, projection) {
|
||||
const tileCoordKey = _ol_tilecoord_.getKeyZXY(z, x, y);
|
||||
const tileCoordKey = getKeyZXY(z, x, y);
|
||||
if (this.tileCache.containsKey(tileCoordKey)) {
|
||||
return /** @type {!ol.Tile} */ (this.tileCache.get(tileCoordKey));
|
||||
} else {
|
||||
@@ -472,7 +472,7 @@ UTFGrid.prototype.getTile = function(z, x, y, pixelRatio, projection) {
|
||||
* @inheritDoc
|
||||
*/
|
||||
UTFGrid.prototype.useTile = function(z, x, y) {
|
||||
const tileCoordKey = _ol_tilecoord_.getKeyZXY(z, x, y);
|
||||
const tileCoordKey = getKeyZXY(z, x, y);
|
||||
if (this.tileCache.containsKey(tileCoordKey)) {
|
||||
this.tileCache.get(tileCoordKey);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import {calculateSourceResolution} from '../reproj.js';
|
||||
import {toSize, buffer as bufferSize, scale as scaleSize} from '../size.js';
|
||||
import TileImage from '../source/TileImage.js';
|
||||
import WMSServerType from '../source/WMSServerType.js';
|
||||
import _ol_tilecoord_ from '../tilecoord.js';
|
||||
import {hash as tileCoordHash} from '../tilecoord.js';
|
||||
import {compareVersions} from '../string.js';
|
||||
import {appendParams} from '../uri.js';
|
||||
|
||||
@@ -247,7 +247,7 @@ TileWMS.prototype.getRequestUrl_ = function(tileCoord, tileSize, tileExtent,
|
||||
if (urls.length == 1) {
|
||||
url = urls[0];
|
||||
} else {
|
||||
const index = modulo(_ol_tilecoord_.hash(tileCoord), urls.length);
|
||||
const index = modulo(tileCoordHash(tileCoord), urls.length);
|
||||
url = urls[index];
|
||||
}
|
||||
return appendParams(url, params);
|
||||
|
||||
@@ -6,7 +6,7 @@ import TileState from '../TileState.js';
|
||||
import {expandUrl, createFromTemplates, nullTileUrlFunction} from '../tileurlfunction.js';
|
||||
import TileSource from '../source/Tile.js';
|
||||
import TileEventType from '../source/TileEventType.js';
|
||||
import _ol_tilecoord_ from '../tilecoord.js';
|
||||
import {getKeyZXY} from '../tilecoord.js';
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
@@ -195,7 +195,7 @@ UrlTile.prototype.setUrls = function(urls) {
|
||||
* @inheritDoc
|
||||
*/
|
||||
UrlTile.prototype.useTile = function(z, x, y) {
|
||||
const tileCoordKey = _ol_tilecoord_.getKeyZXY(z, x, y);
|
||||
const tileCoordKey = getKeyZXY(z, x, y);
|
||||
if (this.tileCache.containsKey(tileCoordKey)) {
|
||||
this.tileCache.get(tileCoordKey);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import VectorImageTile, {defaultLoadFunction} from '../VectorImageTile.js';
|
||||
import VectorTile from '../VectorTile.js';
|
||||
import {toSize} from '../size.js';
|
||||
import UrlTile from '../source/UrlTile.js';
|
||||
import _ol_tilecoord_ from '../tilecoord.js';
|
||||
import {getKeyZXY} from '../tilecoord.js';
|
||||
import {createXYZ, extentFromProjection, createForProjection} from '../tilegrid.js';
|
||||
|
||||
/**
|
||||
@@ -110,7 +110,7 @@ VectorTileSource.prototype.clear = function() {
|
||||
* @inheritDoc
|
||||
*/
|
||||
VectorTileSource.prototype.getTile = function(z, x, y, pixelRatio, projection) {
|
||||
const tileCoordKey = _ol_tilecoord_.getKeyZXY(z, x, y);
|
||||
const tileCoordKey = getKeyZXY(z, x, y);
|
||||
if (this.tileCache.containsKey(tileCoordKey)) {
|
||||
return /** @type {!ol.Tile} */ (this.tileCache.get(tileCoordKey));
|
||||
} else {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/**
|
||||
* @module ol/tilecoord
|
||||
*/
|
||||
const _ol_tilecoord_ = {};
|
||||
|
||||
|
||||
/**
|
||||
@@ -11,7 +10,7 @@ const _ol_tilecoord_ = {};
|
||||
* @param {ol.TileCoord=} opt_tileCoord Tile coordinate.
|
||||
* @return {ol.TileCoord} Tile coordinate.
|
||||
*/
|
||||
_ol_tilecoord_.createOrUpdate = function(z, x, y, opt_tileCoord) {
|
||||
export function createOrUpdate(z, x, y, opt_tileCoord) {
|
||||
if (opt_tileCoord !== undefined) {
|
||||
opt_tileCoord[0] = z;
|
||||
opt_tileCoord[1] = x;
|
||||
@@ -20,7 +19,7 @@ _ol_tilecoord_.createOrUpdate = function(z, x, y, opt_tileCoord) {
|
||||
} else {
|
||||
return [z, x, y];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -29,9 +28,9 @@ _ol_tilecoord_.createOrUpdate = function(z, x, y, opt_tileCoord) {
|
||||
* @param {number} y Y.
|
||||
* @return {string} Key.
|
||||
*/
|
||||
_ol_tilecoord_.getKeyZXY = function(z, x, y) {
|
||||
export function getKeyZXY(z, x, y) {
|
||||
return z + '/' + x + '/' + y;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -39,9 +38,9 @@ _ol_tilecoord_.getKeyZXY = function(z, x, y) {
|
||||
* @param {ol.TileCoord} tileCoord The tile coord.
|
||||
* @return {string} Key.
|
||||
*/
|
||||
_ol_tilecoord_.getKey = function(tileCoord) {
|
||||
return _ol_tilecoord_.getKeyZXY(tileCoord[0], tileCoord[1], tileCoord[2]);
|
||||
};
|
||||
export function getKey(tileCoord) {
|
||||
return getKeyZXY(tileCoord[0], tileCoord[1], tileCoord[2]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -49,25 +48,25 @@ _ol_tilecoord_.getKey = function(tileCoord) {
|
||||
* @param {string} key The tile coord key.
|
||||
* @return {ol.TileCoord} The tile coord.
|
||||
*/
|
||||
_ol_tilecoord_.fromKey = function(key) {
|
||||
export function fromKey(key) {
|
||||
return key.split('/').map(Number);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.TileCoord} tileCoord Tile coord.
|
||||
* @return {number} Hash.
|
||||
*/
|
||||
_ol_tilecoord_.hash = function(tileCoord) {
|
||||
export function hash(tileCoord) {
|
||||
return (tileCoord[1] << tileCoord[0]) + tileCoord[2];
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.TileCoord} tileCoord Tile coord.
|
||||
* @return {string} Quad key.
|
||||
*/
|
||||
_ol_tilecoord_.quadKey = function(tileCoord) {
|
||||
export function quadKey(tileCoord) {
|
||||
const z = tileCoord[0];
|
||||
const digits = new Array(z);
|
||||
let mask = 1 << (z - 1);
|
||||
@@ -85,7 +84,7 @@ _ol_tilecoord_.quadKey = function(tileCoord) {
|
||||
mask >>= 1;
|
||||
}
|
||||
return digits.join('');
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -93,7 +92,7 @@ _ol_tilecoord_.quadKey = function(tileCoord) {
|
||||
* @param {!ol.tilegrid.TileGrid} tileGrid Tile grid.
|
||||
* @return {boolean} Tile coordinate is within extent and zoom level range.
|
||||
*/
|
||||
_ol_tilecoord_.withinExtentAndZ = function(tileCoord, tileGrid) {
|
||||
export function withinExtentAndZ(tileCoord, tileGrid) {
|
||||
const z = tileCoord[0];
|
||||
const x = tileCoord[1];
|
||||
const y = tileCoord[2];
|
||||
@@ -113,5 +112,4 @@ _ol_tilecoord_.withinExtentAndZ = function(tileCoord, tileGrid) {
|
||||
} else {
|
||||
return tileRange.containsXY(x, y);
|
||||
}
|
||||
};
|
||||
export default _ol_tilecoord_;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import {isSorted, linearFindNearest} from '../array.js';
|
||||
import {createOrUpdate, getTopLeft} from '../extent.js';
|
||||
import {clamp} from '../math.js';
|
||||
import {toSize} from '../size.js';
|
||||
import _ol_tilecoord_ from '../tilecoord.js';
|
||||
import {createOrUpdate as tileCoordCreateOrUpdate} from '../tilecoord.js';
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
@@ -422,7 +422,7 @@ TileGrid.prototype.getTileCoordForXYAndResolution_ = function(
|
||||
tileCoordY = Math.floor(tileCoordY);
|
||||
}
|
||||
|
||||
return _ol_tilecoord_.createOrUpdate(z, tileCoordX, tileCoordY, opt_tileCoord);
|
||||
return tileCoordCreateOrUpdate(z, tileCoordX, tileCoordY, opt_tileCoord);
|
||||
};
|
||||
|
||||
|
||||
@@ -461,7 +461,7 @@ TileGrid.prototype.getTileCoordForXYAndZ_ = function(x, y, z, reverseIntersectio
|
||||
tileCoordY = Math.floor(tileCoordY);
|
||||
}
|
||||
|
||||
return _ol_tilecoord_.createOrUpdate(z, tileCoordX, tileCoordY, opt_tileCoord);
|
||||
return tileCoordCreateOrUpdate(z, tileCoordX, tileCoordY, opt_tileCoord);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
import {assert} from './asserts.js';
|
||||
import {modulo} from './math.js';
|
||||
import _ol_tilecoord_ from './tilecoord.js';
|
||||
import {hash as tileCoordHash} from './tilecoord.js';
|
||||
|
||||
|
||||
/**
|
||||
@@ -80,7 +80,7 @@ export function createFromTileUrlFunctions(tileUrlFunctions) {
|
||||
if (!tileCoord) {
|
||||
return undefined;
|
||||
} else {
|
||||
const h = _ol_tilecoord_.hash(tileCoord);
|
||||
const h = tileCoordHash(tileCoord);
|
||||
const index = modulo(h, tileUrlFunctions.length);
|
||||
return tileUrlFunctions[index](tileCoord, pixelRatio, projection);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user