Merge pull request #4187 from ahocevar/dashy-tileurl
Fix {-y} template calculation for custom (TMS) tile grids
This commit is contained in:
@@ -75,7 +75,8 @@ ol.source.TileJSON.prototype.handleTileJSONResponse = function(tileJSON) {
|
||||
});
|
||||
this.tileGrid = tileGrid;
|
||||
|
||||
this.tileUrlFunction = ol.TileUrlFunction.createFromTemplates(tileJSON.tiles);
|
||||
this.tileUrlFunction =
|
||||
ol.TileUrlFunction.createFromTemplates(tileJSON.tiles, tileGrid);
|
||||
|
||||
if (tileJSON.attribution !== undefined &&
|
||||
goog.isNull(this.getAttributions())) {
|
||||
|
||||
@@ -136,7 +136,8 @@ ol.source.TileUTFGrid.prototype.handleTileJSONResponse = function(tileJSON) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.tileUrlFunction_ = ol.TileUrlFunction.createFromTemplates(grids);
|
||||
this.tileUrlFunction_ =
|
||||
ol.TileUrlFunction.createFromTemplates(grids, tileGrid);
|
||||
|
||||
if (tileJSON.attribution !== undefined) {
|
||||
var attributionExtent = extent !== undefined ?
|
||||
|
||||
@@ -341,7 +341,7 @@ ol.source.TileVector.prototype.setTileUrlFunction = function(tileUrlFunction) {
|
||||
*/
|
||||
ol.source.TileVector.prototype.setUrl = function(url) {
|
||||
this.setTileUrlFunction(ol.TileUrlFunction.createFromTemplates(
|
||||
ol.TileUrlFunction.expandUrl(url)));
|
||||
ol.TileUrlFunction.expandUrl(url), this.tileGrid_));
|
||||
};
|
||||
|
||||
|
||||
@@ -349,5 +349,6 @@ ol.source.TileVector.prototype.setUrl = function(url) {
|
||||
* @param {Array.<string>} urls URLs.
|
||||
*/
|
||||
ol.source.TileVector.prototype.setUrls = function(urls) {
|
||||
this.setTileUrlFunction(ol.TileUrlFunction.createFromTemplates(urls));
|
||||
this.setTileUrlFunction(
|
||||
ol.TileUrlFunction.createFromTemplates(urls, this.tileGrid_));
|
||||
};
|
||||
|
||||
@@ -87,7 +87,7 @@ ol.source.XYZ.prototype.getUrls = function() {
|
||||
*/
|
||||
ol.source.XYZ.prototype.setUrl = function(url) {
|
||||
this.setTileUrlFunction(ol.TileUrlFunction.createFromTemplates(
|
||||
ol.TileUrlFunction.expandUrl(url)));
|
||||
ol.TileUrlFunction.expandUrl(url), this.tileGrid));
|
||||
this.urls_ = [url];
|
||||
};
|
||||
|
||||
@@ -97,6 +97,7 @@ ol.source.XYZ.prototype.setUrl = function(url) {
|
||||
* @param {Array.<string>} urls URLs.
|
||||
*/
|
||||
ol.source.XYZ.prototype.setUrls = function(urls) {
|
||||
this.setTileUrlFunction(ol.TileUrlFunction.createFromTemplates(urls));
|
||||
this.setTileUrlFunction(
|
||||
ol.TileUrlFunction.createFromTemplates(urls, this.tileGrid));
|
||||
this.urls_ = urls;
|
||||
};
|
||||
|
||||
@@ -33,9 +33,10 @@ ol.TileCoordTransformType;
|
||||
|
||||
/**
|
||||
* @param {string} template Template.
|
||||
* @param {ol.tilegrid.TileGrid} tileGrid Tile grid.
|
||||
* @return {ol.TileUrlFunctionType} Tile URL function.
|
||||
*/
|
||||
ol.TileUrlFunction.createFromTemplate = function(template) {
|
||||
ol.TileUrlFunction.createFromTemplate = function(template, tileGrid) {
|
||||
var zRegEx = /\{z\}/g;
|
||||
var xRegEx = /\{x\}/g;
|
||||
var yRegEx = /\{y\}/g;
|
||||
@@ -52,15 +53,19 @@ ol.TileUrlFunction.createFromTemplate = function(template) {
|
||||
return undefined;
|
||||
} else {
|
||||
return template.replace(zRegEx, tileCoord[0].toString())
|
||||
.replace(xRegEx, tileCoord[1].toString())
|
||||
.replace(yRegEx, function() {
|
||||
var y = -tileCoord[2] - 1;
|
||||
return y.toString();
|
||||
})
|
||||
.replace(dashYRegEx, function() {
|
||||
var y = (1 << tileCoord[0]) + tileCoord[2];
|
||||
return y.toString();
|
||||
});
|
||||
.replace(xRegEx, tileCoord[1].toString())
|
||||
.replace(yRegEx, function() {
|
||||
var y = -tileCoord[2] - 1;
|
||||
return y.toString();
|
||||
})
|
||||
.replace(dashYRegEx, function() {
|
||||
var z = tileCoord[0];
|
||||
var range = tileGrid.getFullTileRange(z);
|
||||
goog.asserts.assert(range,
|
||||
'The {-y} template requires a tile grid with extent');
|
||||
var y = range.getHeight() + tileCoord[2];
|
||||
return y.toString();
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -68,11 +73,17 @@ ol.TileUrlFunction.createFromTemplate = function(template) {
|
||||
|
||||
/**
|
||||
* @param {Array.<string>} templates Templates.
|
||||
* @param {ol.tilegrid.TileGrid} tileGrid Tile grid.
|
||||
* @return {ol.TileUrlFunctionType} Tile URL function.
|
||||
*/
|
||||
ol.TileUrlFunction.createFromTemplates = function(templates) {
|
||||
return ol.TileUrlFunction.createFromTileUrlFunctions(
|
||||
templates.map(ol.TileUrlFunction.createFromTemplate));
|
||||
ol.TileUrlFunction.createFromTemplates = function(templates, tileGrid) {
|
||||
var len = templates.length;
|
||||
var tileUrlFunctions = new Array(len);
|
||||
for (var i = 0; i < len; ++i) {
|
||||
tileUrlFunctions[i] = ol.TileUrlFunction.createFromTemplate(
|
||||
templates[i], tileGrid);
|
||||
}
|
||||
return ol.TileUrlFunction.createFromTileUrlFunctions(tileUrlFunctions);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user