本示例演示使用来自 maptiler.com 的 ol-mapbox-style 来渲染矢量瓦片.
本示例演示使用来自 maptiler.com 的 ol-mapbox-style 来渲染矢量瓦片。 注意: 在使用本示例的时候, 确保在 https://www.maptiler.com/cloud/ 申请使用你自己的 API key。 如果 API key 过期了,地图将不会显示。
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());
});
<!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>
<!-- Pointer events polyfill for old browsers, see https://caniuse.com/#feat=pointer -->
<script src="./resources/elm-pep.js"></script>
<script type="module" src="main.js"></script>
</body>
</html>
{
"name": "mapbox-style",
"dependencies": {
"ol": "7.3.0",
"ol-mapbox-style": "^9.2.0"
},
"devDependencies": {
"vite": "^3.2.3"
},
"scripts": {
"start": "vite",
"build": "vite build"
}
}