Merge pull request #3780 from ahocevar/call-tileurlfunction-with-transformed-tilecoord
Only expose transformed tile coordinates to the API
This commit is contained in:
@@ -3,8 +3,7 @@ template: example.html
|
||||
title: Canvas tiles example
|
||||
shortdesc: Renders tiles with coordinates for debugging.
|
||||
docs: >
|
||||
<p>The black grid tiles are generated on the client with an HTML5 canvas. Note that the tile coordinates are ol3 normalized tile coordinates (origin bottom left), not
|
||||
OSM tile coordinates (origin top left).</p>
|
||||
The black grid tiles are generated on the client with an HTML5 canvas. In this example, the `ol.source.TileDebug` source uses the tile grid of the `ol.source.OSM` source, so the displayed tile coordinates are the same as those for OSM tile requests.
|
||||
tags: "layers, openstreetmap, canvas"
|
||||
---
|
||||
<div class="row-fluid">
|
||||
|
||||
@@ -7,15 +7,16 @@ goog.require('ol.source.OSM');
|
||||
goog.require('ol.source.TileDebug');
|
||||
|
||||
|
||||
var osmSource = new ol.source.OSM();
|
||||
var map = new ol.Map({
|
||||
layers: [
|
||||
new ol.layer.Tile({
|
||||
source: new ol.source.OSM()
|
||||
source: osmSource
|
||||
}),
|
||||
new ol.layer.Tile({
|
||||
source: new ol.source.TileDebug({
|
||||
projection: 'EPSG:3857',
|
||||
tileGrid: ol.tilegrid.createXYZ({maxZoom: 22})
|
||||
tileGrid: osmSource.getTileGrid()
|
||||
})
|
||||
})
|
||||
],
|
||||
|
||||
@@ -3,7 +3,7 @@ template: example.html
|
||||
title: XYZ Esri EPSG:4326 tileSize 512 example
|
||||
shortdesc: Example of a XYZ source in EPSG:4326 using Esri 512x512 tiles.
|
||||
docs: >
|
||||
ArcGIS REST tile services with custom tile sizes (here: 512x512 pixels) and projection (here: EPSG:4326) are supported by `ol.source.XYZ`. A custom tile grid and tile url function are required.
|
||||
ArcGIS REST tile services with custom tile sizes (here: 512x512 pixels) and projection (here: EPSG:4326) are supported by `ol.source.XYZ`. A custom tile url function is used to handle zoom level offsets.
|
||||
tags: "xyz, esri, tilesize, custom projection"
|
||||
---
|
||||
<div class="row-fluid">
|
||||
|
||||
@@ -1,33 +1,19 @@
|
||||
goog.require('ol.Attribution');
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.View');
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.layer.Tile');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.source.TileImage');
|
||||
goog.require('ol.tilegrid.TileGrid');
|
||||
goog.require('ol.source.XYZ');
|
||||
|
||||
var attribution = new ol.Attribution({
|
||||
html: 'Copyright:© 2013 ESRI, i-cubed, GeoEye'
|
||||
});
|
||||
|
||||
var projection = ol.proj.get('EPSG:4326');
|
||||
var projectionExtent = projection.getExtent();
|
||||
|
||||
// The tile size supported by the ArcGIS tile service.
|
||||
var tileSize = 512;
|
||||
|
||||
// Calculate the resolutions supported by the ArcGIS tile service.
|
||||
// There are 16 resolutions, with a factor of 2 between successive
|
||||
// resolutions. The max resolution is such that the world (360°)
|
||||
// fits into two (512x512 px) tiles.
|
||||
var maxResolution = ol.extent.getWidth(projectionExtent) / (tileSize * 2);
|
||||
var resolutions = new Array(16);
|
||||
var z;
|
||||
for (z = 0; z < 16; ++z) {
|
||||
resolutions[z] = maxResolution / Math.pow(2, z);
|
||||
}
|
||||
|
||||
var urlTemplate = 'http://services.arcgisonline.com/arcgis/rest/services/' +
|
||||
'ESRI_Imagery_World_2D/MapServer/tile/{z}/{y}/{x}';
|
||||
|
||||
@@ -35,31 +21,17 @@ var map = new ol.Map({
|
||||
target: 'map',
|
||||
layers: [
|
||||
new ol.layer.Tile({
|
||||
/* ol.source.XYZ and ol.tilegrid.TileGrid have no resolutions config */
|
||||
source: new ol.source.TileImage({
|
||||
source: new ol.source.XYZ({
|
||||
attributions: [attribution],
|
||||
tileUrlFunction: function(tileCoord, pixelRatio, projection) {
|
||||
var z = tileCoord[0];
|
||||
var x = tileCoord[1];
|
||||
var y = -tileCoord[2] - 1;
|
||||
// wrap the world on the X axis
|
||||
var n = Math.pow(2, z + 1); // 2 tiles at z=0
|
||||
x = x % n;
|
||||
if (x * n < 0) {
|
||||
// x and n differ in sign so add n to wrap the result
|
||||
// to the correct sign
|
||||
x = x + n;
|
||||
}
|
||||
return urlTemplate.replace('{z}', z.toString())
|
||||
.replace('{y}', y.toString())
|
||||
.replace('{x}', x.toString());
|
||||
},
|
||||
maxZoom: 16,
|
||||
projection: projection,
|
||||
tileGrid: new ol.tilegrid.TileGrid({
|
||||
origin: ol.extent.getTopLeft(projectionExtent),
|
||||
resolutions: resolutions,
|
||||
tileSize: 512
|
||||
})
|
||||
tileSize: 512,
|
||||
tileUrlFunction: function(tileCoord) {
|
||||
return urlTemplate.replace('{z}', (tileCoord[0] - 1).toString())
|
||||
.replace('{x}', tileCoord[1].toString())
|
||||
.replace('{y}', tileCoord[2].toString());
|
||||
},
|
||||
wrapX: true
|
||||
})
|
||||
})
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user