Skip to content

Commit

Permalink
Named exports from ol/tilegrid
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaub committed Feb 9, 2018
1 parent 2779fe5 commit 9ed3881
Show file tree
Hide file tree
Showing 26 changed files with 126 additions and 128 deletions.
4 changes: 2 additions & 2 deletions examples/vector-esri-edit.js
Expand Up @@ -11,7 +11,7 @@ import {tile as tileStrategy} from '../src/ol/loadingstrategy.js';
import {fromLonLat} from '../src/ol/proj.js';
import VectorSource from '../src/ol/source/Vector.js';
import XYZ from '../src/ol/source/XYZ.js';
import _ol_tilegrid_ from '../src/ol/tilegrid.js';
import {createXYZ} from '../src/ol/tilegrid.js';


const serviceUrl = 'https://services.arcgis.com/rOo16HdIMeOBI4Mb/arcgis/rest/' +
Expand Down Expand Up @@ -44,7 +44,7 @@ const vectorSource = new VectorSource({
}
}});
},
strategy: tileStrategy(_ol_tilegrid_.createXYZ({
strategy: tileStrategy(createXYZ({
tileSize: 512
}))
});
Expand Down
4 changes: 2 additions & 2 deletions examples/vector-esri.js
Expand Up @@ -10,7 +10,7 @@ import XYZ from '../src/ol/source/XYZ.js';
import Fill from '../src/ol/style/Fill.js';
import Stroke from '../src/ol/style/Stroke.js';
import Style from '../src/ol/style/Style.js';
import _ol_tilegrid_ from '../src/ol/tilegrid.js';
import {createXYZ} from '../src/ol/tilegrid.js';


const serviceUrl = 'https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/' +
Expand Down Expand Up @@ -82,7 +82,7 @@ const vectorSource = new VectorSource({
}
}});
},
strategy: tileStrategy(_ol_tilegrid_.createXYZ({
strategy: tileStrategy(createXYZ({
tileSize: 512
}))
});
Expand Down
6 changes: 3 additions & 3 deletions src/ol/source/BingMaps.js
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/ol/source/Tile.js
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
};
Expand Down
4 changes: 2 additions & 2 deletions src/ol/source/TileImage.js
Expand Up @@ -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
Expand Down Expand Up @@ -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]);
}
Expand Down
6 changes: 3 additions & 3 deletions src/ol/source/TileJSON.js
Expand Up @@ -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
Expand Down Expand Up @@ -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
});
Expand Down
6 changes: 3 additions & 3 deletions src/ol/source/TileUTFGrid.js
Expand Up @@ -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
Expand Down Expand Up @@ -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
});
Expand Down
8 changes: 4 additions & 4 deletions src/ol/source/VectorTile.js
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/ol/source/XYZ.js
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
42 changes: 20 additions & 22 deletions src/ol/tilegrid.js
Expand Up @@ -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;
};
}


/**
Expand All @@ -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);
Expand All @@ -44,7 +43,7 @@ _ol_tilegrid_.wrapX = function(tileGrid, tileCoord, projection) {
} else {
return tileCoord;
}
};
}


/**
Expand All @@ -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({
Expand All @@ -69,7 +68,7 @@ _ol_tilegrid_.createForExtent = function(extent, opt_maxZoom, opt_tileSize, opt_
resolutions: resolutions,
tileSize: opt_tileSize
});
};
}


/**
Expand All @@ -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);
};
}


/**
Expand All @@ -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;

Expand All @@ -120,7 +119,7 @@ _ol_tilegrid_.resolutionsFromExtent = function(extent, opt_maxZoom, opt_tileSize
resolutions[z] = maxResolution / Math.pow(2, z);
}
return resolutions;
};
}


/**
Expand All @@ -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);
};
}


/**
Expand All @@ -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) {
Expand All @@ -155,5 +154,4 @@ _ol_tilegrid_.extentFromProjection = function(projection) {
extent = createOrUpdate(-half, -half, half, half);
}
return extent;
};
export default _ol_tilegrid_;
}
4 changes: 2 additions & 2 deletions test/rendering/ol/layer/image.test.js
Expand Up @@ -4,7 +4,7 @@ import ImageLayer from '../../../../src/ol/layer/Image.js';
import {assign} from '../../../../src/ol/obj.js';
import {get as getProjection, transform, transformExtent} from '../../../../src/ol/proj.js';
import Static from '../../../../src/ol/source/ImageStatic.js';
import _ol_tilegrid_ from '../../../../src/ol/tilegrid.js';
import {createXYZ} from '../../../../src/ol/tilegrid.js';


describe('ol.rendering.layer.Image', function() {
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('ol.rendering.layer.Image', function() {
beforeEach(function() {
source = new Static({
url: 'rendering/ol/data/tiles/osm/5/5/12.png',
imageExtent: _ol_tilegrid_.createXYZ().getTileCoordExtent(
imageExtent: createXYZ().getTileCoordExtent(
[5, 5, -12 - 1]),
projection: getProjection('EPSG:3857')
});
Expand Down
4 changes: 2 additions & 2 deletions test/rendering/ol/layer/tile.test.js
Expand Up @@ -10,7 +10,7 @@ import XYZ from '../../../../src/ol/source/XYZ.js';
import CircleStyle from '../../../../src/ol/style/Circle.js';
import Fill from '../../../../src/ol/style/Fill.js';
import Stroke from '../../../../src/ol/style/Stroke.js';
import _ol_tilegrid_ from '../../../../src/ol/tilegrid.js';
import {createXYZ} from '../../../../src/ol/tilegrid.js';


describe('ol.rendering.layer.Tile', function() {
Expand Down Expand Up @@ -220,7 +220,7 @@ describe('ol.rendering.layer.Tile', function() {
function createSource(tileSize) {
return new TileImage({
url: 'rendering/ol/data/tiles/' + tileSize + '/{z}/{x}/{y}.png',
tileGrid: _ol_tilegrid_.createXYZ({
tileGrid: createXYZ({
tileSize: tileSize.split('x')
}),
transition: 0
Expand Down
4 changes: 2 additions & 2 deletions test/rendering/ol/layer/vectortile.test.js
Expand Up @@ -12,7 +12,7 @@ import CircleStyle from '../../../../src/ol/style/Circle.js';
import Fill from '../../../../src/ol/style/Fill.js';
import Style from '../../../../src/ol/style/Style.js';
import Text from '../../../../src/ol/style/Text.js';
import _ol_tilegrid_ from '../../../../src/ol/tilegrid.js';
import {createXYZ} from '../../../../src/ol/tilegrid.js';


describe('ol.rendering.layer.VectorTile', function() {
Expand Down Expand Up @@ -71,7 +71,7 @@ describe('ol.rendering.layer.VectorTile', function() {
beforeEach(function() {
source = new VectorTileSource({
format: new MVT(),
tileGrid: _ol_tilegrid_.createXYZ(),
tileGrid: createXYZ(),
url: 'rendering/ol/data/tiles/mvt/{z}-{x}-{y}.vector.pbf',
transition: 0
});
Expand Down

0 comments on commit 9ed3881

Please sign in to comment.