From 2842d1b2540b9bfe68532ec19caa5fee4ed26b63 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Tue, 4 Mar 2014 15:59:58 +0100 Subject: [PATCH] Add ol.loading --- src/ol/loading.exports | 3 +++ src/ol/loading.js | 52 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/ol/loading.exports create mode 100644 src/ol/loading.js diff --git a/src/ol/loading.exports b/src/ol/loading.exports new file mode 100644 index 0000000000..7564c21668 --- /dev/null +++ b/src/ol/loading.exports @@ -0,0 +1,3 @@ +@exportSymbol ol.loading.all +@exportSymbol ol.loading.bbox +@exportSymbol ol.loading.createTile diff --git a/src/ol/loading.js b/src/ol/loading.js new file mode 100644 index 0000000000..272d3b2887 --- /dev/null +++ b/src/ol/loading.js @@ -0,0 +1,52 @@ +goog.provide('ol.loading'); + +goog.require('ol.TileCoord'); + + +/** + * @param {ol.Extent} extent Extent. + * @param {number} resolution Resolution. + * @return {Array.} Extents. + */ +ol.loading.all = function(extent, resolution) { + return [[-Infinity, -Infinity, Infinity, Infinity]]; +}; + + +/** + * @param {ol.Extent} extent Extent. + * @param {number} resolution Resolution. + * @return {Array.} Extents. + */ +ol.loading.bbox = function(extent, resolution) { + return [extent]; +}; + + +/** + * @param {ol.tilegrid.TileGrid} tileGrid Tile grid. + * @return {function(ol.Extent, number): Array.} Loading strategy. + */ +ol.loading.createTile = function(tileGrid) { + return ( + /** + * @param {ol.Extent} extent Extent. + * @param {number} resolution Resolution. + * @return {Array.} Extents. + */ + function(extent, resolution) { + var z = tileGrid.getZForResolution(resolution); + var tileRange = tileGrid.getTileRangeForExtentAndZ(extent, z); + /** @type {Array.} */ + var extents = []; + var tileCoord = new ol.TileCoord(z, 0, 0); + for (tileCoord.x = tileRange.minX; tileCoord.x <= tileRange.maxX; + ++tileCoord.x) { + for (tileCoord.y = tileRange.minY; tileCoord.y <= tileRange.maxY; + ++tileCoord.y) { + extents.push(tileGrid.getTileCoordExtent(tileCoord)); + } + } + return extents; + }); +};