I have some data hosted on mapbox and I'm trying to load it as tiled geojson into Leaflet from its mapbox id (I just want to get plain geojson, I'm not trying to render it). How can I achieved that?

I tried this snippet:

L.mapbox.accessToken = 'myAccessToken';

var featureLayer = L.mapbox.featureLayer('myDataId');

but it doesn't work, I get the following error:

" could not load features at http://a.tiles.mapbox.com/v4/"myDataId"/features.json?access_token="myAccessToken" "

I also haven't been able to get L.mapbox.featureLayer() to load vectors I've uploaded to MapBox. Vector Tile source .mbtiles files are no longer .geojsons but have been converted into a bunch of tiled .svgs combined into one .mbtiles file, so I'm not sure if mapbox.js has the ability to render vector .mbtiles the same was it renders hosted .geojson files.

If you want to render the vector tileset on your map, try styling it in Mapbox Studio and uploading the style project to MapBox (docs).


OK, so looks like there are two different ways to import vector data into mapbox:

  1. as a .geojson within the MapBox Editor.

enter image description here

  1. as a vector .mbtiles set, uploaded via MapBox Studio or from the MapBox Uploads page.

Data uploaded via the first method can be loaded onto a map with L.mapbox.featureLayer. Data uploaded via the second method (tiled) must be first given a style in MapBox Studio (see link above) or rendered in a mapbox-gl map.

In summary: it is not possible to access the geojson data of a vector tiles source.

  • You're right, it works with the mapbox editor. I don't find a way to import my data in the editor directly from mapbox though. – Frederic Le Feurmou Jan 27 '15 at 21:29
  • coincidentally, mapbox just blogged about the difference between MapBox Studio and the MapBox Editor. – James Conkling Jan 27 '15 at 21:34

what about


Just tested it again and it works fine. Have you added these two lines with the up to date API and CSS?

<script src='https://api.tiles.mapbox.com/mapbox.js/v2.1.5/mapbox.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox.js/v2.1.5/mapbox.css' rel='stylesheet' />

enter image description here

  • It's nearly the same answer as Klaser. I still have the same error with this : / – Frederic Le Feurmou Jan 27 '15 at 16:06
  • The difference is the addtoMap method, so you add the layer to your map before you load the content.works fine here.perhaps post a bit more of your code to get an idea where's the problem – Thomas B Jan 27 '15 at 16:39
  • Could you give me the link to the fiddle please? I'll try to reproduce it with my id. – Frederic Le Feurmou Jan 27 '15 at 20:31
  • i just replaced my id/token with substitutes so you can fill in your id/token: jsfiddle.net/expedio/uh6ub3tf – Thomas B Jan 27 '15 at 20:47
  • ok, it doesn't work for me. I only get the background tiles. I guess it's a problem with my data format but I don't know how to check that. I made my data available to public api: yowza.14a37d8d – Frederic Le Feurmou Jan 27 '15 at 20:57

I'm not a MapBox-User, but the syntax to get the feature layer seems to be a bit different: https://www.mapbox.com/mapbox.js/api/v1.6.1/l-mapbox-featurelayer/

Try this:

var featureLayer = L.mapbox.featureLayer()

// loads markers from the map `examples.map-0l53fhk2` on Mapbox,
// if that map has markers
  • I think that my syntax works in the last version of the api. L.mapbox.featureLayer(id|url|geojson, options) I tried your syntax but my error is still the same. – Frederic Le Feurmou Jan 26 '15 at 18:31
  • Hmm, you're right. I missinterpreted the doc earlier and I don't see why var featureLayer = L.mapbox.featureLayer('map-id') isn't working. Sorry I can't be of better help. Have you double-checked the map ID in your code? Has it worked in different contexts? – Klaster Jan 26 '15 at 23:50
  • The map ID is good and I can load my data in mabox studio. – Frederic Le Feurmou Jan 27 '15 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.