- [Example: Add a vector tile source](https://docs.mapbox.com/mapbox-gl-js/example/vector-source/)
- [Example: Add a third party vector tile source](https://docs.mapbox.com/mapbox-gl-js/example/third-party/)
Examples:
map.addSource('some id', {
type: 'vector',
tiles: ['https://d25uarhxywzl1j.cloudfront.net/v0.1/{z}/{x}/{y}.mvt'],
minzoom: 6,
maxzoom: 14
});
map.getSource('some id').setUrl("mapbox://mapbox.mapbox-streets-v8");
map.getSource('some id').setTiles(['https://d25uarhxywzl1j.cloudfront.net/v0.1/{z}/{x}/{y}.mvt']);
See:
Methods
-
Reloads the source data and re-renders the map.
Example:
map.getSource('source-id').reload();
-
setTiles(tiles) → VectorTileSource
-
Sets the source `tiles` property and re-renders the map.
Name Type Description tiles
Array.<string> An array of one or more tile source URLs, as in the TileJSON spec. Returns:
Returns itself to allow for method chaining.Example:
map.addSource('source-id', { type: 'vector', tiles: ['https://some_end_point.net/{z}/{x}/{y}.mvt'], minzoom: 6, maxzoom: 14 }); // Set the endpoint associated with a vector tile source. map.getSource('source-id').setTiles(['https://another_end_point.net/{z}/{x}/{y}.mvt']);
-
setUrl(url) → VectorTileSource
-
Sets the source `url` property and re-renders the map.
Name Type Description url
string A URL to a TileJSON resource. Supported protocols are `http:`, `https:`, and `mapbox:// `. Returns:
Returns itself to allow for method chaining.