是否可以在传单中使用Mapbox研究中制作的样式

Is it possible to use a style made in Mapbox studion in Leaflet?

本文关键字:样式 Mapbox 单中使 是否      更新时间:2023-09-26

我在Mapbox Studio中制作了一个样式,想知道是否可以在传单项目中使用该样式。我有一个样式URL和我的访问令牌,但没有Mapbox ID。我如何使用传单?有可能吗?

样式url:mapbox://styles/gustavsvensson/cin1hwd9a00bncznomsx507se

您需要通过在线上传到Mapbox或使用他们的企业系统Atlas Server来获取您的Mapbox ID。他们有一个免费账户,你可以把它放在那里,并获得你的风格ID。

下面是一个示例片段,我用在Studio中创建的一个地图样式进行了测试,它成功了。请注意,我需要提供密钥、用户名和Mapbox ID才能正确渲染瓷砖。

<!DOCTYPE html>
<html>
   <head>
      <meta charset=utf-8 />
      <title>Add styles made with Mapbox Studio to a Leaflet map</title>
      <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
      <script src='https://api.mapbox.com/mapbox.js/v2.4.0/mapbox.js'></script>
      <link href='https://api.mapbox.com/mapbox.js/v2.4.0/mapbox.css' rel='stylesheet' />
      <style>
         body { margin:0; padding:0; }
         #map { position:absolute; top:0; bottom:0; width:100%; }
      </style>
   </head>
   <body>
      <div id='map'></div>
      <script>
         L.mapbox.accessToken = '<Your access token here';
         var map = L.map('map').setView([38.97416, -95.23252], 15);

         // Add tiles from Mapbox Style API(https://www.mapbox.com/developers/api/styles/)
         // Tiles are 512x512 pixels and are offset by 1 zoom level
         L.tileLayer(
         'https://api.mapbox.com/styles/v1/<mapbox username>/<style ID>/tiles/{z}/{x}/{y}?access_token=' + L.mapbox.accessToken, {
             tileSize: 512,
             zoomOffset: -1,
             attribution: '© <a href="https://www.mapbox.com/map-feedback/">Mapbox</a> © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
         }).addTo(map);
      </script>
   </body>
</html>