Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit source options overwrite #8232

Merged
merged 6 commits into from
Jun 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is unknown properties support needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think foreign members (unknown properties) in source options should be leaved as it is. Foreign members does not affect source's functionality and add extensibility for metadata or custom sources. As we don't invalidate foreign members in geojson、image、video sources, invalidate foreign members in vector, raster, raster-dem seems inconsistent.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jingsam Sorry for the delay in getting back to this. Allowing foreign members in the TileJSON does not seem necessary as part of this PR. It is preferable to have strict validation to ensure that unnecesary or incorrect properties are not being added to such files.

"line": 17
},
{
"message": "sources.video-missing-coordinates: missing required property \"coordinates\"",
"line": 26
Expand Down