Replace multiple placeholder occurrences in templates
This commit is contained in:
@@ -31,6 +31,10 @@ ol.TileCoordTransformType;
|
|||||||
* @return {ol.TileUrlFunctionType} Tile URL function.
|
* @return {ol.TileUrlFunctionType} Tile URL function.
|
||||||
*/
|
*/
|
||||||
ol.TileUrlFunction.createFromTemplate = function(template) {
|
ol.TileUrlFunction.createFromTemplate = function(template) {
|
||||||
|
var zRegEx = /\{z\}/g;
|
||||||
|
var xRegEx = /\{x\}/g;
|
||||||
|
var yRegEx = /\{y\}/g;
|
||||||
|
var dashYRegEx = /\{-y\}/g;
|
||||||
return (
|
return (
|
||||||
/**
|
/**
|
||||||
* @param {ol.TileCoord} tileCoord Tile Coordinate.
|
* @param {ol.TileCoord} tileCoord Tile Coordinate.
|
||||||
@@ -42,10 +46,10 @@ ol.TileUrlFunction.createFromTemplate = function(template) {
|
|||||||
if (goog.isNull(tileCoord)) {
|
if (goog.isNull(tileCoord)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
} else {
|
} else {
|
||||||
return template.replace('{z}', tileCoord.z.toString())
|
return template.replace(zRegEx, tileCoord.z.toString())
|
||||||
.replace('{x}', tileCoord.x.toString())
|
.replace(xRegEx, tileCoord.x.toString())
|
||||||
.replace('{y}', tileCoord.y.toString())
|
.replace(yRegEx, tileCoord.y.toString())
|
||||||
.replace('{-y}', function() {
|
.replace(dashYRegEx, function() {
|
||||||
var y = (1 << tileCoord.z) - tileCoord.y - 1;
|
var y = (1 << tileCoord.z) - tileCoord.y - 1;
|
||||||
return y.toString();
|
return y.toString();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user