Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I have to use a different Mapbox access token in every page / app?

Tags:

leaflet

mapbox

I'm developing a web application using NodeJS, OpenStreetMaps, Leaflet and Mapbox.

For a while I just use a home page and a register page, both with a map, using this code to display it. Very straight forward, as shown in Leaflet Quick Start Guide

    var map = L.map('map');
  map.setView([19.34, -99.15], 12);
  L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
      attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
      maxZoom: 18,
      id: <myMapboxMapId>,
      accessToken: <myMapboxAccessToken>
  }).addTo(map);

I thought that I will use the same code for the entire app, till I add a new page with a map, got really frustrated that the map would not show up, no javascript warning or erros, checked lots of Stackoverflow questions and other forums, without answer.

I made that page a simple html with the leaflet js and css and it didn't show. Just a grey area.

So after a while, I went to Mapbox, create a new access token, place it and it worked.

What I find weird is that I was using the first token on two different pages, working perfect. But not with a third one.

So the question... Do I have to use a different Mapbox access token in every page / app? How does this work?

I've looked in the Mapbox documentation, without answers. Here Mapbox access token docs

Thanks!

like image 861
Ralexrdz Avatar asked Nov 09 '22 23:11

Ralexrdz


1 Answers

No. You can use the same access token on every site if you want. But obviously they all share the same usage counts, so if you hit your limit, all the sites will stop working.

like image 163
Steve Bennett Avatar answered Jan 04 '23 02:01

Steve Bennett