本文最后更新于:2022-06-10T22:55:23+08:00
由于 mapbox 的服务器在国外,在开发的时候有可能加载很慢,而且大多时候与背景地图无关,此时可以加载一个空白的地图来增加加载速度从而提高开发效率。
代码如下:
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| <!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>
|