由於 mapbox 的服務器在國外,在開發的時候有可能加載很慢,而且大多時候與背景地圖無關,此時可以加載一個空白的地圖來增加加載速度從而提高開發效率。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Add an image</title>
<meta
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<script src="https://api.tiles.mapbox.com/mapbox-gl-js/v0.53.1/mapbox-gl.js"></script>
<link
href="https://api.tiles.mapbox.com/mapbox-gl-js/v0.53.1/mapbox-gl.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>
const blankStyle = {
version: 8,
name: "BlankMap",
sources: {},
layers: [
{
id: 'background',
type: 'background',
paint: { 'background-color': '#08294A' } /* 背景顏色 */
}
]
};
var map = new mapboxgl.Map({
container: "map",
zoom: 3,
center: [0, 0],
style: blankStyle
});
</script>
</body>
</html>