Bret Hawkins
Bret Hawkins

Reputation: 41

Pull geoJSON data from Mapbox Dataset for Store Locator

I recently followed the Mapbox Store Locator tutorial for a client's events page. It's working great, however (if possible) I would now like to pull in the geoJSON points from a Mapbox Dataset or Tileset instead of the inline geoJSON data in the store locator script I made.

I've been advised to upload the Dataset to a tileset then add that tileset to a style, and that does show the points on the map correctly, but it doesn't allow the store locator script I've made to build the list of "stores" because the geoJSON data is no longer inline in the script.

How can I modify the Store Locator script to either populate the "stores" variable with the Dataset URL, or have the location list parts of the script be able to pull the geoJSON features from the Style layer? Thanks!

Right now, the geoJSON data is in a variable called stores and then the script that pulls the data into the map looks like this:

map.on('load', function(e){
  map.addSource("places",{
    "type": "geojson",
    "data": stores
});

Upvotes: 2

Views: 472

Answers (1)

xaddict
xaddict

Reputation: 1328

Awfully late answer:

The MapboxGL API supports adding a tileset source via:

map.addSource("name-of-source", {
    type: "vector",
    url: "mapbox://url-found-in-mapbox-under-tileset-id"
});

and using it live like this:

map.addLayer({
    id: "layer-id",
    type: "line",
    source: "name-of-source",
    "source-layer": "name-of-tileset",
});

I haven't found a way to directly add a data source yet.

Upvotes: 0

Related Questions