From c69974f4606f2093c5d7902258fbda141768a684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Thu, 9 Oct 2014 13:20:51 +0200 Subject: [PATCH 1/3] Add more explanations to xyz-esri-4326-512 example --- examples/xyz-esri-4326-512.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/examples/xyz-esri-4326-512.js b/examples/xyz-esri-4326-512.js index 7f525ff5c1..64f865633f 100644 --- a/examples/xyz-esri-4326-512.js +++ b/examples/xyz-esri-4326-512.js @@ -14,10 +14,18 @@ var attribution = new ol.Attribution({ var projection = ol.proj.get('EPSG:4326'); var projectionExtent = projection.getExtent(); -var size = ol.extent.getWidth(projectionExtent) / 256; +// 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); -for (var z = 2; z < 18; ++z) { - resolutions[z - 2] = size / Math.pow(2, z); +var z; +for (z = 0; z < 16; ++z) { + resolutions[z] = maxResolution / Math.pow(2, z); } var url = 'http://services.arcgisonline.com/arcgis/rest/services/' + From efd2357d5ba935b95f9e79b80e0bbe8cbeee402e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Thu, 9 Oct 2014 13:21:24 +0200 Subject: [PATCH 2/3] Fix typo in xyz-esri-4326-512 example --- examples/xyz-esri-4326-512.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/xyz-esri-4326-512.js b/examples/xyz-esri-4326-512.js index 64f865633f..0b84f053ad 100644 --- a/examples/xyz-esri-4326-512.js +++ b/examples/xyz-esri-4326-512.js @@ -35,8 +35,7 @@ var map = new ol.Map({ target: 'map', layers: [ new ol.layer.Tile({ - extent: projectionExtent, - /* ol.source.XYZ and ol.tilegrid.XYZ have nu resolutions config */ + /* ol.source.XYZ and ol.tilegrid.XYZ have no resolutions config */ source: new ol.source.TileImage({ attributions: [attribution], tileUrlFunction: function(tileCoord, pixelRatio, projection) { From 8067bc3863400fa5f411e7d939bb146273aa9697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Thu, 9 Oct 2014 13:22:01 +0200 Subject: [PATCH 3/3] Show how to wrap world in xyz-esri-4326-512 example --- examples/xyz-esri-4326-512.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/examples/xyz-esri-4326-512.js b/examples/xyz-esri-4326-512.js index 0b84f053ad..c10c5d270b 100644 --- a/examples/xyz-esri-4326-512.js +++ b/examples/xyz-esri-4326-512.js @@ -28,8 +28,8 @@ for (z = 0; z < 16; ++z) { resolutions[z] = maxResolution / Math.pow(2, z); } -var url = 'http://services.arcgisonline.com/arcgis/rest/services/' + - 'ESRI_Imagery_World_2D/MapServer/tile/'; +var urlTemplate = 'http://services.arcgisonline.com/arcgis/rest/services/' + + 'ESRI_Imagery_World_2D/MapServer/tile/{z}/{y}/{x}'; var map = new ol.Map({ target: 'map', @@ -39,8 +39,20 @@ var map = new ol.Map({ source: new ol.source.TileImage({ attributions: [attribution], tileUrlFunction: function(tileCoord, pixelRatio, projection) { - return url + tileCoord[0] + '/' + (-tileCoord[2] - 1) + '/' + - tileCoord[1]; + 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()); }, projection: projection, tileGrid: new ol.tilegrid.TileGrid({