Named exports from ol/tilegrid

This commit is contained in:
Tim Schaub
2018-02-09 09:30:16 -07:00
parent 2779fe57ff
commit 9ed3881f34
26 changed files with 126 additions and 128 deletions

View File

@@ -9,7 +9,7 @@ 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 _ol_tilegrid_ from '../tilegrid.js';
import {createXYZ, extentFromProjection} from '../tilegrid.js';
/**
* @classdesc
@@ -129,10 +129,10 @@ BingMaps.prototype.handleImageryMetadataResponse = function(response) {
const maxZoom = this.maxZoom_ == -1 ? resource.zoomMax : this.maxZoom_;
const sourceProjection = this.getProjection();
const extent = _ol_tilegrid_.extentFromProjection(sourceProjection);
const extent = extentFromProjection(sourceProjection);
const tileSize = resource.imageWidth == resource.imageHeight ?
resource.imageWidth : [resource.imageWidth, resource.imageHeight];
const tileGrid = _ol_tilegrid_.createXYZ({
const tileGrid = createXYZ({
extent: extent,
minZoom: resource.zoomMin,
maxZoom: maxZoom,

View File

@@ -9,7 +9,7 @@ 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 _ol_tilegrid_ from '../tilegrid.js';
import {wrapX, getForProjection as getTileGridForProjection} from '../tilegrid.js';
/**
* @classdesc
@@ -215,7 +215,7 @@ TileSource.prototype.getTileGrid = function() {
*/
TileSource.prototype.getTileGridForProjection = function(projection) {
if (!this.tileGrid) {
return _ol_tilegrid_.getForProjection(projection);
return getTileGridForProjection(projection);
} else {
return this.tileGrid;
}
@@ -281,7 +281,7 @@ TileSource.prototype.getTileCoordForTileUrlFunction = function(tileCoord, opt_pr
opt_projection : this.getProjection();
const tileGrid = this.getTileGridForProjection(projection);
if (this.getWrapX() && projection.isGlobal()) {
tileCoord = _ol_tilegrid_.wrapX(tileGrid, tileCoord, projection);
tileCoord = wrapX(tileGrid, tileCoord, projection);
}
return _ol_tilecoord_.withinExtentAndZ(tileCoord, tileGrid) ? tileCoord : null;
};

View File

@@ -12,7 +12,7 @@ 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 _ol_tilegrid_ from '../tilegrid.js';
import {getForProjection as getTileGridForProjection} from '../tilegrid.js';
/**
* @classdesc
@@ -174,7 +174,7 @@ TileImage.prototype.getTileGridForProjection = function(projection) {
const projKey = getUid(projection).toString();
if (!(projKey in this.tileGridForProjection)) {
this.tileGridForProjection[projKey] =
_ol_tilegrid_.getForProjection(projection);
getTileGridForProjection(projection);
}
return /** @type {!ol.tilegrid.TileGrid} */ (this.tileGridForProjection[projKey]);
}

View File

