Avoid creating ol.Coordinate objects to call getTileCoordForCoordAndResolution_
This commit is contained in:
@@ -189,10 +189,10 @@ ol.tilegrid.TileGrid.prototype.getTileRangeExtent = function(z, tileRange) {
|
||||
*/
|
||||
ol.tilegrid.TileGrid.prototype.getTileRangeForExtentAndResolution = function(
|
||||
extent, resolution) {
|
||||
var min = this.getTileCoordForCoordAndResolution_(
|
||||
new ol.Coordinate(extent.minX, extent.minY), resolution);
|
||||
var max = this.getTileCoordForCoordAndResolution_(
|
||||
new ol.Coordinate(extent.maxX, extent.maxY), resolution, true);
|
||||
var min = this.getTileCoordForXYAndResolution_(
|
||||
extent.minX, extent.minY, resolution);
|
||||
var max = this.getTileCoordForXYAndResolution_(
|
||||
extent.maxX, extent.maxY, resolution, true);
|
||||
return new ol.TileRange(min.x, min.y, max.x, max.y);
|
||||
};
|
||||
|
||||
@@ -249,12 +249,14 @@ ol.tilegrid.TileGrid.prototype.getTileCoordExtent = function(tileCoord) {
|
||||
*/
|
||||
ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndResolution = function(
|
||||
coordinate, resolution) {
|
||||
return this.getTileCoordForCoordAndResolution_(coordinate, resolution);
|
||||
return this.getTileCoordForXYAndResolution_(
|
||||
coordinate.x, coordinate.y, resolution);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Coordinate} coordinate Coordinate.
|
||||
* @param {number} x X.
|
||||
* @param {number} y Y.
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {boolean=} opt_reverseIntersectionPolicy Instead of letting edge
|
||||
* intersections go to the higher tile coordinate, let edge intersections
|
||||
@@ -262,25 +264,25 @@ ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndResolution = function(
|
||||
* @return {ol.TileCoord} Tile coordinate.
|
||||
* @private
|
||||
*/
|
||||
ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndResolution_ = function(
|
||||
coordinate, resolution, opt_reverseIntersectionPolicy) {
|
||||
ol.tilegrid.TileGrid.prototype.getTileCoordForXYAndResolution_ = function(
|
||||
x, y, resolution, opt_reverseIntersectionPolicy) {
|
||||
var z = this.getZForResolution(resolution);
|
||||
var scale = resolution / this.getResolution(z);
|
||||
var origin = this.getOrigin(z);
|
||||
var tileSize = this.getTileSize(z);
|
||||
|
||||
var x = scale * (coordinate.x - origin.x) / (resolution * tileSize.width);
|
||||
var y = scale * (coordinate.y - origin.y) / (resolution * tileSize.height);
|
||||
var tileCoordX = scale * (x - origin.x) / (resolution * tileSize.width);
|
||||
var tileCoordY = scale * (y - origin.y) / (resolution * tileSize.height);
|
||||
|
||||
if (!opt_reverseIntersectionPolicy) {
|
||||
x = Math.floor(x);
|
||||
y = Math.floor(y);
|
||||
tileCoordX = Math.floor(tileCoordX);
|
||||
tileCoordY = Math.floor(tileCoordY);
|
||||
} else {
|
||||
x = Math.ceil(x) - 1;
|
||||
y = Math.ceil(y) - 1;
|
||||
tileCoordX = Math.ceil(tileCoordX) - 1;
|
||||
tileCoordY = Math.ceil(tileCoordY) - 1;
|
||||
}
|
||||
|
||||
return new ol.TileCoord(z, x, y);
|
||||
return new ol.TileCoord(z, tileCoordX, tileCoordY);
|
||||
};
|
||||
|
||||
|
||||
@@ -292,7 +294,8 @@ 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.getTileCoordForXYAndResolution_(
|
||||
coordinate.x, coordinate.y, resolution);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -379,7 +379,7 @@ describe('ol.tilegrid.TileGrid', function() {
|
||||
});
|
||||
|
||||
|
||||
describe('getTileCoordForCoordAndResolution_', function() {
|
||||
describe('getTileCoordForXYAndResolution_', function() {
|
||||
it('returns higher tile coord for intersections by default', function() {
|
||||
var tileGrid = new ol.tilegrid.TileGrid({
|
||||
resolutions: resolutions,
|
||||
@@ -388,21 +388,18 @@ describe('ol.tilegrid.TileGrid', function() {
|
||||
tileSize: tileSize
|
||||
});
|
||||
|
||||
var coordinate;
|
||||
var tileCoord;
|
||||
|
||||
// gets higher tile for edge intersection
|
||||
coordinate = new ol.Coordinate(0, 0);
|
||||
tileCoord = tileGrid.getTileCoordForCoordAndResolution_(
|
||||
coordinate, 100);
|
||||
tileCoord = tileGrid.getTileCoordForXYAndResolution_(
|
||||
0, 0, 100);
|
||||
expect(tileCoord.z).to.eql(3);
|
||||
expect(tileCoord.x).to.eql(0);
|
||||
expect(tileCoord.y).to.eql(0);
|
||||
|
||||
// gets higher tile for edge intersection
|
||||
coordinate = new ol.Coordinate(100000, 100000);
|
||||
tileCoord = tileGrid.getTileCoordForCoordAndResolution_(
|
||||
coordinate, 100);
|
||||
tileCoord = tileGrid.getTileCoordForXYAndResolution_(
|
||||
100000, 100000, 100);
|
||||
expect(tileCoord.z).to.eql(3);
|
||||
expect(tileCoord.x).to.eql(10);
|
||||
expect(tileCoord.y).to.eql(10);
|
||||
@@ -417,21 +414,18 @@ describe('ol.tilegrid.TileGrid', function() {
|
||||
tileSize: tileSize
|
||||
});
|
||||
|
||||
var coordinate;
|
||||
var tileCoord;
|
||||
|
||||
// can get lower tile for edge intersection
|
||||
coordinate = new ol.Coordinate(0, 0);
|
||||
tileCoord = tileGrid.getTileCoordForCoordAndResolution_(
|
||||
coordinate, 100, true);
|
||||
tileCoord = tileGrid.getTileCoordForXYAndResolution_(
|
||||
0, 0, 100, true);
|
||||
expect(tileCoord.z).to.eql(3);
|
||||
expect(tileCoord.x).to.eql(-1);
|
||||
expect(tileCoord.y).to.eql(-1);
|
||||
|
||||
// gets higher tile for edge intersection
|
||||
coordinate = new ol.Coordinate(100000, 100000);
|
||||
tileCoord = tileGrid.getTileCoordForCoordAndResolution_(
|
||||
coordinate, 100, true);
|
||||
tileCoord = tileGrid.getTileCoordForXYAndResolution_(
|
||||
100000, 100000, 100, true);
|
||||
expect(tileCoord.z).to.eql(3);
|
||||
expect(tileCoord.x).to.eql(9);
|
||||
expect(tileCoord.y).to.eql(9);
|
||||
|
||||
Reference in New Issue
Block a user