0

以下是我运行包含地图框的 Angular 应用程序时的错误。它不会在 stackblitz 中显示地图,而在本地机器上运行时会显示。我在 mapbox 中添加了访问令牌。有没有其他人遇到过这个问题?

AppComponent_Host.ngfactory.js? [sm]:1 ERROR Error: An API access token is required to use Mapbox GL. See https://www.mapbox.com/api-documentation/#access-tokens-and-token-scopes
    at N._makeAPIURL (mapbox.js:184)
    at N.normalizeStyleURL (mapbox.js:74)
    at i.loadURL (style.js:214)
    at r._updateStyle (map.js:1262)
    at r.setStyle (map.js:1233)
    at new r (map.js:449)
    at AppComponent.ngOnInit (VM13107 app.component.ts:38)
    at checkAndUpdateDirectiveInline (provider.ts:212)
    at checkAndUpdateNodeInline (view.ts:429)
    at checkAndUpdateNode (view.ts:389)
4

1 回答 1

1

似乎您的 api 访问令牌未被正确识别。

请检查一些工作的 stackblitz 实例以获得正确的配置。

app.module.ts应该包含NgxMapboxGLModule.withConfigNgxMapboxGLModule.forRoot连同您的 api 访问令牌。

   NgxMapboxGLModule.withConfig({
      accessToken: 'myCustomTokenComesHere'
    })

例如:

如需进一步检查,请分享您的 Stackblitz(如果您不想公开,可能没有您的访问令牌)。

于 2020-03-03T20:40:54.497 回答