@@ -15,7 +15,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_tilegrid_ from '../tilegrid.js';
import {createXYZ, extentFromProjection} from '../tilegrid.js';
/**
* @classdesc
@@ -126,8 +126,8 @@ TileJSON.prototype.handleTileJSONResponse = function(tileJSON) {
const minZoom = tileJSON.minzoom || 0;
const maxZoom = tileJSON.maxzoom || 22;
const tileGrid = _ol_tilegrid_.createXYZ({
extent: _ol_tilegrid_.extentFromProjection(sourceProjection),
const tileGrid = createXYZ({
extent: extentFromProjection(sourceProjection),
maxZoom: maxZoom,
minZoom: minZoom
});

View File

@@ -14,7 +14,7 @@ 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 _ol_tilegrid_ from '../tilegrid.js';
import {createXYZ, extentFromProjection} from '../tilegrid.js';
/**
* @classdesc
@@ -176,8 +176,8 @@ UTFGrid.prototype.handleTileJSONResponse = function(tileJSON) {
const minZoom = tileJSON.minzoom || 0;
const maxZoom = tileJSON.maxzoom || 22;
const tileGrid = _ol_tilegrid_.createXYZ({
extent: _ol_tilegrid_.extentFromProjection(sourceProjection),
const tileGrid = createXYZ({
extent: extentFromProjection(sourceProjection),
maxZoom: maxZoom,
minZoom: minZoom
});

View File

@@ -8,7 +8,7 @@ import VectorTile from '../VectorTile.js';
import {toSize} from '../size.js';
import UrlTile from '../source/UrlTile.js';
import _ol_tilecoord_ from '../tilecoord.js';
import _ol_tilegrid_ from '../tilegrid.js';
import {createXYZ, extentFromProjection, createForProjection} from '../tilegrid.js';
/**
* @classdesc
@@ -29,9 +29,9 @@ import _ol_tilegrid_ from '../tilegrid.js';
const VectorTileSource = function(options) {
const projection = options.projection || 'EPSG:3857';
const extent = options.extent || _ol_tilegrid_.extentFromProjection(projection);
const extent = options.extent || extentFromProjection(projection);
const tileGrid = options.tileGrid || _ol_tilegrid_.createXYZ({
const tileGrid = options.tileGrid || createXYZ({
extent: extent,
maxZoom: options.maxZoom || 22,
minZoom: options.minZoom,
@@ -143,7 +143,7 @@ VectorTileSource.prototype.getTileGridForProjection = function(projection) {
// A tile grid that matches the tile size of the source tile grid is more
// likely to have 1:1 relationships between source tiles and rendered tiles.
const sourceTileGrid = this.tileGrid;
tileGrid = this.tileGrids_[code] = _ol_tilegrid_.createForProjection(projection, undefined,
tileGrid = this.tileGrids_[code] = createForProjection(projection, undefined,
sourceTileGrid ? sourceTileGrid.getTileSize(sourceTileGrid.getMinZoom()) : undefined);
}
return tileGrid;

View File

@@ -3,7 +3,7 @@
*/
import {inherits} from '../index.js';
import TileImage from '../source/TileImage.js';
import _ol_tilegrid_ from '../tilegrid.js';
import {createXYZ, extentFromProjection} from '../tilegrid.js';
/**
* @classdesc
@@ -33,8 +33,8 @@ const XYZ = function(opt_options) {
options.projection : 'EPSG:3857';
const tileGrid = options.tileGrid !== undefined ? options.tileGrid :
_ol_tilegrid_.createXYZ({
extent: _ol_tilegrid_.extentFromProjection(projection),
createXYZ({
extent: extentFromProjection(projection),
maxZoom: options.maxZoom,
minZoom: options.minZoom,
tileSize: options.tileSize

View File

@@ -9,21 +9,20 @@ import {assign} from './obj.js';
import {get as getProjection, METERS_PER_UNIT} from './proj.js';
import Units from './proj/Units.js';
import TileGrid from './tilegrid/TileGrid.js';
const _ol_tilegrid_ = {};
/**
* @param {ol.proj.Projection} projection Projection.
* @return {!ol.tilegrid.TileGrid} Default tile grid for the passed projection.
*/
_ol_tilegrid_.getForProjection = function(projection) {
export function getForProjection(projection) {
let tileGrid = projection.getDefaultTileGrid();
if (!tileGrid) {
tileGrid = _ol_tilegrid_.createForProjection(projection);
tileGrid = createForProjection(projection);
projection.setDefaultTileGrid(tileGrid);
}
return tileGrid;
};
}
/**
@@ -32,10 +31,10 @@ _ol_tilegrid_.getForProjection = function(projection) {
* @param {ol.proj.Projection} projection Projection.
* @return {ol.TileCoord} Tile coordinate.
*/
_ol_tilegrid_.wrapX = function(tileGrid, tileCoord, projection) {
export function wrapX(tileGrid, tileCoord, projection) {
const z = tileCoord[0];
const center = tileGrid.getTileCoordCenter(tileCoord);
const projectionExtent = _ol_tilegrid_.extentFromProjection(projection);
const projectionExtent = extentFromProjection(projection);
if (!containsCoordinate(projectionExtent, center)) {
const worldWidth = getWidth(projectionExtent);
const worldsAway = Math.ceil((projectionExtent[0] - center[0]) / worldWidth);
@@ -44,7 +43,7 @@ _ol_tilegrid_.wrapX = function(tileGrid, tileCoord, projection) {
} else {
return tileCoord;
}
};
}
/**
@@ -57,10 +56,10 @@ _ol_tilegrid_.wrapX = function(tileGrid, tileCoord, projection) {
* ol.extent.Corner.TOP_LEFT).
* @return {!ol.tilegrid.TileGrid} TileGrid instance.
*/
_ol_tilegrid_.createForExtent = function(extent, opt_maxZoom, opt_tileSize, opt_corner) {
export function createForExtent(extent, opt_maxZoom, opt_tileSize, opt_corner) {
const corner = opt_corner !== undefined ? opt_corner : Corner.TOP_LEFT;
const resolutions = _ol_tilegrid_.resolutionsFromExtent(
const resolutions = resolutionsFromExtent(
extent, opt_maxZoom, opt_tileSize);
return new TileGrid({
@@ -69,7 +68,7 @@ _ol_tilegrid_.createForExtent = function(extent, opt_maxZoom, opt_tileSize, opt_
resolutions: resolutions,
tileSize: opt_tileSize
});
};
}
/**
@@ -78,19 +77,19 @@ _ol_tilegrid_.createForExtent = function(extent, opt_maxZoom, opt_tileSize, opt_
* @return {!ol.tilegrid.TileGrid} Tile grid instance.
* @api
*/
_ol_tilegrid_.createXYZ = function(opt_options) {
export function createXYZ(opt_options) {
const options = /** @type {olx.tilegrid.TileGridOptions} */ ({});
assign(options, opt_options !== undefined ?
opt_options : /** @type {olx.tilegrid.XYZOptions} */ ({}));
if (options.extent === undefined) {
options.extent = getProjection('EPSG:3857').getExtent();
}
options.resolutions = _ol_tilegrid_.resolutionsFromExtent(
options.resolutions = resolutionsFromExtent(
options.extent, options.maxZoom, options.tileSize);
delete options.maxZoom;
return new TileGrid(options);
};
}
/**
@@ -102,7 +101,7 @@ _ol_tilegrid_.createXYZ = function(opt_options) {
* DEFAULT_TILE_SIZE).
* @return {!Array.<number>} Resolutions array.
*/
_ol_tilegrid_.resolutionsFromExtent = function(extent, opt_maxZoom, opt_tileSize) {
function resolutionsFromExtent(extent, opt_maxZoom, opt_tileSize) {
const maxZoom = opt_maxZoom !== undefined ?
opt_maxZoom : DEFAULT_MAX_ZOOM;
@@ -120,7 +119,7 @@ _ol_tilegrid_.resolutionsFromExtent = function(extent, opt_maxZoom, opt_tileSize
resolutions[z] = maxResolution / Math.pow(2, z);
}
return resolutions;
};
}
/**
@@ -133,11 +132,11 @@ _ol_tilegrid_.resolutionsFromExtent = function(extent, opt_maxZoom, opt_tileSize
* ol.extent.Corner.BOTTOM_LEFT).
* @return {!ol.tilegrid.TileGrid} TileGrid instance.
*/
_ol_tilegrid_.createForProjection = function(projection, opt_maxZoom, opt_tileSize, opt_corner) {
const extent = _ol_tilegrid_.extentFromProjection(projection);
return _ol_tilegrid_.createForExtent(
export function createForProjection(projection, opt_maxZoom, opt_tileSize, opt_corner) {
const extent = extentFromProjection(projection);
return createForExtent(
extent, opt_maxZoom, opt_tileSize, opt_corner);
};
}
/**
@@ -146,7 +145,7 @@ _ol_tilegrid_.createForProjection = function(projection, opt_maxZoom, opt_tileSi
* @param {ol.ProjectionLike} projection Projection.
* @return {ol.Extent} Extent.
*/
_ol_tilegrid_.extentFromProjection = function(projection) {
export function extentFromProjection(projection) {
projection = getProjection(projection);
let extent = projection.getExtent();
if (!extent) {
@@ -155,5 +154,4 @@ _ol_tilegrid_.extentFromProjection = function(projection) {
extent = createOrUpdate(-half, -half, half, half);
}
return extent;
};
export default _ol_tilegrid_;
}