From 3c41470d7a8c6f6255a6f9a1e380ccc658353db7 Mon Sep 17 00:00:00 2001 From: Francisco Dans Date: Mon, 5 Jan 2015 11:15:18 +0100 Subject: [PATCH 1/7] adjusts tile xy value when coordinates are out of bounds --- .../leaflet/leaflet_tileloader_mixin.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/torque/leaflet/leaflet_tileloader_mixin.js b/lib/torque/leaflet/leaflet_tileloader_mixin.js index 5d77c63..06f8c36 100644 --- a/lib/torque/leaflet/leaflet_tileloader_mixin.js +++ b/lib/torque/leaflet/leaflet_tileloader_mixin.js @@ -116,6 +116,7 @@ L.Mixin.TileLoader = { for (j = bounds.min.y; j <= bounds.max.y; j++) { for (i = bounds.min.x; i <= bounds.max.x; i++) { point = new L.Point(i, j); + this._adjustTilePoint(point); point.zoom = zoom; if (this._tileShouldBeLoaded(point)) { @@ -143,5 +144,36 @@ L.Mixin.TileLoader = { } this.fire("tilesLoading"); + }, + _adjustTilePoint: function (tilePoint) { + + var limit = this._getWrapTileNum(); + + // wrap tile coordinates + if (!this.options.continuousWorld && !this.options.noWrap) { + tilePoint.x = ((tilePoint.x % limit.x) + limit.x) % limit.x; + } + + if (this.options.tms) { + tilePoint.y = limit.y - tilePoint.y - 1; + } + }, + _getWrapTileNum: function () { + var crs = this._map.options.crs, + size = crs.getSize(this._map.getZoom()); + return size.divideBy(this._getTileSize())._floor(); + }, + _getTileSize: function () { + var map = this._map, + zoom = map.getZoom() + this.options.zoomOffset, + zoomN = this.options.maxNativeZoom, + tileSize = this.options.tileSize; + + if (zoomN && zoom > zoomN) { + tileSize = Math.round(map.getZoomScale(zoom) / map.getZoomScale(zoomN) * tileSize); + } + + return tileSize; } + } From 1a2c6f2ab01c3f47c0780e139901f2550bb547f0 Mon Sep 17 00:00:00 2001 From: Francisco Dans Date: Mon, 12 Jan 2015 16:21:52 +0100 Subject: [PATCH 2/7] removes adjust operations from tileloader_mixin --- lib/torque/leaflet/leaflet_tileloader_mixin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/torque/leaflet/leaflet_tileloader_mixin.js b/lib/torque/leaflet/leaflet_tileloader_mixin.js index 06f8c36..9b429ba 100644 --- a/lib/torque/leaflet/leaflet_tileloader_mixin.js +++ b/lib/torque/leaflet/leaflet_tileloader_mixin.js @@ -116,7 +116,7 @@ L.Mixin.TileLoader = { for (j = bounds.min.y; j <= bounds.max.y; j++) { for (i = bounds.min.x; i <= bounds.max.x; i++) { point = new L.Point(i, j); - this._adjustTilePoint(point); + //this._adjustTilePoint(point); point.zoom = zoom; if (this._tileShouldBeLoaded(point)) { From 1c0057b0eded0f5244bd12bdc5efc36332def04b Mon Sep 17 00:00:00 2001 From: Francisco Dans Date: Mon, 12 Jan 2015 16:22:47 +0100 Subject: [PATCH 3/7] adds corrected tile values to tile object in order to for the URL correctly --- lib/torque/leaflet/torque.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lib/torque/leaflet/torque.js b/lib/torque/leaflet/torque.js index 9f8d8c7..ec322cc 100644 --- a/lib/torque/leaflet/torque.js +++ b/lib/torque/leaflet/torque.js @@ -84,6 +84,11 @@ L.TorqueLayer = L.CanvasLayer.extend({ // for each tile shown on the map request the data this.on('tileAdded', function(t) { + var fixedPoint = new L.Point(t.x, t.y); + this._adjustTilePoint(fixedPoint); + t.corrected = {}; + t.corrected.x = fixedPoint.x; + t.corrected.y = fixedPoint.y; var tileData = this.provider.getTileData(t, t.zoom, function(tileData) { // don't load tiles that are not being shown if (t.zoom !== self._map.getZoom()) return; @@ -97,6 +102,36 @@ L.TorqueLayer = L.CanvasLayer.extend({ }, + _adjustTilePoint: function (tilePoint) { + + var limit = this._getWrapTileNum(); + + // wrap tile coordinates + if (!this.options.continuousWorld && !this.options.noWrap) { + tilePoint.x = ((tilePoint.x % limit.x) + limit.x) % limit.x; + } + + if (this.options.tms) { + tilePoint.y = limit.y - tilePoint.y - 1; + } + }, + _getWrapTileNum: function () { + var crs = this._map.options.crs, + size = crs.getSize(this._map.getZoom()); + return size.divideBy(this._getTileSize())._floor(); + }, + _getTileSize: function () { + var map = this._map, + zoom = map.getZoom() + this.options.zoomOffset, + zoomN = this.options.maxNativeZoom, + tileSize = this.options.tileSize; + + if (zoomN && zoom > zoomN) { + tileSize = Math.round(map.getZoomScale(zoom) / map.getZoomScale(zoomN) * tileSize); + } + + return tileSize; + }, _clearTileCaches: function() { var t, tile; From bfcd6ca06fbd7a2188e053c02f24d83c9a7d4f95 Mon Sep 17 00:00:00 2001 From: Francisco Dans Date: Mon, 12 Jan 2015 16:23:38 +0100 Subject: [PATCH 4/7] url always uses corrected values from tile object --- lib/torque/provider/windshaft.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/torque/provider/windshaft.js b/lib/torque/provider/windshaft.js index 14b7808..5671d2f 100644 --- a/lib/torque/provider/windshaft.js +++ b/lib/torque/provider/windshaft.js @@ -281,10 +281,10 @@ var self = this; var prof_fetch_time = Profiler.metric('torque.provider.windshaft.tile.fetch').start(); var subdomains = this.options.subdomains || '0123'; - var index = Math.abs(coord.x + coord.y) % subdomains.length; + var index = Math.abs(coord.corrected.x + coord.corrected.y) % subdomains.length; var url = this.templateUrl - .replace('{x}', coord.x) - .replace('{y}', coord.y) + .replace('{x}', coord.corrected.x) + .replace('{y}', coord.corrected.y) .replace('{z}', zoom) .replace('{s}', subdomains[index]) From 1e106b23b99b864c99a0c93f00f14a1ffea45f80 Mon Sep 17 00:00:00 2001 From: Francisco Dans Date: Mon, 12 Jan 2015 16:28:45 +0100 Subject: [PATCH 5/7] removes adjusting methods from mixin (this time for realsies) --- .../leaflet/leaflet_tileloader_mixin.js | 31 ------------------- 1 file changed, 31 deletions(-) diff --git a/lib/torque/leaflet/leaflet_tileloader_mixin.js b/lib/torque/leaflet/leaflet_tileloader_mixin.js index 9b429ba..1e72a48 100644 --- a/lib/torque/leaflet/leaflet_tileloader_mixin.js +++ b/lib/torque/leaflet/leaflet_tileloader_mixin.js @@ -116,7 +116,6 @@ L.Mixin.TileLoader = { for (j = bounds.min.y; j <= bounds.max.y; j++) { for (i = bounds.min.x; i <= bounds.max.x; i++) { point = new L.Point(i, j); - //this._adjustTilePoint(point); point.zoom = zoom; if (this._tileShouldBeLoaded(point)) { @@ -144,36 +143,6 @@ L.Mixin.TileLoader = { } this.fire("tilesLoading"); - }, - _adjustTilePoint: function (tilePoint) { - - var limit = this._getWrapTileNum(); - - // wrap tile coordinates - if (!this.options.continuousWorld && !this.options.noWrap) { - tilePoint.x = ((tilePoint.x % limit.x) + limit.x) % limit.x; - } - - if (this.options.tms) { - tilePoint.y = limit.y - tilePoint.y - 1; - } - }, - _getWrapTileNum: function () { - var crs = this._map.options.crs, - size = crs.getSize(this._map.getZoom()); - return size.divideBy(this._getTileSize())._floor(); - }, - _getTileSize: function () { - var map = this._map, - zoom = map.getZoom() + this.options.zoomOffset, - zoomN = this.options.maxNativeZoom, - tileSize = this.options.tileSize; - - if (zoomN && zoom > zoomN) { - tileSize = Math.round(map.getZoomScale(zoom) / map.getZoomScale(zoomN) * tileSize); - } - - return tileSize; } } From 8d8dbb29b45c582ff099511eb97dd8e183f9e79b Mon Sep 17 00:00:00 2001 From: Francisco Dans Date: Mon, 12 Jan 2015 16:47:51 +0100 Subject: [PATCH 6/7] changes test forming windshaft url --- test/provider.windshaft.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/provider.windshaft.test.js b/test/provider.windshaft.test.js index b2a35e3..82f6b9f 100644 --- a/test/provider.windshaft.test.js +++ b/test/provider.windshaft.test.js @@ -82,7 +82,7 @@ QUnit.module('provider.windshaft', { test("fetch tile", function() { windshaft._ready = true; - windshaft.getTileData({x: 0, y: 1}, 2, function() {}); + windshaft.getTileData({x: 0, y: 1, corrected: {x: 0, y: 1}}, 2, function() {}); equal(lastCall,"http://rambo.cartodb.com:80/api/v1/map/testlg/0/2/0/1.json.torque?testing=abcd%25"); }); From dac3246fcde4b56956b9d332ed00a4b9d2157bf1 Mon Sep 17 00:00:00 2001 From: Francisco Dans Date: Mon, 12 Jan 2015 16:53:01 +0100 Subject: [PATCH 7/7] style --- lib/torque/leaflet/torque.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/torque/leaflet/torque.js b/lib/torque/leaflet/torque.js index ec322cc..0a27be0 100644 --- a/lib/torque/leaflet/torque.js +++ b/lib/torque/leaflet/torque.js @@ -100,8 +100,8 @@ L.TorqueLayer = L.CanvasLayer.extend({ }); }, this); - }, + _adjustTilePoint: function (tilePoint) { var limit = this._getWrapTileNum(); @@ -115,11 +115,13 @@ L.TorqueLayer = L.CanvasLayer.extend({ tilePoint.y = limit.y - tilePoint.y - 1; } }, + _getWrapTileNum: function () { var crs = this._map.options.crs, size = crs.getSize(this._map.getZoom()); return size.divideBy(this._getTileSize())._floor(); }, + _getTileSize: function () { var map = this._map, zoom = map.getZoom() + this.options.zoomOffset,