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