Skip to content

Commit

Permalink
support 'tms' tile scheme (#2565)
Browse files Browse the repository at this point in the history
  • Loading branch information
indus authored and mourner committed May 18, 2016
1 parent 08ac032 commit 1fe021b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions js/source/raster_tile_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var normalizeURL = require('../util/mapbox').normalizeTileURL;
module.exports = RasterTileSource;

function RasterTileSource(options) {
util.extend(this, util.pick(options, ['url', 'tileSize']));
util.extend(this, util.pick(options, ['url', 'scheme', 'tileSize']));

Source._loadTileJSON.call(this, options);
}
Expand All @@ -18,6 +18,7 @@ RasterTileSource.prototype = util.inherit(Evented, {
minzoom: 0,
maxzoom: 22,
roundZoom: true,
scheme: 'xyz',
tileSize: 512,
_loaded: false,

Expand Down Expand Up @@ -51,7 +52,7 @@ RasterTileSource.prototype = util.inherit(Evented, {
getTile: Source._getTile,

_loadTile: function(tile) {
var url = normalizeURL(tile.coord.url(this.tiles), this.url, this.tileSize);
var url = normalizeURL(tile.coord.url(this.tiles, null, this.scheme), this.url, this.tileSize);

tile.request = ajax.getImage(url, done.bind(this));

Expand Down
4 changes: 2 additions & 2 deletions js/source/tile_coord.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ TileCoord.fromID = function(id) {
};

// given a list of urls, choose a url template and return a tile URL
TileCoord.prototype.url = function(urls, sourceMaxZoom) {
TileCoord.prototype.url = function(urls, sourceMaxZoom, scheme) {
return urls[(this.x + this.y) % urls.length]
.replace('{prefix}', (this.x % 16).toString(16) + (this.y % 16).toString(16))
.replace('{z}', Math.min(this.z, sourceMaxZoom || this.z))
.replace('{x}', this.x)
.replace('{y}', this.y);
.replace('{y}', scheme === 'tms' ? (Math.pow(2, this.z) - this.y - 1) : this.y);
};

// Return the coordinate of the parent tile
Expand Down
5 changes: 3 additions & 2 deletions js/source/vector_tile_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var normalizeURL = require('../util/mapbox').normalizeTileURL;
module.exports = VectorTileSource;

function VectorTileSource(options) {
util.extend(this, util.pick(options, ['url', 'tileSize']));
util.extend(this, util.pick(options, ['url', 'scheme', 'tileSize']));
this._options = util.extend({ type: 'vector' }, options);

if (this.tileSize !== 512) {
Expand All @@ -21,6 +21,7 @@ function VectorTileSource(options) {
VectorTileSource.prototype = util.inherit(Evented, {
minzoom: 0,
maxzoom: 22,
scheme: 'xyz',
tileSize: 512,
reparseOverscaled: true,
_loaded: false,
Expand Down Expand Up @@ -59,7 +60,7 @@ VectorTileSource.prototype = util.inherit(Evented, {
_loadTile: function(tile) {
var overscaling = tile.coord.z > this.maxzoom ? Math.pow(2, tile.coord.z - this.maxzoom) : 1;
var params = {
url: normalizeURL(tile.coord.url(this.tiles, this.maxzoom), this.url),
url: normalizeURL(tile.coord.url(this.tiles, this.maxzoom, this.scheme), this.url),
uid: tile.uid,
coord: tile.coord,
zoom: tile.coord.z,
Expand Down

0 comments on commit 1fe021b

Please sign in to comment.