Merge pull request #3722 from ahocevar/tilejson-tilegrid
Use the correct TileCoord transform function
This commit is contained in:
@@ -76,7 +76,7 @@ ol.source.TileJSON.prototype.handleTileJSONResponse = function(tileJSON) {
|
|||||||
this.tileGrid = tileGrid;
|
this.tileGrid = tileGrid;
|
||||||
|
|
||||||
this.tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
|
this.tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
|
||||||
tileGrid.createTileCoordTransform({extent: extent}),
|
ol.tilegrid.createOriginTopLeftTileCoordTransform(tileGrid),
|
||||||
ol.TileUrlFunction.createFromTemplates(tileJSON.tiles));
|
ol.TileUrlFunction.createFromTemplates(tileJSON.tiles));
|
||||||
|
|
||||||
if (goog.isDef(tileJSON.attribution) &&
|
if (goog.isDef(tileJSON.attribution) &&
|
||||||
|
|||||||
@@ -137,9 +137,7 @@ ol.source.TileUTFGrid.prototype.handleTileJSONResponse = function(tileJSON) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.tileUrlFunction_ = ol.TileUrlFunction.withTileCoordTransform(
|
this.tileUrlFunction_ = ol.TileUrlFunction.withTileCoordTransform(
|
||||||
tileGrid.createTileCoordTransform({
|
ol.tilegrid.createOriginTopLeftTileCoordTransform(tileGrid),
|
||||||
extent: extent
|
|
||||||
}),
|
|
||||||
ol.TileUrlFunction.createFromTemplates(grids));
|
ol.TileUrlFunction.createFromTemplates(grids));
|
||||||
|
|
||||||
if (goog.isDef(tileJSON.attribution)) {
|
if (goog.isDef(tileJSON.attribution)) {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ goog.provide('ol.tilegrid.TileGrid');
|
|||||||
|
|
||||||
goog.require('goog.array');
|
goog.require('goog.array');
|
||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
goog.require('goog.functions');
|
|
||||||
goog.require('goog.math');
|
goog.require('goog.math');
|
||||||
goog.require('goog.object');
|
goog.require('goog.object');
|
||||||
goog.require('ol');
|
goog.require('ol');
|
||||||
@@ -165,15 +164,13 @@ ol.tilegrid.TileGrid.tmpTileCoord_ = [0, 0, 0];
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the identity function. May be overridden in subclasses.
|
* Source specific TileCoord transform function. May be implemented by
|
||||||
|
* subclasses.
|
||||||
* @param {{extent: (ol.Extent|undefined)}=} opt_options Options.
|
* @param {{extent: (ol.Extent|undefined)}=} opt_options Options.
|
||||||
* @return {function(ol.TileCoord, ol.proj.Projection, ol.TileCoord=):
|
* @return {function(ol.TileCoord, ol.proj.Projection, ol.TileCoord=):
|
||||||
* ol.TileCoord} Tile coordinate transform.
|
* ol.TileCoord} Tile coordinate transform.
|
||||||
*/
|
*/
|
||||||
ol.tilegrid.TileGrid.prototype.createTileCoordTransform =
|
ol.tilegrid.TileGrid.prototype.createTileCoordTransform = goog.abstractMethod;
|
||||||
function(opt_options) {
|
|
||||||
return goog.functions.identity;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
64
test/spec/ol/source/tilejsonsource.test.js
Normal file
64
test/spec/ol/source/tilejsonsource.test.js
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
goog.provide('ol.test.source.TileJSON');
|
||||||
|
|
||||||
|
|
||||||
|
describe('ol.source.TileJSON', function() {
|
||||||
|
|
||||||
|
describe('tileUrlFunction', function() {
|
||||||
|
|
||||||
|
var source, tileGrid;
|
||||||
|
|
||||||
|
beforeEach(function(done) {
|
||||||
|
source = new ol.source.TileJSON({
|
||||||
|
url: 'http://api.tiles.mapbox.com/v3/mapbox.geography-class.jsonp'
|
||||||
|
});
|
||||||
|
var key = source.on('change', function() {
|
||||||
|
if (source.getState() === 'ready') {
|
||||||
|
source.unByKey(key);
|
||||||
|
tileGrid = source.getTileGrid();
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('uses the correct tile coordinates', function() {
|
||||||
|
|
||||||
|
var coordinate = [829330.2064098881, 5933916.615134273];
|
||||||
|
var regex = /\/([0-9]*\/[0-9]*\/[0-9]*)\.png$/;
|
||||||
|
var tileUrl;
|
||||||
|
|
||||||
|
tileUrl = source.tileUrlFunction(
|
||||||
|
tileGrid.getTileCoordForCoordAndZ(coordinate, 0));
|
||||||
|
expect(tileUrl.match(regex)[1]).to.eql('0/0/0');
|
||||||
|
|
||||||
|
tileUrl = source.tileUrlFunction(
|
||||||
|
tileGrid.getTileCoordForCoordAndZ(coordinate, 1));
|
||||||
|
expect(tileUrl.match(regex)[1]).to.eql('1/1/0');
|
||||||
|
|
||||||
|
tileUrl = source.tileUrlFunction(
|
||||||
|
tileGrid.getTileCoordForCoordAndZ(coordinate, 2));
|
||||||
|
expect(tileUrl.match(regex)[1]).to.eql('2/2/1');
|
||||||
|
|
||||||
|
tileUrl = source.tileUrlFunction(
|
||||||
|
tileGrid.getTileCoordForCoordAndZ(coordinate, 3));
|
||||||
|
expect(tileUrl.match(regex)[1]).to.eql('3/4/2');
|
||||||
|
|
||||||
|
tileUrl = source.tileUrlFunction(
|
||||||
|
tileGrid.getTileCoordForCoordAndZ(coordinate, 4));
|
||||||
|
expect(tileUrl.match(regex)[1]).to.eql('4/8/5');
|
||||||
|
|
||||||
|
tileUrl = source.tileUrlFunction(
|
||||||
|
tileGrid.getTileCoordForCoordAndZ(coordinate, 5));
|
||||||
|
expect(tileUrl.match(regex)[1]).to.eql('5/16/11');
|
||||||
|
|
||||||
|
tileUrl = source.tileUrlFunction(
|
||||||
|
tileGrid.getTileCoordForCoordAndZ(coordinate, 6));
|
||||||
|
expect(tileUrl.match(regex)[1]).to.eql('6/33/22');
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
goog.require('ol.TileCoord');
|
||||||
|
goog.require('ol.source.TileJSON');
|
||||||
Reference in New Issue
Block a user