From 7a264a07706dab7ff676d06cf5d9305d8e4a8f58 Mon Sep 17 00:00:00 2001 From: jingsam Date: Sat, 15 Jun 2019 06:46:20 +0800 Subject: [PATCH] Explicit source options overwrite (#8232) explicit source options take precedence over TileJSON --- src/source/load_tilejson.js | 7 +-- src/source/raster_dem_tile_source.js | 2 +- src/source/raster_tile_source.js | 2 +- src/style-spec/validate/validate_source.js | 7 --- .../overwrite-bounds/expected.png | Bin 0 -> 2868 bytes .../overwrite-bounds/style.json | 41 ++++++++++++++++++ .../style-spec/fixture/sources.output.json | 8 ---- 7 files changed, 47 insertions(+), 20 deletions(-) create mode 100644 test/integration/render-tests/tilejson-bounds/overwrite-bounds/expected.png create mode 100644 test/integration/render-tests/tilejson-bounds/overwrite-bounds/style.json diff --git a/src/source/load_tilejson.js b/src/source/load_tilejson.js index f3fcfc88582..f26816d1b49 100644 --- a/src/source/load_tilejson.js +++ b/src/source/load_tilejson.js @@ -1,6 +1,6 @@ // @flow -import { pick } from '../util/util'; +import { pick, extend } from '../util/util'; import { getJSON, ResourceType } from '../util/ajax'; import browser from '../util/browser'; @@ -16,8 +16,9 @@ export default function(options: any, requestManager: RequestManager, callback: return callback(err); } else if (tileJSON) { const result: any = pick( - tileJSON, - ['tiles', 'minzoom', 'maxzoom', 'attribution', 'mapbox_logo', 'bounds'] + // explicit source options take precedence over TileJSON + extend(tileJSON, options), + ['tiles', 'minzoom', 'maxzoom', 'attribution', 'mapbox_logo', 'bounds', 'scheme', 'tileSize', 'encoding'] ); if (tileJSON.vector_layers) { diff --git a/src/source/raster_dem_tile_source.js b/src/source/raster_dem_tile_source.js index cf02306b4ef..4407f207ec2 100644 --- a/src/source/raster_dem_tile_source.js +++ b/src/source/raster_dem_tile_source.js @@ -23,7 +23,7 @@ class RasterDEMTileSource extends RasterTileSource implements Source { super(id, options, dispatcher, eventedParent); this.type = 'raster-dem'; this.maxzoom = 22; - this._options = extend({}, options); + this._options = extend({ type: 'raster-dem' }, options); this.encoding = options.encoding || "mapbox"; } diff --git a/src/source/raster_tile_source.js b/src/source/raster_tile_source.js index 5580996c341..ecadfd17241 100644 --- a/src/source/raster_tile_source.js +++ b/src/source/raster_tile_source.js @@ -55,7 +55,7 @@ class RasterTileSource extends Evented implements Source { this.tileSize = 512; this._loaded = false; - this._options = extend({}, options); + this._options = extend({ type: 'raster' }, options); extend(this, pick(options, ['url', 'scheme', 'tileSize'])); } diff --git a/src/style-spec/validate/validate_source.js b/src/style-spec/validate/validate_source.js index 44ec5dceebc..b325eb69508 100644 --- a/src/style-spec/validate/validate_source.js +++ b/src/style-spec/validate/validate_source.js @@ -29,13 +29,6 @@ export default function validateSource(options) { style: options.style, styleSpec }); - if ('url' in value) { - for (const prop in value) { - if (['type', 'url', 'tileSize'].indexOf(prop) < 0) { - errors.push(new ValidationError(`${key}.${prop}`, value[prop], `a source with a "url" property may not include a "${prop}" property`)); - } - } - } return errors; case 'geojson': diff --git a/test/integration/render-tests/tilejson-bounds/overwrite-bounds/expected.png b/test/integration/render-tests/tilejson-bounds/overwrite-bounds/expected.png new file mode 100644 index 0000000000000000000000000000000000000000..49bdc00630094fd74e251e55eb2e8dcc1eaeaf23 GIT binary patch literal 2868 zcmZ8jc|4SB8+If+8ASGNEHM}*WH*@xSr6k-OpUEZqJ+jC*$LUQW;q#}gd-i<4`XaI z6r+?RyENIeW&0lazVpZT$NRp&_xHTd{oeO=U)Oa%@z$0oE_Pvd1_lN$QxoIg!PD^Y zVr2$*BJR!@crcn88`daOcotrxo03VS7ly}dx5rVl|UbxUGv`m7F_nvGuP(coV~Z`)Uq|np*^{Rho^Uh ze~ji3tiJqWca@?_%|FlA`o#)mcIndgV&f7#-8fEISop@$w|CDSUf5d}>i0c0O<&&G zbASnGPX;uqzgDyvQ73c)y5BHBT1Px#;918rE9)L@#*oQD^5xUGWnhFL@$M zN~C)!l+&uJb5kh>9^ZzZ!5pd?Qo0_DuLs2^C(l}rdTaLe^+9E2v2q+z%iAGL(b3U1 zPEO``?x?j_V@avd_{J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51l2Yj_6N+(QFCQ>?M#v?fA)+GkPQskW6Yf6 z80i7ihDsSNQSOo7(U~zZ%pU#uJyC3YuZKSVsASP%t3v(5^}%1%Uqtd26w$RK zNfYBOJBu{`4#6AEcuYpbZX|rX%nIoC=-YW*dKYN!Q?VFg0m5}2{rHIS&uwIjk*U<`G zg&OQG9|N}1F>#w`=S7O<+L zqa!sf4N=~NQEe|lCV~S7%l}0olgSww8Oz-=Db?577y$wzU__r~IUx>}mS$}HZ22~x zPhJ5AJA5mnnU(|e5uTok9_g>SoQENz+$?%QKO{}iXeO{&g=uC*0_y;XVFyZ(AZ3lC zpE13A_pbQAS%XCq96y_L9sm8WE_j}?j?TTs=}B@T6bgm=f3u4OUJd7*?JuBw_{;SW z*$XBX7Nt6=H&Da=OtB=RD@3BSR)HnL|La>R%Y3c2`@bEl{^;e$!h6dOjkdA2z7I78 zFh&L}j3B`Q>`zpR$5>NfR4;v98g{uhuIT-Hd*F02m2}pC#sdA&pFB@-!oR=-L!CUg zCiRp+;GJIE1~`cvkt>ohf&qZ>6m$|8(_#6VK4a4#uNTe?pd@6w>FX|X@dtJHmN5If zYgV1fVia&@Um<+V!C@vq<*%wUSN KG_FKki~JAioqqHH literal 0 HcmV?d00001 diff --git a/test/integration/render-tests/tilejson-bounds/overwrite-bounds/style.json b/test/integration/render-tests/tilejson-bounds/overwrite-bounds/style.json new file mode 100644 index 00000000000..c19bafe6c9a --- /dev/null +++ b/test/integration/render-tests/tilejson-bounds/overwrite-bounds/style.json @@ -0,0 +1,41 @@ +{ + "version": 8, + "metadata": { + "test": { + "height": 64, + "width":64 + } + }, + "center": [ + 13.425247606101294, 52.5033795378269 + ], + "zoom": 14, + "sources": { + "mapbox": { + "type": "vector", + "maxzoom": 14, + "url": "local://tilesets/vector.json", + "bounds":[13.4043671, 52.4959407, 13.425247606101294, 52.5033795378269] + } + }, + "layers": [ + { + "id": "background", + "type": "background", + "paint": { + "background-color": "white" + } + }, + { + "id": "road", + "type": "line", + "source": "mapbox", + "source-layer": "road", + "paint": { + "line-width": 2, + "line-color": "#000" + } + } + ] + } + \ No newline at end of file diff --git a/test/unit/style-spec/fixture/sources.output.json b/test/unit/style-spec/fixture/sources.output.json index 34674e6aa96..ea691559a05 100644 --- a/test/unit/style-spec/fixture/sources.output.json +++ b/test/unit/style-spec/fixture/sources.output.json @@ -7,14 +7,6 @@ "message": "sources.invalid-type.type: expected one of [vector, raster, raster-dem, geojson, video, image], \"invalid\" found", "line": 7 }, - { - "message": "sources.no-tilejson-properties-with-url.tiles: a source with a \"url\" property may not include a \"tiles\" property", - "line": 12 - }, - { - "message": "sources.no-unknown-properties-with-url.foo: a source with a \"url\" property may not include a \"foo\" property", - "line": 17 - }, { "message": "sources.video-missing-coordinates: missing required property \"coordinates\"", "line": 26