Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support 'tms' tile scheme #2565

Merged
merged 1 commit into from
May 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I'm using mbtiles, but i find the tool i used to translate google xyz to tms schema does not use Math.pow(2, this.z) - this.y - 1, but Math.pow(2, this.z - 1) - this.y - 1. I konw that tms's original is (-180, -90), and xyz's original is (-180, 90), so it is easy to understand Math.pow(2, this.z - 1) - this.y - 1.

Can somebody tell me how does Math.pow(2, this.z) - this.y - 1 works and which is right method?

Copy link
Contributor Author

@indus indus Dec 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've red the 3rd blog and learned that i misunderstood the map tile method. So we transfer the world to a square using Web Mercator system, and we can get the total tile number which can be described as (1 << zoom - 1).
Now I guess it is the coordinate system i'm using cause the problem. In fact, i transformed a map to mbtiles which is projected to EPSG:4326 (WGS84) . But as we know mbtiles spec using tms and mercator projection. That might need to be supported by a projection-customized mapbox-gl.
Thanks for your help! :) 👍

};

// 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