Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapbox tiles and Leafletjs

Tags:

I'm trying to load some additional tile layers on my map but I can't quite figure it out. The ones that I currently have I only have thanks to someone that provided a tutorial but didn't say what the other tile options were. Can someone help me with this?

var mapboxUrl = 'https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}'; var accessToken = 'mySuperSecretToken';  var grayscale = L.tileLayer(mapboxUrl, {id: 'mapbox.light', attribution: '', maxZoom: 20, accessToken: accessToken}), streets = L.tileLayer(mapboxUrl, {id: 'mapbox.streets', attribution: '', maxZoom: 20, accessToken: accessToken}); 

I cannot seem to figure out how to get any additional layers or even use the new streets version that I got an email about today.

like image 984
twg_ Avatar asked May 11 '16 14:05

twg_


People also ask

What is a Mapbox tile?

What are Mapbox vector tiles? Vector tiles are a lightweight data format for storing geospatial vector data, such as points, lines, and polygons. Mapbox vector tiles are designed to visualize a large amount of data on a map in a scalable and cost effective way.

Are Mapbox tiles free?

Mapbox pricing is described here - mapbox.com/pricing - the free tier applies to public and free-to-access apps. For private or pay-for apps you don't get a free tier. Note that your quota usage might not be updated in real time.

Is Mapbox based on leaflet?

Leaflet is an open-source JavaScript library used for web mapping. The Leaflet library forms the basis of Mapbox.

What is the difference between leaflet and Mapbox?

Leaflet is "just" a map API. It doesn't provide data/maps itself. Mapbox is a service to design and publish maps, where the end-result is a bunch of generated map-tiles stored in the cloud (and some json files).


2 Answers

I actually finally found the answer.

The URL string needed to be updated to

https://api.mapbox.com/styles/v1/mapbox/{id}/tiles/{z}/{x}/{y}?access_token={accessToken} 

The available styles ({id}) are

  • streets-v9
  • satellite-streets-v9
  • light-v9
  • dark-v9
  • outdoors-v9
like image 55
twg_ Avatar answered Sep 21 '22 13:09

twg_


Full list of Mapbox classic map IDs, ie for Leaflet, are at https://www.mapbox.com/api-documentation/#maps.

At the time of writing the IDs are:

  • mapbox.streets
  • mapbox.light
  • mapbox.dark
  • mapbox.satellite
  • mapbox.streets-satellite
  • mapbox.wheatpaste
  • mapbox.streets-basic
  • mapbox.comic
  • mapbox.outdoors
  • mapbox.run-bike-hike
  • mapbox.pencil
  • mapbox.pirates
  • mapbox.emerald
  • mapbox.high-contrast
like image 34
Victor Häggqvist Avatar answered Sep 19 '22 13:09

Victor Häggqvist