Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use MapBox GL JS without Access Token

Is there a way to use MapBox GL JS without access token? I cannot find any hint in the documentation of MapBox GL JS, however, Uber suggest that it is possible with their library, providing React Components for MapBox GL JS.

From the documentation of react-map-gl

Display Maps Without A Mapbox Token

It is possible to use the map component without the Mapbox service, if you use another tile source (for example, if you host your own map tiles). You will need a custom Mapbox GL style that points to your own vector tile source, and pass it to ReactMapGL using the mapStyle prop. This custom style must match the schema of your tile source.

Source https://uber.github.io/react-map-gl/#/Documentation/getting-started/about-mapbox-tokens

Is it possible to use the "native" MapBox GL JS without Access Token? If so, how?

like image 523
Stophface Avatar asked Jul 29 '19 10:07

Stophface


People also ask

Do I need a Mapbox token?

You need a Mapbox access token to use any of Mapbox's tools, APIs, or SDKs. Mapbox uses access tokens to associate your account with your requests to Mapbox API resources. You can find all your access tokens, create new ones, or delete existing ones on your Access tokens page.

How do I get my Mapbox access token?

To obtain an access token, sign in to Mapbox and visit the Account Apps page. For Mapbox. js, a "Public" token (starting with "pk") is required. You may create multiple tokens and use different ones for different applications.

Is Mapbox GL JS open source?

Mapbox GL JS is an open-source JavaScript library that uses Mapbox GL to render interactive maps.

How do you make a secret token in Mapbox?

Create a token that can create tokens To create the authorization token, visit your Tokens page, and click Create a token. Every requested scope must be present in the access token used to allow the request. It is not possible to create a token with access to more scopes than the token that created it.


1 Answers

Yep, as the comments mention, just don't set the accessToken and refrain from using any mapbox styles or tiles:

var map = new mapboxgl.Map({
    container: 'map'
    center: [-74.50, 40],
    zoom: 9
});

Then you can add your layer programmatically via map.addLayer/addSource or just create your own style.json file referencing your tile server and layers. The style specification is documented extensively here: https://docs.mapbox.com/mapbox-gl-js/style-spec/

like image 64
Scarysize Avatar answered Oct 15 '22 04:10

Scarysize