Named exports from ol/tilegrid
This commit is contained in:
@@ -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_;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user