通常在项目中我们会遇到需要空白底图的情况,如专题底图展示,特殊图层的展示等,效果如下图:

    MapBox创建空白底图 - 图1MapBox创建空白底图 - 图2

    mapbox 可以很方便的创建各种底图包括空白底图,也可改变空白底图的背景色。除底图是空白的,其他交互与正常无异。

    以下为展示空白底图的代码:

    1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4. <meta charset='utf-8' />
    5. <title>Add an image</title>
    6. <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
    7. <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    8. <script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.53.1/mapbox-gl.js'></script>
    9. <link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.53.1/mapbox-gl.css' rel='stylesheet' />
    10. <style>
    11. body { margin:0; padding:0; }
    12. #map { position:absolute; top:0; bottom:0; width:100%; }
    13. </style>
    14. </head>
    15. <body>
    16. <div id='map'></div>
    17. <script>
    18. mapboxgl.accessToken = 'pk.eyJ1Ijoibmlld3poIiwiYSI6ImNqbjRvM2F4ODA5ZDEzd2xkd2oxZnB4Y2UifQ.phMvmLw9t9lDxobKyYVbPw';
    19. var mapStyle = {
    20. "version": 8,
    21. "name": "Dark",
    22. "sources": {
    23. "mapbox": {
    24. "type": "vector",
    25. "url": "mapbox://mapbox.mapbox-streets-v8"
    26. },
    27. },
    28. "sprite": "mapbox://sprites/mapbox/dark-v10",
    29. "glyphs": "mapbox://fonts/mapbox/{fontstack}/{range}.pbf",
    30. "layers": [
    31. ]
    32. };
    33. var map = new mapboxgl.Map({
    34. container: 'map',
    35. zoom: 3,
    36. center: [0, 0],
    37. style: mapStyle
    38. });
    39. </script>
    40. </body>
    41. </html>