Merge pull request #3559 from ahocevar/tile-width-height

Add support for non-square tiles
This commit is contained in:
Andreas Hocevar
2015-04-16 09:26:27 +02:00
23 changed files with 444 additions and 121 deletions

View File

@@ -107,7 +107,8 @@ ol.source.BingMaps.prototype.handleImageryMetadataResponse =
extent: ol.tilegrid.extentFromProjection(sourceProjection),
minZoom: resource.zoomMin,
maxZoom: maxZoom,
tileSize: resource.imageWidth
tileSize: resource.imageWidth == resource.imageHeight ?
resource.imageWidth : [resource.imageWidth, resource.imageHeight]
});
this.tileGrid = tileGrid;

View File

@@ -11,6 +11,7 @@ goog.require('ol.TileCoord');
goog.require('ol.TileUrlFunction');
goog.require('ol.extent');
goog.require('ol.proj');
goog.require('ol.size');
goog.require('ol.source.TileImage');
goog.require('ol.tilecoord');
@@ -86,7 +87,7 @@ ol.source.TileArcGISRest.prototype.getParams = function() {
/**
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {number} tileSize Tile size.
* @param {ol.Size} tileSize Tile size.
* @param {ol.Extent} tileExtent Tile extent.
* @param {number} pixelRatio Pixel ratio.
* @param {ol.proj.Projection} projection Projection.
@@ -106,7 +107,7 @@ ol.source.TileArcGISRest.prototype.getRequestUrl_ =
// ArcGIS Server only wants the numeric portion of the projection ID.
var srid = projection.getCode().split(':').pop();
params['SIZE'] = tileSize + ',' + tileSize;
params['SIZE'] = tileSize[0] + ',' + tileSize[1];
params['BBOX'] = tileExtent.join(',');
params['BBOXSR'] = srid;
params['IMAGESR'] = srid;
@@ -143,7 +144,7 @@ ol.source.TileArcGISRest.prototype.getRequestUrl_ =
* @param {number} z Z.
* @param {number} pixelRatio Pixel ratio.
* @param {ol.proj.Projection} projection Projection.
* @return {number} Size.
* @return {ol.Size} Size.
*/
ol.source.TileArcGISRest.prototype.getTilePixelSize =
function(z, pixelRatio, projection) {
@@ -151,7 +152,7 @@ ol.source.TileArcGISRest.prototype.getTilePixelSize =
if (pixelRatio == 1) {
return tileSize;
} else {
return (tileSize * pixelRatio + 0.5) | 0;
return ol.size.scale(tileSize, pixelRatio, this.tmpSize);
}
};
@@ -207,10 +208,11 @@ ol.source.TileArcGISRest.prototype.tileUrlFunction_ =
var tileExtent = tileGrid.getTileCoordExtent(
tileCoord, this.tmpExtent_);
var tileSize = tileGrid.getTileSize(tileCoord[0]);
var tileSize = ol.size.toSize(
tileGrid.getTileSize(tileCoord[0]), this.tmpSize);
if (pixelRatio != 1) {
tileSize = (tileSize * pixelRatio + 0.5) | 0;
tileSize = ol.size.scale(tileSize, pixelRatio, this.tmpSize);
}
// Apply default params and override with user specified values.

View File

@@ -4,6 +4,7 @@ goog.require('ol.Tile');
goog.require('ol.TileCoord');
goog.require('ol.TileState');
goog.require('ol.dom');
goog.require('ol.size');
goog.require('ol.source.Tile');
goog.require('ol.tilecoord');
goog.require('ol.tilegrid.TileGrid');
@@ -23,9 +24,10 @@ ol.DebugTile_ = function(tileCoord, tileGrid) {
/**
* @private
* @type {number}
* @type {ol.Size}
*/
this.tileSize_ = tileGrid.getTileSize(tileCoord[0]);
this.tileSize_ = ol.size.toSize(
tileGrid.getTileSize(tileCoord[0]));
/**
* @private
@@ -47,17 +49,17 @@ ol.DebugTile_.prototype.getImage = function(opt_context) {
} else {
var tileSize = this.tileSize_;
var context = ol.dom.createCanvasContext2D(tileSize, tileSize);
var context = ol.dom.createCanvasContext2D(tileSize[0], tileSize[1]);
context.strokeStyle = 'black';
context.strokeRect(0.5, 0.5, tileSize + 0.5, tileSize + 0.5);
context.strokeRect(0.5, 0.5, tileSize[0] + 0.5, tileSize[1] + 0.5);
context.fillStyle = 'black';
context.textAlign = 'center';
context.textBaseline = 'middle';
context.font = '24px sans-serif';
context.fillText(ol.tilecoord.toString(this.tileCoord),
tileSize / 2, tileSize / 2);
tileSize[0] / 2, tileSize[1] / 2);
this.canvasByContext_[key] = context.canvas;
return context.canvas;

View File

@@ -8,6 +8,7 @@ goog.require('ol.Extent');
goog.require('ol.TileCache');
goog.require('ol.TileRange');
goog.require('ol.TileState');
goog.require('ol.size');
goog.require('ol.source.Source');
goog.require('ol.tilecoord');
goog.require('ol.tilegrid.TileGrid');
@@ -74,6 +75,12 @@ ol.source.Tile = function(options) {
*/
this.tileCache = new ol.TileCache();
/**
* @protected
* @type {ol.Size}
*/
this.tmpSize = [0, 0];
/**
* @private
* @type {boolean|undefined}
@@ -202,12 +209,13 @@ ol.source.Tile.prototype.getTileGridForProjection = function(projection) {
* @param {number} z Z.
* @param {number} pixelRatio Pixel ratio.
* @param {ol.proj.Projection} projection Projection.
* @return {number} Tile size.
* @return {ol.Size} Tile size.
*/
ol.source.Tile.prototype.getTilePixelSize =
function(z, pixelRatio, projection) {
var tileGrid = this.getTileGridForProjection(projection);
return tileGrid.getTileSize(z) * this.tilePixelRatio_;
return ol.size.scale(ol.size.toSize(tileGrid.getTileSize(z), this.tmpSize),
this.tilePixelRatio_, this.tmpSize);
};

View File

@@ -15,6 +15,7 @@ goog.require('ol.TileCoord');
goog.require('ol.TileUrlFunction');
goog.require('ol.extent');
goog.require('ol.proj');
goog.require('ol.size');
goog.require('ol.source.TileImage');
goog.require('ol.source.wms');
goog.require('ol.source.wms.ServerType');
@@ -148,11 +149,12 @@ ol.source.TileWMS.prototype.getGetFeatureInfoUrl =
var tileResolution = tileGrid.getResolution(tileCoord[0]);
var tileExtent = tileGrid.getTileCoordExtent(tileCoord, this.tmpExtent_);
var tileSize = tileGrid.getTileSize(tileCoord[0]);
var tileSize = ol.size.toSize(
tileGrid.getTileSize(tileCoord[0]), this.tmpSize);
var gutter = this.gutter_;
if (gutter !== 0) {
tileSize += 2 * gutter;
tileSize = ol.size.buffer(tileSize, gutter, this.tmpSize);
tileExtent = ol.extent.buffer(tileExtent,
tileResolution * gutter, tileExtent);
}
@@ -207,7 +209,7 @@ ol.source.TileWMS.prototype.getParams = function() {
/**
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {number} tileSize Tile size.
* @param {ol.Size} tileSize Tile size.
* @param {ol.Extent} tileExtent Tile extent.
* @param {number} pixelRatio Pixel ratio.
* @param {ol.proj.Projection} projection Projection.
@@ -224,8 +226,8 @@ ol.source.TileWMS.prototype.getRequestUrl_ =
return undefined;
}
params['WIDTH'] = tileSize;
params['HEIGHT'] = tileSize;
params['WIDTH'] = tileSize[0];
params['HEIGHT'] = tileSize[1];
params[this.v13_ ? 'CRS' : 'SRS'] = projection.getCode();
@@ -282,7 +284,7 @@ ol.source.TileWMS.prototype.getRequestUrl_ =
* @param {number} z Z.
* @param {number} pixelRatio Pixel ratio.
* @param {ol.proj.Projection} projection Projection.
* @return {number} Size.
* @return {ol.Size} Size.
*/
ol.source.TileWMS.prototype.getTilePixelSize =
function(z, pixelRatio, projection) {
@@ -290,7 +292,7 @@ ol.source.TileWMS.prototype.getTilePixelSize =
if (pixelRatio == 1 || !this.hidpi_ || !goog.isDef(this.serverType_)) {
return tileSize;
} else {
return (tileSize * pixelRatio + 0.5) | 0;
return ol.size.scale(tileSize, pixelRatio, this.tmpSize);
}
};
@@ -372,17 +374,18 @@ ol.source.TileWMS.prototype.tileUrlFunction_ =
var tileResolution = tileGrid.getResolution(tileCoord[0]);
var tileExtent = tileGrid.getTileCoordExtent(tileCoord, this.tmpExtent_);
var tileSize = tileGrid.getTileSize(tileCoord[0]);
var tileSize = ol.size.toSize(
tileGrid.getTileSize(tileCoord[0]), this.tmpSize);
var gutter = this.gutter_;
if (gutter !== 0) {
tileSize += 2 * gutter;
tileSize = ol.size.buffer(tileSize, gutter, this.tmpSize);
tileExtent = ol.extent.buffer(tileExtent,
tileResolution * gutter, tileExtent);
}
if (pixelRatio != 1) {
tileSize = (tileSize * pixelRatio + 0.5) | 0;
tileSize = ol.size.scale(tileSize, pixelRatio, this.tmpSize);
}
var baseParams = {