Merge pull request #84 from CartoDB/coord-wrap
Adjusts tile xy value when coordinates are out of bounds
This commit is contained in:
commit
93e0b8129b
@ -144,4 +144,5 @@ L.Mixin.TileLoader = {
|
||||
this.fire("tilesLoading");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
@ -95,7 +100,39 @@ L.TorqueLayer = L.CanvasLayer.extend({
|
||||
});
|
||||
}, this);
|
||||
|
||||
},
|
||||
|
||||
_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() {
|
||||
|
@ -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])
|
||||
|
||||
|
@ -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");
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user