Correct range for extent and resolution

Tile ranges are inclusive.  When getting the tile range for an extent, the top-right corner of the extent should be considered with a different intersection policy than the bottom-left corner.
This commit is contained in:
Tim Schaub
2013-02-18 17:09:33 -07:00
parent 8b19751264
commit 797dba2cdb
2 changed files with 135 additions and 13 deletions

View File

@@ -183,10 +183,10 @@ ol.tilegrid.TileGrid.prototype.getTileRangeExtent = function(z, tileRange) {
*/
ol.tilegrid.TileGrid.prototype.getTileRangeForExtentAndResolution = function(
extent, resolution) {
var min = this.getTileCoordForCoordAndResolution(
var min = this.getTileCoordForCoordAndResolution_(
new ol.Coordinate(extent.minX, extent.minY), resolution);
var max = this.getTileCoordForCoordAndResolution(
new ol.Coordinate(extent.maxX, extent.maxY), resolution);
var max = this.getTileCoordForCoordAndResolution_(
new ol.Coordinate(extent.maxX, extent.maxY), resolution, true);
return new ol.TileRange(min.x, min.y, max.x, max.y);
};
@@ -233,26 +233,46 @@ ol.tilegrid.TileGrid.prototype.getTileCoordExtent = function(tileCoord) {
/**
* Get the tile coordinate for the given map coordinate and resolution. This
* method considers that coordinates that intersect tile boundaries should be
* assigned the higher tile coordinate.
*
* @param {ol.Coordinate} coordinate Coordinate.
* @param {number} resolution Resolution.
* @return {ol.TileCoord} Tile coordinate.
*/
ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndResolution = function(
coordinate, resolution) {
return this.getTileCoordForCoordAndResolution_(coordinate, resolution);
};
/**
* @param {ol.Coordinate} coordinate Coordinate.
* @param {number} resolution Resolution.
* @param {boolean=} opt_reverseIntersectionPolicy Instead of letting edge
* intersections go to the higher tile coordinate, let edge intersections
* go to the lower tile coordinate.
* @return {ol.TileCoord} Tile coordinate.
* @private
*/
ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndResolution_ = function(
coordinate, resolution, opt_reverseIntersectionPolicy) {
var z = this.getZForResolution(resolution);
var scale = resolution / this.getResolution(z);
var origin = this.getOrigin(z);
var offsetFromOrigin = new ol.Coordinate(
Math.floor((coordinate.x - origin.x) / resolution),
Math.floor((coordinate.y - origin.y) / resolution));
var tileSize = this.getTileSize();
tileSize = new ol.Size(tileSize.width / scale,
tileSize.height / scale);
var x = Math.floor(offsetFromOrigin.x / tileSize.width);
var y = Math.floor(offsetFromOrigin.y / tileSize.height);
var x = scale * (coordinate.x - origin.x) / (resolution * tileSize.width);
var y = scale * (coordinate.y - origin.y) / (resolution * tileSize.height);
if (!opt_reverseIntersectionPolicy) {
x = Math.floor(x);
y = Math.floor(y);
} else {
x = Math.ceil(x) - 1;
y = Math.ceil(y) - 1;
}
return new ol.TileCoord(z, x, y);
};
@@ -266,7 +286,7 @@ ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndResolution = function(
ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndZ =
function(coordinate, z) {
var resolution = this.getResolution(z);
return this.getTileCoordForCoordAndResolution(coordinate, resolution);
return this.getTileCoordForCoordAndResolution_(coordinate, resolution);
};