Named exports from ol/size

This commit is contained in:
Tim Schaub
2018-02-07 11:47:51 -07:00
parent cd9b06135f
commit 11a4e1afa6
12 changed files with 58 additions and 59 deletions

View File

@@ -26,7 +26,7 @@ import {DEVICE_PIXEL_RATIO, TOUCH} from './has.js';
import LayerGroup from './layer/Group.js';
import {getMapRendererPlugins} from './plugins.js';
import RendererType from './renderer/Type.js';
import _ol_size_ from './size.js';
import {hasArea} from './size.js';
import PriorityQueue from './structs/PriorityQueue.js';
import _ol_transform_ from './transform.js';
@@ -1201,7 +1201,7 @@ PluggableMap.prototype.renderFrame_ = function(time) {
const previousFrameState = this.frameState_;
/** @type {?olx.FrameState} */
let frameState = null;
if (size !== undefined && _ol_size_.hasArea(size) && view && view.isDef()) {
if (size !== undefined && hasArea(size) && view && view.isDef()) {
const viewHints = view.getHints(this.frameState_ ? this.frameState_.viewHints : undefined);
const layerStatesArray = this.getLayerGroup().getLayerStatesArray();
const layerStates = {};

View File

@@ -15,7 +15,7 @@ import RendererType from '../Type.js';
import WebGLLayerRenderer from '../webgl/Layer.js';
import _ol_renderer_webgl_tilelayershader_ from '../webgl/tilelayershader.js';
import _ol_renderer_webgl_tilelayershader_Locations_ from '../webgl/tilelayershader/Locations.js';
import _ol_size_ from '../../size.js';
import {toSize} from '../../size.js';
import _ol_transform_ from '../../transform.js';
import _ol_webgl_ from '../../webgl.js';
import _ol_webgl_Buffer_ from '../../webgl/Buffer.js';
@@ -181,7 +181,7 @@ WebGLTileLayerRenderer.prototype.prepareFrame = function(frameState, layerState,
const tilePixelSize =
tileSource.getTilePixelSize(z, frameState.pixelRatio, projection);
const pixelRatio = tilePixelSize[0] /
_ol_size_.toSize(tileGrid.getTileSize(z), this.tmpSize_)[0];
toSize(tileGrid.getTileSize(z), this.tmpSize_)[0];
const tilePixelResolution = tileResolution / pixelRatio;
const tileGutter = tileSource.getTilePixelRatio(pixelRatio) * tileSource.getGutter(projection);

View File

@@ -1,24 +1,23 @@
/**
* @module ol/size
*/
const _ol_size_ = {};
/**
* Returns a buffered size.
* @param {ol.Size} size Size.
* @param {number} buffer Buffer.
* @param {number} num The amount by which to buffer.
* @param {ol.Size=} opt_size Optional reusable size array.
* @return {ol.Size} The buffered size.
*/
_ol_size_.buffer = function(size, buffer, opt_size) {
export function buffer(size, num, opt_size) {
if (opt_size === undefined) {
opt_size = [0, 0];
}
opt_size[0] = size[0] + 2 * buffer;
opt_size[1] = size[1] + 2 * buffer;
opt_size[0] = size[0] + 2 * num;
opt_size[1] = size[1] + 2 * num;
return opt_size;
};
}
/**
@@ -26,9 +25,9 @@ _ol_size_.buffer = function(size, buffer, opt_size) {
* @param {ol.Size} size The size to test.
* @return {boolean} The size has a positive area.
*/
_ol_size_.hasArea = function(size) {
export function hasArea(size) {
return size[0] > 0 && size[1] > 0;
};
}
/**
@@ -38,14 +37,14 @@ _ol_size_.hasArea = function(size) {
* @param {ol.Size=} opt_size Optional reusable size array.
* @return {ol.Size} The scaled size.
*/
_ol_size_.scale = function(size, ratio, opt_size) {
export function scale(size, ratio, opt_size) {
if (opt_size === undefined) {
opt_size = [0, 0];
}
opt_size[0] = (size[0] * ratio + 0.5) | 0;
opt_size[1] = (size[1] * ratio + 0.5) | 0;
return opt_size;
};
}
/**
@@ -57,7 +56,7 @@ _ol_size_.scale = function(size, ratio, opt_size) {
* @return {ol.Size} Size.
* @api
*/
_ol_size_.toSize = function(size, opt_size) {
export function toSize(size, opt_size) {
if (Array.isArray(size)) {
return size;
} else {
@@ -68,5 +67,5 @@ _ol_size_.toSize = function(size, opt_size) {
}
return opt_size;
}
};
export default _ol_size_;
}

View File

@@ -6,7 +6,7 @@ import TileCache from '../TileCache.js';
import TileState from '../TileState.js';
import Event from '../events/Event.js';
import {equivalent} from '../proj.js';
import _ol_size_ from '../size.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';
@@ -258,11 +258,11 @@ TileSource.prototype.getTilePixelRatio = function(pixelRatio) {
TileSource.prototype.getTilePixelSize = function(z, pixelRatio, projection) {
const tileGrid = this.getTileGridForProjection(projection);
const tilePixelRatio = this.getTilePixelRatio(pixelRatio);
const tileSize = _ol_size_.toSize(tileGrid.getTileSize(z), this.tmpSize);
const tileSize = toSize(tileGrid.getTileSize(z), this.tmpSize);
if (tilePixelRatio == 1) {
return tileSize;
} else {
return _ol_size_.scale(tileSize, tilePixelRatio, this.tmpSize);
return scaleSize(tileSize, tilePixelRatio, this.tmpSize);
}
};

View File

@@ -5,7 +5,7 @@ import {inherits} from '../index.js';
import {createEmpty} from '../extent.js';
import {modulo} from '../math.js';
import {assign} from '../obj.js';
import _ol_size_ from '../size.js';
import {toSize, scale as scaleSize} from '../size.js';
import TileImage from '../source/TileImage.js';
import _ol_tilecoord_ from '../tilecoord.js';
import {appendParams} from '../uri.js';
@@ -153,11 +153,11 @@ TileArcGISRest.prototype.fixedTileUrlFunction = function(tileCoord, pixelRatio,
const tileExtent = tileGrid.getTileCoordExtent(
tileCoord, this.tmpExtent_);
let tileSize = _ol_size_.toSize(
let tileSize = toSize(
tileGrid.getTileSize(tileCoord[0]), this.tmpSize);
if (pixelRatio != 1) {
tileSize = _ol_size_.scale(tileSize, pixelRatio, this.tmpSize);
tileSize = scaleSize(tileSize, pixelRatio, this.tmpSize);
}
// Apply default params and override with user specified values.

View File

@@ -5,7 +5,7 @@ import {inherits} from '../index.js';
import Tile from '../Tile.js';
import TileState from '../TileState.js';
import {createCanvasContext2D} from '../dom.js';
import _ol_size_ from '../size.js';
import {toSize} from '../size.js';
import TileSource from '../source/Tile.js';
import _ol_tilecoord_ from '../tilecoord.js';
@@ -44,7 +44,7 @@ TileDebug.prototype.getTile = function(z, x, y) {
if (this.tileCache.containsKey(tileCoordKey)) {
return /** @type {!ol.source.TileDebug.Tile_} */ (this.tileCache.get(tileCoordKey));
} else {
const tileSize = _ol_size_.toSize(this.tileGrid.getTileSize(z));
const tileSize = toSize(this.tileGrid.getTileSize(z));
const tileCoord = [z, x, y];
const textTileCoord = this.getTileCoordForTileUrlFunction(tileCoord);
const text = !textTileCoord ? '' :

View File

@@ -10,7 +10,7 @@ import {assign} from '../obj.js';
import {modulo} from '../math.js';
import {get as getProjection, transform, transformExtent} from '../proj.js';
import _ol_reproj_ from '../reproj.js';
import _ol_size_ from '../size.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';
@@ -125,12 +125,12 @@ TileWMS.prototype.getGetFeatureInfoUrl = function(coordinate, resolution, projec
let tileResolution = tileGrid.getResolution(tileCoord[0]);
let tileExtent = tileGrid.getTileCoordExtent(tileCoord, this.tmpExtent_);
let tileSize = _ol_size_.toSize(tileGrid.getTileSize(tileCoord[0]), this.tmpSize);
let tileSize = toSize(tileGrid.getTileSize(tileCoord[0]), this.tmpSize);
const gutter = this.gutter_;
if (gutter !== 0) {
tileSize = _ol_size_.buffer(tileSize, gutter, this.tmpSize);
tileSize = bufferSize(tileSize, gutter, this.tmpSize);
tileExtent = buffer(tileExtent, tileResolution * gutter, tileExtent);
}
@@ -297,17 +297,17 @@ TileWMS.prototype.fixedTileUrlFunction = function(tileCoord, pixelRatio, project
const tileResolution = tileGrid.getResolution(tileCoord[0]);
let tileExtent = tileGrid.getTileCoordExtent(tileCoord, this.tmpExtent_);
let tileSize = _ol_size_.toSize(
let tileSize = toSize(
tileGrid.getTileSize(tileCoord[0]), this.tmpSize);
const gutter = this.gutter_;
if (gutter !== 0) {
tileSize = _ol_size_.buffer(tileSize, gutter, this.tmpSize);
tileSize = bufferSize(tileSize, gutter, this.tmpSize);
tileExtent = buffer(tileExtent, tileResolution * gutter, tileExtent);
}
if (pixelRatio != 1) {
tileSize = _ol_size_.scale(tileSize, pixelRatio, this.tmpSize);
tileSize = scaleSize(tileSize, pixelRatio, this.tmpSize);
}
const baseParams = {

View File

@@ -5,7 +5,7 @@ import {inherits} from '../index.js';
import TileState from '../TileState.js';
import VectorImageTile, {defaultLoadFunction} from '../VectorImageTile.js';
import VectorTile from '../VectorTile.js';
import _ol_size_ from '../size.js';
import {toSize} from '../size.js';
import UrlTile from '../source/UrlTile.js';
import _ol_tilecoord_ from '../tilecoord.js';
import _ol_tilegrid_ from '../tilegrid.js';
@@ -162,7 +162,7 @@ VectorTileSource.prototype.getTilePixelRatio = function(pixelRatio) {
* @inheritDoc
*/
VectorTileSource.prototype.getTilePixelSize = function(z, pixelRatio, projection) {
const tileSize = _ol_size_.toSize(this.getTileGridForProjection(projection).getTileSize(z));
const tileSize = toSize(this.getTileGridForProjection(projection).getTileSize(z));
return [Math.round(tileSize[0] * pixelRatio), Math.round(tileSize[1] * pixelRatio)];
};
export default VectorTileSource;

View File

@@ -9,7 +9,7 @@ import {expandUrl, createFromTileUrlFunctions} from '../tileurlfunction.js';
import {assert} from '../asserts.js';
import {createCanvasContext2D} from '../dom.js';
import {getTopLeft} from '../extent.js';
import _ol_size_ from '../size.js';
import {toSize} from '../size.js';
import TileImage from '../source/TileImage.js';
import TileGrid from '../tilegrid/TileGrid.js';
@@ -179,7 +179,7 @@ Zoomify.Tile_ = function(
* @private
* @type {ol.Size}
*/
this.tileSize_ = _ol_size_.toSize(tileGrid.getTileSize(tileCoord[0]));
this.tileSize_ = toSize(tileGrid.getTileSize(tileCoord[0]));
};
inherits(Zoomify.Tile_, ImageTile);

View File

@@ -2,7 +2,7 @@
* @module ol/tilegrid
*/
import {DEFAULT_MAX_ZOOM, DEFAULT_TILE_SIZE} from './tilegrid/common.js';
import _ol_size_ from './size.js';
import {toSize} from './size.js';
import {containsCoordinate, createOrUpdate, getCorner, getHeight, getWidth} from './extent.js';
import Corner from './extent/Corner.js';
import {assign} from './obj.js';
@@ -109,7 +109,7 @@ _ol_tilegrid_.resolutionsFromExtent = function(extent, opt_maxZoom, opt_tileSize
const height = getHeight(extent);
const width = getWidth(extent);
const tileSize = _ol_size_.toSize(opt_tileSize !== undefined ?
const tileSize = toSize(opt_tileSize !== undefined ?
opt_tileSize : DEFAULT_TILE_SIZE);
const maxResolution = Math.max(
width / tileSize[0], height / tileSize[1]);

View File

@@ -7,7 +7,7 @@ import TileRange from '../TileRange.js';
import {isSorted, linearFindNearest} from '../array.js';
import {createOrUpdate, getTopLeft} from '../extent.js';
import {clamp} from '../math.js';
import _ol_size_ from '../size.js';
import {toSize} from '../size.js';
import _ol_tilecoord_ from '../tilecoord.js';
/**
@@ -308,7 +308,7 @@ TileGrid.prototype.getTileCoordChildTileRange = function(tileCoord, opt_tileRang
TileGrid.prototype.getTileRangeExtent = function(z, tileRange, opt_extent) {
const origin = this.getOrigin(z);
const resolution = this.getResolution(z);
const tileSize = _ol_size_.toSize(this.getTileSize(z), this.tmpSize_);
const tileSize = toSize(this.getTileSize(z), this.tmpSize_);
const minX = origin[0] + tileRange.minX * tileSize[0] * resolution;
const maxX = origin[0] + (tileRange.maxX + 1) * tileSize[0] * resolution;
const minY = origin[1] + tileRange.minY * tileSize[1] * resolution;
@@ -342,7 +342,7 @@ TileGrid.prototype.getTileRangeForExtentAndZ = function(extent, z, opt_tileRange
TileGrid.prototype.getTileCoordCenter = function(tileCoord) {
const origin = this.getOrigin(tileCoord[0]);
const resolution = this.getResolution(tileCoord[0]);
const tileSize = _ol_size_.toSize(this.getTileSize(tileCoord[0]), this.tmpSize_);
const tileSize = toSize(this.getTileSize(tileCoord[0]), this.tmpSize_);
return [
origin[0] + (tileCoord[1] + 0.5) * tileSize[0] * resolution,
origin[1] + (tileCoord[2] + 0.5) * tileSize[1] * resolution
@@ -361,7 +361,7 @@ TileGrid.prototype.getTileCoordCenter = function(tileCoord) {
TileGrid.prototype.getTileCoordExtent = function(tileCoord, opt_extent) {
const origin = this.getOrigin(tileCoord[0]);
const resolution = this.getResolution(tileCoord[0]);
const tileSize = _ol_size_.toSize(this.getTileSize(tileCoord[0]), this.tmpSize_);
const tileSize = toSize(this.getTileSize(tileCoord[0]), this.tmpSize_);
const minX = origin[0] + tileCoord[1] * tileSize[0] * resolution;
const minY = origin[1] + tileCoord[2] * tileSize[1] * resolution;
const maxX = minX + tileSize[0] * resolution;
@@ -405,7 +405,7 @@ TileGrid.prototype.getTileCoordForXYAndResolution_ = function(
const z = this.getZForResolution(resolution);
const scale = resolution / this.getResolution(z);
const origin = this.getOrigin(z);
const tileSize = _ol_size_.toSize(this.getTileSize(z), this.tmpSize_);
const tileSize = toSize(this.getTileSize(z), this.tmpSize_);
const adjustX = reverseIntersectionPolicy ? 0.5 : 0;
const adjustY = reverseIntersectionPolicy ? 0 : 0.5;
@@ -444,7 +444,7 @@ TileGrid.prototype.getTileCoordForXYAndResolution_ = function(
TileGrid.prototype.getTileCoordForXYAndZ_ = function(x, y, z, reverseIntersectionPolicy, opt_tileCoord) {
const origin = this.getOrigin(z);
const resolution = this.getResolution(z);
const tileSize = _ol_size_.toSize(this.getTileSize(z), this.tmpSize_);
const tileSize = toSize(this.getTileSize(z), this.tmpSize_);
const adjustX = reverseIntersectionPolicy ? 0.5 : 0;
const adjustY = reverseIntersectionPolicy ? 0 : 0.5;

View File

@@ -1,4 +1,4 @@
import _ol_size_ from '../../../src/ol/size.js';
import {hasArea, toSize, buffer as bufferSize, scale as scaleSize} from '../../../src/ol/size.js';
describe('ol.size', function() {
@@ -7,14 +7,14 @@ describe('ol.size', function() {
it('buffers a size', function() {
const size = [50, 75];
const bufferedSize = _ol_size_.buffer(size, 20);
const bufferedSize = bufferSize(size, 20);
expect(bufferedSize).to.eql([90, 115]);
});
it('reuses an existing array', function() {
const reuse = [0, 0];
const size = [50, 50];
const bufferedSize = _ol_size_.buffer(size, 20, reuse);
const bufferedSize = bufferSize(size, 20, reuse);
expect(bufferedSize).to.equal(reuse);
});
@@ -23,13 +23,13 @@ describe('ol.size', function() {
describe('hasArea()', function() {
it('determines if a size has a positive area', function() {
expect(_ol_size_.hasArea([50, 75])).to.equal(true);
expect(_ol_size_.hasArea([0, 75])).to.equal(false);
expect(_ol_size_.hasArea([50, 0])).to.equal(false);
expect(_ol_size_.hasArea([0, 0])).to.equal(false);
expect(_ol_size_.hasArea([-1, 75])).to.equal(false);
expect(_ol_size_.hasArea([50, -1])).to.equal(false);
expect(_ol_size_.hasArea([-1, -1])).to.equal(false);
expect(hasArea([50, 75])).to.equal(true);
expect(hasArea([0, 75])).to.equal(false);
expect(hasArea([50, 0])).to.equal(false);
expect(hasArea([0, 0])).to.equal(false);
expect(hasArea([-1, 75])).to.equal(false);
expect(hasArea([50, -1])).to.equal(false);
expect(hasArea([-1, -1])).to.equal(false);
});
});
@@ -38,14 +38,14 @@ describe('ol.size', function() {
it('scales a size and rounds the result', function() {
const size = [50, 75];
const scaledSize = _ol_size_.scale(size, 1.75);
const scaledSize = scaleSize(size, 1.75);
expect(scaledSize).to.eql([88, 131]);
});
it('reuses an existing array', function() {
const reuse = [0, 0];
const size = [50, 50];
const scaledSize = _ol_size_.scale(size, 1.75, reuse);
const scaledSize = scaleSize(size, 1.75, reuse);
expect(scaledSize).to.equal(reuse);
});
@@ -54,21 +54,21 @@ describe('ol.size', function() {
describe('toSize()', function() {
it('creates a size array from a number', function() {
const size = _ol_size_.toSize(512);
const size = toSize(512);
expect(size).to.eql([512, 512]);
});
it('reuses an existing array', function() {
const sizeArray = [0, 0];
const size = _ol_size_.toSize(512, sizeArray);
const size = toSize(512, sizeArray);
expect(size).to.equal(sizeArray);
});
it('returns a size array unaltered', function() {
const sizeArray = [512, 256];
let size = _ol_size_.toSize(sizeArray);
let size = toSize(sizeArray);
expect(size).to.equal(sizeArray);
size = _ol_size_.toSize(sizeArray, [0, 0]);
size = toSize(sizeArray, [0, 0]);
expect(size).to.equal(sizeArray);
});