Mapbox-gl typing won't allow accessToken assignment

前端 未结 3 2462
日久生厌
日久生厌 2021-02-20 00:54

I\'m using the mapbox-gl library with TypeScript, and I\'ve installed its community sourced type definitions with @types/mapbox-gl. When I try to import and set an

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-20 01:43

    For those finding this now ... You don't even need to set the Mapbox accessToken this way, it can be passed in as an option (since v1.2)

    const map = new mapboxgl.Map({
      accessToken: '...',
      container: '...',
      style: '...',
    });
    

    Pity it's not the method used in any of the examples (yet).

    Docs: https://docs.mapbox.com/mapbox-gl-js/api/#map

    1.2 release notes: https://github.com/mapbox/mapbox-gl-js/releases/tag/v1.2.0

    PR that adds it: https://github.com/mapbox/mapbox-gl-js/pull/8364

提交回复
热议问题