# cesium加载自定义mapbox地图

# 自定义mapbox地图

可以使用mapbox studio来自定义地图样式

mapbox-studio官网 (opens new window)

  1. 首页

image-20220107171223820

  1. 使用模版创建地图

image-20220107171313135

  1. 自定义地图,然后发布

image-20220107171601661

  1. 使用自定义样式token

image-20220107171658107

# 具体代码

<!DOCTYPE html>
<html lang="en">
<head>
    <!-- Use correct character set. -->
    <meta charset="utf-8"/>
    <!-- Tell IE to use the latest, best version. -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <!-- Make the application on mobile take up the full browser screen and disable user scaling. -->
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"/>
    <title>cesium加载自定义mapbox地图</title>
    <script src="http://192.168.1.1:8088/lib/Cesium-1.78/Build/Cesium/Cesium.js"></script>
    <style>
        @import url(http://192.168.1.1:8088/lib/Cesium-1.78/Build/Cesium/Widgets/widgets.css);

        html,
        body,
        #cesiumContainer {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            overflow: hidden;
        }
    </style>
</head>
<body>
<div id="cesiumContainer"></div>
<script>
    //Cesium token
    let cesium_tk = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJkYWRlMmQ1Ni1iNGMxLTRhY2YtYmExYi1jNjYyNTUxNDhjYzgiLCJpZCI6MjMwODAsInNjb3BlcyI6WyJhc2wiLCJhc3IiLCJhc3ciLCJnYyIsInByIl0sImlhdCI6MTU4OTE4NzE1NH0.QrUVmI13wKIqFwmnsGSR6aMr8FEtbO7jsTA0mqnvbdM";

    // 添加mapbox自定义地图实例
    let layer=new Cesium.MapboxStyleImageryProvider({
        url:'https://api.mapbox.com/styles/v1',
        username:'sungang',
        styleId: 'styleId',
        accessToken: 'token',
        scaleFactor:true
    });

    //初始页面加载
    Cesium.Ion.defaultAccessToken = cesium_tk;
    let viewer = new Cesium.Viewer('cesiumContainer', {
        geocoder: false,   // 位置查找工具
        baseLayerPicker: false,// 图层选择器(地形影像服务)
        timeline: false, // 底部时间线
        homeButton: false,// 视角返回初始位置
        fullscreenButton: false, // 全屏
        animation: false,   // 左下角仪表盘(动画器件)
        sceneModePicker: false,// 选择视角的模式(球体、平铺、斜视平铺)
        navigationHelpButton: false, //导航帮助按钮
        imageryProvider: layer, //设置默认底图
    });




    //添加图层
    // viewer.imageryLayers.addImageryProvider(layer);

    // 去除版权信息
    viewer._cesiumWidget._creditContainer.style.display = "none";

</script>

</body>
</html>
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

成果如下:

image-20220107171915892

上次更新时间: 2022年5月20日星期五上午11点16分