原文链接及内容

MapboxVector图层对象允许创建单个矢量数据源的图层,该图层使用了mapbox的托管样式。如果样式用于多个数据源,请使用source
属性选择单个矢量数据源。如果想渲染样式层的一系列样式的图层(假设它们都共享相同的数据源),可以使用layers
属性。
main.js
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| import Map from 'ol/Map.js'; import MapboxVector from 'ol/layer/MapboxVector.js'; import View from 'ol/View.js';
const map = new Map({ target: 'map', layers: [ new MapboxVector({ styleUrl: 'mapbox://styles/mapbox/bright-v9', accessToken: 'Your Mapbox access token from https://mapbox.com/ here', }), ], view: new View({ center: [0, 0], zoom: 2, }), });
|
界面布局文件index.html
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Mapbox Vector Layer</title> <link rel="stylesheet" href="node_modules/ol/ol.css"> <style> .map { width: 100%; height: 400px; } </style> </head> <body> <div id="map" class="map"></div> <script src="https://cdn.jsdelivr.net/npm/elm-pep@1.0.6/dist/elm-pep.js"></script> <script type="module" src="main.js"></script> </body> </html>
|