首页 > 技术文章 > Cesium初始化

reround 2020-01-07 11:25 原文

如果还不会配置和引入的话,可以去看一下我的这两篇文章

https://www.cnblogs.com/reround/p/11943717.html
https://www.cnblogs.com/reround/p/12020661.html

1.给页面添加一个div#cesiumContainer 

2.初始化方法

   

this.viewer = new this.Cesium.Viewer('cesiumContainer', {
        imageryProvider: new this.Cesium.UrlTemplateImageryProvider({
          url: this.sourceUrl +'/webearth/tiles/world/{z}/{x}/{reverseY}.jpg',  // sourceUrl 是配置的ip地址和端口 后面是路径是后台提供的
          proxy: new this.Cesium.DefaultProxy('/proxy/')   //cesium的跨域
        }),
        baseLayerPicker: false,   //图层选择器
        animation: false,   //左下角仪表
        fullscreenButton: false,   //全屏按钮
        geocoder: false,   //右上角查询搜索
        infoBox: false,   //信息框
        homeButton: false,   //home按钮
        sceneModePicker: true,  //3d 2d选择器
        selectionIndicator: false,  //
        timeline: false,   //时间轴
        navigationHelpButton: false,  //右上角帮助按钮
        contextOptions: {   //截图需要的
          webgl:{
            alpha: true,
            depth:true,
            stencil:true,
            antialias:true,
            premultipliedAlpha:true,
            //通过canvas.toDataURL()实现截图需要将该项设置为true
            preserveDrawingBuffer:true,
            failIfMajorPerformanceCaveat:true
          }
        }
      })

定义在init() 里后,记得调用

如果你需要哪些功能,可以把对应的代码去掉,cesium默认是有的 

如果你加载的图层是cesium的图层 你得去cesium的官网注册一个 ion token 不然有的图层你是没法使用的 

推荐阅读