如何在 Mapbox GL JS 中使用私有 Mapbox Tileset?

How do I use a private Mapbox Tileset in Mapbox GL JS?

我有一个使用 Mapbox GL JS 构建的前端,并希望它访问我上传到 Mapbox Studio 的私有 Tileset。然而,私有 Tilesets 只能使用秘密令牌访问,并且 Mapbox 在使用这些令牌初始化时拒绝工作。

有没有办法让我的地图保持私有并通过 Mapbox GL 访问它?

However private Tilesets can only be accessed with secret Tokens

我认为你错了。根据 the documentation:

,同一帐户的任何令牌都可以访问私有 tilesets

If a tileset is public, the tileset ID can be used by any Mapbox user with their access tokens. But, only the owner of a tileset can make changes or delete a tileset, even if it's public. If a tileset is private, the tileset ID can only be used with an access token from the owner's account. By default, new tilesets created in Mapbox Studio are private.

所以,切换到使用常规 public 令牌,它应该可以工作。