Edit

从 Mapbox Style 对象创建的矢量瓦片

vectortiles6 mapboxstyle2 ol-mapbox-style3 maptiler26

使用 maptiler.com 的瓦片结合 ol-mapbox-style 的示例。

使用 ol-mapbox-style 和 maptiler.com 瓦片的示例。注意:使用此示例时,请确保在 https://www.maptiler.com/cloud/ 获取您自己的 API 密钥。当 API 密钥过期时,将无法看到地图。

main.js
import olms from 'ol-mapbox-style';
import FullScreen from 'ol/control/FullScreen.js';

olms(
  'map',
  'https://api.maptiler.com/maps/outdoor-v2/style.json?key=Get your own API key at https://www.maptiler.com/cloud/',
).then(function (map) {
  map.addControl(new FullScreen());
});
index.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Vector tiles created from a Mapbox Style object</title>
    <link rel="stylesheet" href="node_modules/ol/ol.css">
    <style>
      .map {
        width: 100%;
        height: 400px;
      }
      .map .ol-rotate {
        left: .5em;
        bottom: .5em;
        top: auto;
        right: auto;
      }
      .map:-webkit-full-screen {
        height: 100%;
        margin: 0;
      }
      .map:fullscreen {
        height: 100%;
      }
    </style>
  </head>
  <body>
    <div id="map" class="map"></div>

    <script type="module" src="main.js"></script>
  </body>
</html>
package.json
{
  "name": "mapbox-style",
  "dependencies": {
    "ol": "10.9.0",
    "ol-mapbox-style": "^13.4.1"
  },
  "devDependencies": {
    "vite": "^3.2.3"
  },
  "scripts": {
    "start": "vite",
    "build": "vite build"
  }
}