使用不带访问令牌的MapBox GL JS [英] Use MapBox GL JS without Access Token
问题描述
是否可以使用没有访问令牌的 MapBox GL JS
?我在 MapBox GL JS 的文档中找不到任何提示,但是 Uber
建议它为提供 React
组件 MapBox GL JS
的a>.
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
.
来自 react-map-gl
显示没有Mapbox令牌的地图
Display Maps Without A Mapbox Token
如果没有Mapbox服务,则可以使用地图组件,如果您使用另一个图块源(例如,如果您托管自己的地图瓷砖).您将需要一种自定义的Mapbox GL样式,该样式应指向您自己的样式向量图块源,然后使用mapStyle道具将其传递给ReactMapGL.此自定义样式必须与图块源的模式匹配.
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.
来源 https://uber.github.io/react-map-gl/#/Documentation/getting-started/about-mapbox-tokens
是否可以使用不带访问令牌的本机" MapBox GL JS
?如果可以,怎么办?
Is it possible to use the "native" MapBox GL JS
without Access Token? If so, how?
推荐答案
是的,正如评论所提到的,只是不要设置accessToken并避免使用任何mapbox样式或图块:
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
});
然后,您可以通过 map.addLayer/addSource
以编程方式添加图层,或仅创建引用您的切片服务器和图层的自己的style.json文件.样式说明在此处大量记录: https://docs.mapbox.com/mapbox-gl-js/style-spec/
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/
这篇关于使用不带访问令牌的MapBox GL JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!