Mapbox添加空白地图,减少加载时间

由于mapbox 的服务器在国外,在开发的时候有可能加载很慢,而且大多时候与背景地图无关,此时可以加载一个空白的地图来增加加载速度从而提高开发效率。代码如下:
首发在https://www.aigisss.com/posts/e1a3a842.html

<!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="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <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>
      var 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>

上一篇:C#小写数字金额转换成大写人民币金额的算法


下一篇:mapbox-gl集成three.js开发