Spaces:
Sleeping
Sleeping
File size: 1,494 Bytes
e7b2eb4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | // @flow
import {pick, extend} from '../util/util';
import {getJSON, ResourceType} from '../util/ajax';
import browser from '../util/browser';
import type {RequestManager} from '../util/mapbox';
import type {Callback} from '../types/callback';
import type {TileJSON} from '../types/tilejson';
import type {Cancelable} from '../types/cancelable';
export default function(options: any, requestManager: RequestManager, callback: Callback<TileJSON>): Cancelable {
const loaded = function(err: ?Error, tileJSON: ?Object) {
if (err) {
return callback(err);
} else if (tileJSON) {
const result: any = pick(
// explicit source options take precedence over TileJSON
extend(tileJSON, options),
['tiles', 'minzoom', 'maxzoom', 'attribution', 'mapbox_logo', 'bounds', 'scheme', 'tileSize', 'encoding']
);
if (tileJSON.vector_layers) {
result.vectorLayers = tileJSON.vector_layers;
result.vectorLayerIds = result.vectorLayers.map((layer) => { return layer.id; });
}
result.tiles = requestManager.canonicalizeTileset(result, options.url);
callback(null, result);
}
};
if (options.url) {
return getJSON(requestManager.transformRequest(requestManager.normalizeSourceURL(options.url), ResourceType.Source), loaded);
} else {
return browser.frame(() => loaded(null, options));
}
}
|