Allow '{-y}' placeholder

This commit is contained in:
Frederic Junod
2014-04-14 13:57:36 +02:00
parent 738fe65268
commit 9b5512c065
5 changed files with 105 additions and 6 deletions

51
examples/xyz.html Normal file
View File

@@ -0,0 +1,51 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<link rel="stylesheet" href="../css/ol.css" type="text/css">
<link rel="stylesheet" href="../resources/bootstrap/css/bootstrap.min.css" type="text/css">
<link rel="stylesheet" href="../resources/layout.css" type="text/css">
<link rel="stylesheet" href="../resources/bootstrap/css/bootstrap-responsive.min.css" type="text/css">
<title>XYZ example</title>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="./"><img src="../resources/logo.png"> OpenLayers 3 Examples</a>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<div id="map" class="map"></div>
</div>
</div>
<div class="row-fluid">
<div class="span12">
<h4 id="title">XYZ example</h4>
<p id="shortdesc">Example of a XYZ source.</p>
<div id="docs">
<p>See the <a href="xyz.js" target="_blank">xyz.js source</a> for details on how this is done.</p>
</div>
<div id="tags">xyz</div>
</div>
</div>
</div>
<script src="jquery.min.js" type="text/javascript"></script>
<script src="../resources/example-behaviour.js" type="text/javascript"></script>
<script src="loader.js?id=xyz" type="text/javascript"></script>
</body>
</html>

40
examples/xyz.js Normal file
View File

@@ -0,0 +1,40 @@
goog.require('ol.Attribution');
goog.require('ol.Map');
goog.require('ol.View2D');
goog.require('ol.layer.Tile');
goog.require('ol.source.OSM');
goog.require('ol.source.XYZ');
var attribution = new ol.Attribution({
html: 'Tiles &copy; <a href="http://maps.nls.uk/townplans/glasgow_1.html">' +
'National Library of Scotland</a>'
});
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM({
attributions: [
new ol.Attribution({
html: 'Tiles &copy; <a href="http://www.opencyclemap.org/">' +
'OpenCycleMap</a>'
}),
ol.source.OSM.DATA_ATTRIBUTION
],
url: 'http://{a-c}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png'
})
}),
new ol.layer.Tile({
source: new ol.source.XYZ({
attributions: [attribution],
url: 'http://geo.nls.uk/maps/towns/glasgow1857/{z}/{x}/{-y}.png'
})
})
],
view: new ol.View2D({
center: [-472202, 7530279],
zoom: 12
})
});

View File

@@ -2774,7 +2774,7 @@ olx.source.TileVectorOptions.prototype.tileUrlFunction;
/**
* URL template. Must include `{x}`, `{y}`, and `{z}` placeholders.
* URL template. Must include `{x}`, `{y}` or `{-y}`, and `{z}` placeholders.
* @type {string|undefined}
*/
olx.source.TileVectorOptions.prototype.url;
@@ -3173,8 +3173,8 @@ olx.source.OSMOptions.prototype.tileLoadFunction;
/**
* URL template. Must include `{x}`, `{y}`, and `{z}` placeholders. Default is
* `//{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png`.
* URL template. Must include `{x}`, `{y}` or `{-y}`, and `{z}` placeholders.
* Default is `//{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png`.
* @type {string|undefined}
*/
olx.source.OSMOptions.prototype.url;
@@ -3573,7 +3573,7 @@ olx.source.StamenOptions.prototype.tileLoadFunction;
/**
* URL template. Must include `{x}`, `{y}`, and `{z}` placeholders.
* URL template. Must include `{x}`, `{y}` or `{-y}`, and `{z}` placeholders.
* @type {string|undefined}
*/
olx.source.StamenOptions.prototype.url;
@@ -4252,7 +4252,7 @@ olx.source.XYZOptions.prototype.tileUrlFunction;
/**
* URL template. Must include `{x}`, `{y}`, and `{z}` placeholders.
* URL template. Must include `{x}`, `{y}` or `{-y}`, and `{z}` placeholders.
* @type {string|undefined}
*/
olx.source.XYZOptions.prototype.url;

View File

@@ -44,7 +44,11 @@ ol.TileUrlFunction.createFromTemplate = function(template) {
} else {
return template.replace('{z}', tileCoord.z.toString())
.replace('{x}', tileCoord.x.toString())
.replace('{y}', tileCoord.y.toString());
.replace('{y}', tileCoord.y.toString())
.replace('{-y}', function() {
var y = (1 << tileCoord.z) - tileCoord.y - 1;
return y.toString();
});
}
});
};

View File

@@ -33,6 +33,10 @@ describe('ol.TileUrlFunction', function() {
expect(tileUrl(new ol.TileCoord(3, 2, 1))).to.eql('3/2/1');
expect(tileUrl(null)).to.be(undefined);
});
it('accepts {-y} placeholder', function() {
var tileUrl = ol.TileUrlFunction.createFromTemplate('{z}/{x}/{-y}');
expect(tileUrl(new ol.TileCoord(3, 2, 2))).to.eql('3/2/5');
});
});
describe('createFromTemplates', function() {