Skip to content

Commit

Permalink
Explicit source options overwrite (#8232)
Browse files Browse the repository at this point in the history
explicit source options take precedence over TileJSON
  • Loading branch information
jingsam authored and Asheem Mamoowala committed Jun 14, 2019
1 parent e8b8887 commit 7a264a0
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 20 deletions.
7 changes: 4 additions & 3 deletions src/source/load_tilejson.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/source/raster_dem_tile_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

Expand Down
2 changes: 1 addition & 1 deletion src/source/raster_tile_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']));
}

Expand Down
7 changes: 0 additions & 7 deletions src/style-spec/validate/validate_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}

8 changes: 0 additions & 8 deletions test/unit/style-spec/fixture/sources.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7a264a0

Please sign in to comment.