Add ol.source.Tile support for wrapping around the x-axis

This commit is contained in:
Andreas Hocevar
2015-03-22 14:27:19 +01:00
parent c707c5e9db
commit 3e18b85206
15 changed files with 260 additions and 42 deletions
+3 -8
View File
@@ -33,7 +33,8 @@ ol.source.BingMaps = function(options) {
opaque: true,
projection: ol.proj.get('EPSG:3857'),
state: ol.source.State.LOADING,
tileLoadFunction: options.tileLoadFunction
tileLoadFunction: options.tileLoadFunction,
wrapX: goog.isDef(options.wrapX) ? options.wrapX : true
});
/**
@@ -48,12 +49,6 @@ ol.source.BingMaps = function(options) {
*/
this.maxZoom_ = goog.isDef(options.maxZoom) ? options.maxZoom : -1;
/**
* @private
* @type {boolean}
*/
this.wrapX_ = goog.isDef(options.wrapX) ? options.wrapX : true;
var protocol = ol.IS_HTTPS ? 'https:' : 'http:';
var uri = new goog.Uri(
protocol + '//dev.virtualearth.net/REST/v1/Imagery/Metadata/' +
@@ -117,7 +112,7 @@ ol.source.BingMaps.prototype.handleImageryMetadataResponse =
var culture = this.culture_;
this.tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
tileGrid.createTileCoordTransform({wrapX: this.wrapX_}),
tileGrid.createTileCoordTransform(),
ol.TileUrlFunction.createFromTileUrlFunctions(
goog.array.map(
resource.imageUrlSubdomains,
+2 -1
View File
@@ -42,7 +42,8 @@ ol.source.TileArcGISRest = function(opt_options) {
projection: options.projection,
tileGrid: options.tileGrid,
tileLoadFunction: options.tileLoadFunction,
tileUrlFunction: goog.bind(this.tileUrlFunction_, this)
tileUrlFunction: goog.bind(this.tileUrlFunction_, this),
wrapX: goog.isDef(options.wrapX) ? options.wrapX : true
});
var urls = options.urls;
+5 -2
View File
@@ -34,7 +34,8 @@ ol.source.TileImage = function(options) {
state: goog.isDef(options.state) ?
/** @type {ol.source.State} */ (options.state) : undefined,
tileGrid: options.tileGrid,
tilePixelRatio: options.tilePixelRatio
tilePixelRatio: options.tilePixelRatio,
wrapX: options.wrapX
});
/**
@@ -91,7 +92,9 @@ ol.source.TileImage.prototype.getTile =
} else {
goog.asserts.assert(projection);
var tileCoord = [z, x, y];
var tileUrl = this.tileUrlFunction(tileCoord, pixelRatio, projection);
var urlTileCoord = this.getWrapXTileCoord(tileCoord, projection);
var tileUrl = goog.isNull(urlTileCoord) ? undefined :
this.tileUrlFunction(urlTileCoord, pixelRatio, projection);
var tile = new this.tileClass(
tileCoord,
goog.isDef(tileUrl) ? ol.TileState.IDLE : ol.TileState.EMPTY,
+3 -11
View File
@@ -37,15 +37,10 @@ ol.source.TileJSON = function(options) {
crossOrigin: options.crossOrigin,
projection: ol.proj.get('EPSG:3857'),
state: ol.source.State.LOADING,
tileLoadFunction: options.tileLoadFunction
tileLoadFunction: options.tileLoadFunction,
wrapX: goog.isDef(options.wrapX) ? options.wrapX : true
});
/**
* @type {boolean|undefined}
* @private
*/
this.wrapX_ = options.wrapX;
var request = new goog.net.Jsonp(options.url);
request.send(undefined, goog.bind(this.handleTileJSONResponse, this));
@@ -82,10 +77,7 @@ ol.source.TileJSON.prototype.handleTileJSONResponse = function(tileJSON) {
this.tileGrid = tileGrid;
this.tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
tileGrid.createTileCoordTransform({
extent: extent,
wrapX: this.wrapX_
}),
tileGrid.createTileCoordTransform({extent: extent}),
ol.TileUrlFunction.createFromTemplates(tileJSON.tiles));
if (goog.isDef(tileJSON.attribution) &&
+34 -1
View File
@@ -20,7 +20,8 @@ goog.require('ol.tilegrid.TileGrid');
* tilePixelRatio: (number|undefined),
* projection: ol.proj.ProjectionLike,
* state: (ol.source.State|undefined),
* tileGrid: (ol.tilegrid.TileGrid|undefined)}}
* tileGrid: (ol.tilegrid.TileGrid|undefined),
* wrapX: (boolean|undefined)}}
*/
ol.source.TileOptions;
@@ -72,6 +73,12 @@ ol.source.Tile = function(options) {
*/
this.tileCache = new ol.TileCache();
/**
* @private
* @type {boolean|undefined}
*/
this.wrapX_ = options.wrapX;
};
goog.inherits(ol.source.Tile, ol.source.Source);
@@ -203,6 +210,32 @@ ol.source.Tile.prototype.getTilePixelSize =
};
/**
* Handles x-axis wrapping. When `this.wrapX_` is undefined or the projection
* is not a global projection, `tileCoord` will be returned unaltered. When
* `this.wrapX_` is true, the tile coordinate will be wrapped horizontally.
* When `this.wrapX_` is `false`, `null` will be returned for tiles that are
* outside the projection extent.
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {ol.proj.Projection=} opt_projection Projection.
* @return {ol.TileCoord} Tile coordinate.
*/
ol.source.Tile.prototype.getWrapXTileCoord =
function(tileCoord, opt_projection) {
var projection = goog.isDef(opt_projection) ?
opt_projection : this.getProjection();
if (goog.isDef(this.wrapX_) && projection.isGlobal()) {
var tileGrid = this.getTileGridForProjection(projection);
var extent = ol.tilegrid.extentFromProjection(projection);
return this.wrapX_ ?
ol.tilecoord.wrapX(tileCoord, tileGrid, extent) :
ol.tilecoord.clipX(tileCoord, tileGrid, extent);
} else {
return tileCoord;
}
};
/**
* Marks a tile coord as being used, without triggering a load.
* @param {number} z Tile coordinate z.
+2 -1
View File
@@ -47,7 +47,8 @@ ol.source.TileWMS = function(opt_options) {
projection: options.projection,
tileGrid: options.tileGrid,
tileLoadFunction: options.tileLoadFunction,
tileUrlFunction: goog.bind(this.tileUrlFunction_, this)
tileUrlFunction: goog.bind(this.tileUrlFunction_, this),
wrapX: options.wrapX
});
var urls = options.urls;
+3 -4
View File
@@ -34,16 +34,15 @@ ol.source.XYZ = function(options) {
tileGrid: tileGrid,
tileLoadFunction: options.tileLoadFunction,
tilePixelRatio: options.tilePixelRatio,
tileUrlFunction: ol.TileUrlFunction.nullTileUrlFunction
tileUrlFunction: ol.TileUrlFunction.nullTileUrlFunction,
wrapX: goog.isDef(options.wrapX) ? options.wrapX : true
});
/**
* @private
* @type {ol.TileCoordTransformType}
*/
this.tileCoordTransform_ = tileGrid.createTileCoordTransform({
wrapX: options.wrapX
});
this.tileCoordTransform_ = tileGrid.createTileCoordTransform();
if (goog.isDef(options.tileUrlFunction)) {
this.setTileUrlFunction(options.tileUrlFunction);