原文链接及内容
针对maptiler.com中的切片数据使用ol-mapbox-style样式渲染的示例的示例。请务必在 https://www.maptiler.com/cloud/ 获取你自己的API key。当API key过期时,将无法加载地图数据。
main.js
代码如下:
1 2 3 4 5 6 7 8 9 import FullScreen from 'ol/control/FullScreen.js' ;import olms from 'ol-mapbox-style' ;olms ( 'map' , 'https://api.maptiler.com/maps/topo/style.json?key=Get your own API key at https://www.maptiler.com/cloud/' ).then (function (map ) { map.addControl (new FullScreen ()); });
界面布局文件index.html
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 <!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 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 >