From ee487ca3087b71007e12db75863ccd15847ed420 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Mon, 18 Aug 2014 23:26:36 -0600 Subject: [PATCH] Sources may be configured with a projection, tile grids with an extent An XYZ tile grid is constructed with an extent defining the bounds of the tile grid. --- externs/olx.js | 23 +++++++++++++---------- src/ol/source/bingmapssource.js | 3 ++- src/ol/source/tilejsonsource.js | 4 +++- src/ol/source/xyzsource.js | 5 ++--- src/ol/tilegrid/xyztilegrid.js | 12 +++++------- 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/externs/olx.js b/externs/olx.js index ca007aca10..4c170ec6e2 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -5092,14 +5092,24 @@ olx.tilegrid.WMTSOptions.prototype.tileSizes; /** - * @typedef {{maxZoom: (number|undefined), - * minZoom: (number|undefined), - * projection: (ol.proj.ProjectionLike|undefined)}} + * @typedef {{extent: (ol.Extent|undefined), + * maxZoom: (number|undefined), + * minZoom: (number|undefined)}} * @api */ olx.tilegrid.XYZOptions; +/** + * Extent for the tile grid. The origin for an XYZ tile grid is the top-left + * corner of the extent. The zero level of the grid is defined by the + * resolution at which one 256 x 256 tile fits in the provided extent. If not + * provided, the extent of the EPSG:3857 projection is used. + * @type {ol.Extent|undefined} + */ +olx.tilegrid.XYZOptions.prototype.extent; + + /** * Maximum zoom. * @type {number|undefined} @@ -5114,13 +5124,6 @@ olx.tilegrid.XYZOptions.prototype.maxZoom; olx.tilegrid.XYZOptions.prototype.minZoom; -/** - * Projection. Default is `'EPSG:3857'`. - * @type {ol.proj.ProjectionLike|undefined} - */ -olx.tilegrid.XYZOptions.prototype.projection; - - /** * @typedef {{resolutions: !Array.}} * @api diff --git a/src/ol/source/bingmapssource.js b/src/ol/source/bingmapssource.js index bccce2b375..7d6a7b4158 100644 --- a/src/ol/source/bingmapssource.js +++ b/src/ol/source/bingmapssource.js @@ -89,7 +89,9 @@ ol.source.BingMaps.prototype.handleImageryMetadataResponse = var resource = response.resourceSets[0].resources[0]; goog.asserts.assert(resource.imageWidth == resource.imageHeight); + var sourceProjection = this.getProjection(); var tileGrid = new ol.tilegrid.XYZ({ + extent: ol.tilegrid.extentFromProjection(sourceProjection), minZoom: resource.zoomMin, maxZoom: resource.zoomMax, tileSize: resource.imageWidth @@ -97,7 +99,6 @@ ol.source.BingMaps.prototype.handleImageryMetadataResponse = this.tileGrid = tileGrid; var culture = this.culture_; - var sourceProjection = this.getProjection(); this.tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform( tileGrid.createTileCoordTransform(), ol.TileUrlFunction.createFromTileUrlFunctions( diff --git a/src/ol/source/tilejsonsource.js b/src/ol/source/tilejsonsource.js index 24c1ba8402..a9a623d601 100644 --- a/src/ol/source/tilejsonsource.js +++ b/src/ol/source/tilejsonsource.js @@ -54,10 +54,11 @@ ol.source.TileJSON.prototype.handleTileJSONResponse = function(tileJSON) { var epsg4326Projection = ol.proj.get('EPSG:4326'); + var sourceProjection = this.getProjection(); var extent; if (goog.isDef(tileJSON.bounds)) { var transform = ol.proj.getTransformFromProjections( - epsg4326Projection, this.getProjection()); + epsg4326Projection, sourceProjection); extent = ol.extent.applyTransform(tileJSON.bounds, transform); } @@ -67,6 +68,7 @@ ol.source.TileJSON.prototype.handleTileJSONResponse = function(tileJSON) { var minZoom = tileJSON.minzoom || 0; var maxZoom = tileJSON.maxzoom || 22; var tileGrid = new ol.tilegrid.XYZ({ + extent: ol.tilegrid.extentFromProjection(sourceProjection), maxZoom: maxZoom, minZoom: minZoom }); diff --git a/src/ol/source/xyzsource.js b/src/ol/source/xyzsource.js index 4654362859..ab72d2bac7 100644 --- a/src/ol/source/xyzsource.js +++ b/src/ol/source/xyzsource.js @@ -17,13 +17,12 @@ goog.require('ol.tilegrid.XYZ'); * @api */ ol.source.XYZ = function(options) { - var projection = goog.isDef(options.projection) ? options.projection : 'EPSG:3857'; var tileGrid = new ol.tilegrid.XYZ({ - maxZoom: options.maxZoom, - projection: options.projection + extent: ol.tilegrid.extentFromProjection(projection), + maxZoom: options.maxZoom }); goog.base(this, { diff --git a/src/ol/tilegrid/xyztilegrid.js b/src/ol/tilegrid/xyztilegrid.js index 8d66446bf6..47638ebba0 100644 --- a/src/ol/tilegrid/xyztilegrid.js +++ b/src/ol/tilegrid/xyztilegrid.js @@ -7,6 +7,7 @@ goog.require('ol.TileRange'); goog.require('ol.extent'); goog.require('ol.extent.Corner'); goog.require('ol.proj'); +goog.require('ol.proj.EPSG3857'); goog.require('ol.tilecoord'); goog.require('ol.tilegrid.TileGrid'); @@ -23,19 +24,16 @@ goog.require('ol.tilegrid.TileGrid'); * @api */ ol.tilegrid.XYZ = function(options) { - var projection = goog.isDef(options.projection) ? - options.projection : 'EPSG:3857'; - var extent = ol.tilegrid.extentFromProjection(projection); - + // TODO: accept a tileSize option var tileSize = ol.DEFAULT_TILE_SIZE; + var extent = goog.isDef(options.extent) ? + options.extent : ol.proj.EPSG3857.EXTENT; var resolutions = ol.tilegrid.resolutionsFromExtent( extent, options.maxZoom, tileSize); - var origin = ol.extent.getCorner(extent, ol.extent.Corner.TOP_LEFT); - goog.base(this, { minZoom: options.minZoom, - origin: origin, + origin: ol.extent.getCorner(extent, ol.extent.Corner.TOP_LEFT), resolutions: resolutions, tileSize: tileSize });