How can I add a data source hosted Mapbox into a mapbox-gl-js project

1.4k views Asked by At

How can I add a data source hosted Mapbox into a mapbox-gl-js project? It used to be like this: http://bit.ly/1LcwekS way back in V.2.1

var sourceObj = new mapboxgl.Source({
    type: 'vector',
    url: 'mapbox://foo-bar.ci58c127'
});

but mapboxgl.Source is no longer supported in mapboxgl.Source version 8.0

1

There are 1 answers

1
John On BEST ANSWER

The new way to do this is via Map#addSource:

map.addSource('foo-bar.ci58c127', {
    type: 'vector',
    url: 'mapbox://foo-bar.ci58c127'
});

The first argument is the source ID, which you can use when adding layers:

map.addLayer({
    "id": "markers",
    "type": "symbol",
    "source": "foo-bar.ci58c127",
    "layout": { ... },
    "paint": { ... }
});

Whenever there are breaking changes in a release, we add details about them in the CHANGELOG, so if you come across any other upgrade issues that's the place to look. We're also planning to pull that content directly into the API documentation.