Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
point old style templates to equivalent gl styles
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Erb committed Jan 29, 2020
1 parent 6a3d983 commit c50a68c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
'mapbox.outdoors': 'mapbox/outdoors-v11',
'mapbox.satellite': 'mapbox/satellite-v9',
'mapbox.streets': 'mapbox/streets-v11',
'mapbox.streets-basic': 'mapbox/basic-v9'
'mapbox.streets-basic': 'mapbox/basic-v9',
'mapbox.streets-satellite': 'mapbox/satellite-streets-v11'
}
};
8 changes: 7 additions & 1 deletion src/format_url.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ module.exports.tileJSON = function(urlOrMapID, accessToken) {
if (urlOrMapID.indexOf('/') !== -1)
return urlOrMapID;

var url = module.exports('/v4/' + urlOrMapID + '.json', accessToken);
var url;
if (urlOrMapID in config.TEMPLATE_STYLES) {
url = module.exports('/styles/v1/' + config.TEMPLATE_STYLES[urlOrMapID], accessToken);
} else {
// TODO: remove this and throw error around classic style usage instead
url = module.exports('/v4/' + urlOrMapID + '.json', accessToken);
}

// TileJSON requests need a secure flag appended to their URLs so
// that the server knows to send SSL-ified resource references.
Expand Down
8 changes: 8 additions & 0 deletions src/load_tilejson.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@ module.exports = {
_loadTileJSON: function(_) {
if (typeof _ === 'string') {
_ = format_url.tileJSON(_, this.options && this.options.accessToken);
var isGLStyle = _.indexOf('/styles/v1/') !== -1;

request(_, L.bind(function(err, json) {
if (err) {
util.log('could not load TileJSON at ' + _);
this.fire('error', {error: err});
} else if (json && isGLStyle) {
// In order to preserve compatibility, 256x256 tiles are requested by default
// If you would like better resolution & fewer network requests, use a styleLayer instead
json.tiles = [ format_url('/styles/v1/' + json.owner + '/' + json.id + '/tiles/256/{z}/{x}/{y}', this.options.accessToken) ];
this._setTileJSON(json);
this.fire('ready');
} else if (json) {
this._setTileJSON(json);
this.fire('ready');
Expand Down

0 comments on commit c50a68c

Please sign in to comment.