From 0b99b232fd8db39f0b413d8f1b343bd40d661859 Mon Sep 17 00:00:00 2001 From: Ryan Hamley Date: Wed, 22 May 2019 09:13:33 -0700 Subject: [PATCH] Add sku token to Mapbox API tile requests (#14) (#8276) --- bench/lib/fetch_style.js | 6 +- bench/lib/tile_parser.js | 21 +- package.json | 2 +- src/render/glyph_manager.js | 10 +- src/source/geojson_source.js | 2 +- src/source/image_source.js | 2 +- src/source/load_tilejson.js | 9 +- src/source/raster_dem_tile_source.js | 5 +- src/source/raster_tile_source.js | 10 +- src/source/vector_tile_source.js | 10 +- src/source/video_source.js | 2 +- src/style/load_glyph_range.js | 10 +- src/style/load_sprite.js | 9 +- src/style/style.js | 10 +- src/style/style_layer/symbol_style_layer.js | 2 +- src/ui/map.js | 22 +- src/util/mapbox.js | 133 +++- src/util/{token.js => resolve_tokens.js} | 0 src/util/sku_token.js | 42 ++ test/unit/source/geojson_source.test.js | 14 +- test/unit/source/image_source.test.js | 13 +- .../source/raster_dem_tile_source.test.js | 5 +- test/unit/source/raster_tile_source.test.js | 5 +- test/unit/source/vector_tile_source.test.js | 5 +- test/unit/style/load_glyph_range.test.js | 4 +- test/unit/style/style.test.js | 10 +- test/unit/ui/control/logo.test.js | 1 + test/unit/util/mapbox.test.js | 616 ++++++++++-------- .../{token.test.js => resolve_tokens.test.js} | 2 +- test/unit/util/sku_token.test.js | 32 + 30 files changed, 617 insertions(+), 397 deletions(-) rename src/util/{token.js => resolve_tokens.js} (100%) create mode 100644 src/util/sku_token.js rename test/unit/util/{token.test.js => resolve_tokens.test.js} (96%) create mode 100644 test/unit/util/sku_token.test.js diff --git a/bench/lib/fetch_style.js b/bench/lib/fetch_style.js index a766e8a6f75..316cfd84588 100644 --- a/bench/lib/fetch_style.js +++ b/bench/lib/fetch_style.js @@ -1,10 +1,12 @@ // @flow import type {StyleSpecification} from '../../src/style-spec/types'; -import {normalizeStyleURL} from '../../src/util/mapbox'; +import { RequestManager } from '../../src/util/mapbox'; + +const requestManager = new RequestManager(); export default function fetchStyle(value: string | StyleSpecification): Promise { return typeof value === 'string' ? - fetch(normalizeStyleURL(value)).then(response => response.json()) : + fetch(requestManager.normalizeStyleURL(value)).then(response => response.json()) : Promise.resolve(value); } diff --git a/bench/lib/tile_parser.js b/bench/lib/tile_parser.js index 1b0d72dabf3..3be9eb95b16 100644 --- a/bench/lib/tile_parser.js +++ b/bench/lib/tile_parser.js @@ -7,7 +7,7 @@ import assert from 'assert'; import deref from '../../src/style-spec/deref'; import Style from '../../src/style/style'; import { Evented } from '../../src/util/evented'; -import { normalizeSourceURL, normalizeTileURL } from '../../src/util/mapbox'; +import { RequestManager } from '../../src/util/mapbox'; import WorkerTile from '../../src/source/worker_tile'; import StyleLayerIndex from '../../src/style/style_layer_index'; @@ -17,14 +17,19 @@ import type { OverscaledTileID } from '../../src/source/tile_id'; import type { TileJSON } from '../../src/types/tilejson'; class StubMap extends Evented { - _transformRequest(url) { - return {url}; + _requestManager: RequestManager; + + constructor() { + super(); + this._requestManager = new RequestManager(); } } +const mapStub = new StubMap(); + function createStyle(styleJSON: StyleSpecification): Promise