Cesium地图小控件(底图设置),点线面

首先我们先来看一下地图小控件

 this.viewer = new Cesium.Viewer('cesiumContainer', {
        geocoder: true, //搜索按钮(可以搜索地区)
        timeline: true, //底部时间轴
        animation: true, //左下角仪表盘
        baseLayerPicker: true, //底图切换按钮
        fullscreenButton: true, //全屏按钮(毋庸置疑就是全屏)
        vrButton: true, //vr按钮
        homeButton: true, //初始视角按钮(小房子图标,无论你怎么旋转放大缩小点击后都会回到你初始化页面的样子)
        sceneModePicker: true, //二维 <===> 三维切换按钮
        navigationHelpButton: true, //帮助按钮
        // ArcGIS在线影像底图(只有baseLayerPicker为true时可用)
        imageryProvider: new Cesium.ArcGisMapServerImageryProvider({
          url:
            'http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer',
        }),
      });

在这里插入图片描述

		vrButton: true,

在这里插入图片描述

        sceneModePicker: true, //二维 <===> 三维切换按钮

在这里插入图片描述

这是默认的地球跟上面那个地球看出区别了吗

在这里插入图片描述

如果想设置初始视角

 this.viewer.camera.setView({
        // Cesium的坐标是以地心为原点
        // fromDegrees(lng,lat,alt)方法,将经纬度和高程转换为世界坐标
        //lng 经度 lat纬度 alt高度
        destination: Cesium.Cartesian3.fromDegrees(111.0, 35.0, 500000.0),
        orientation: {
          // 指向
          heading: Cesium.Math.toRadians(0),
          // 视角
          pitch: Cesium.Math.toRadians(-40),
          roll: 0.0,
        },
      });
//heading 可以理解为y指针绕着蓝线转(360度)
//pitch 可以理解为z指针绕着黄线转(360度)
//roll 可以理解为x指针绕着绿线转(360度)
//当然是根据坐标点不是整个地球

在这里插入图片描述

接下来我们往地球上添加点,线,面

点(point)

 this.viewer.entities.add({
        name: 'point',
        position: Cesium.Cartesian3.fromDegrees(111.0, 40.0, 0),//坐标
        point: {
          show: true, // default
          color: Cesium.Color.AQUA,//点的颜色
          pixelSize: 15, //点的大小
          outlineWidth: 0,//边框
        },
        description: `<p>这是entity的属性信息,可以为html</p> `,
      });

在这里插入图片描述

线(polyline)

 	var position = [112.0, 40.0, 0, 110.0, 40.0, 0];
      this.viewer.entities.add({
        name: 'line',
        polyline: {
          positions: Cesium.Cartesian3.fromDegreesArrayHeights(position),
          width: 4,
          //发光材质
          material: new Cesium.PolylineGlowMaterialProperty({
            glowPower: 0.8,
            taperPower: 0.5,
            color: Cesium.Color.CORNFLOWERBLUE,
          }),
          //外轮廓材质
          // material: new Cesium.PolylineOutlineMaterialProperty({
          //   color: Cesium.Color.ORANGE,
          //   outlineWidth: 5,
          //   outlineColor: Cesium.Color.BLACK,
          // }),
          //带箭头的线
          // material: new Cesium.PolylineArrowMaterialProperty(Cesium.Color.PURPLE),
          //虚线
          // material: new Cesium.PolylineDashMaterialProperty({
          //   color: Cesium.Color.CYAN,
          // }),
          // 线低于地形时用于绘制折线的材质
          // depthFailMaterial: Cesium.Color.WHITE,

          // 折线段必须遵循的线型
          // arcType: Cesium.ArcType.GEODESIC,
          clampToGround: true, // 是否贴地
        },
      });

在这里插入图片描述

面(Polygon)

var polygon = this.viewer.entities.add({
        name: 'polygon',
        polygon: {
          show: true,
          hierarchy: Cesium.Cartesian3.fromDegreesArray([
            115.0,
            43.0,
            115.0,
            42.0,
            113.0,
            42.0,
            113.0,
            43.0,
          ]),
          height: 0, // 多边形相对于椭球面的高度
          heightReference: Cesium.HeightReference.NONE,
          // extrudedHeight: 0, // 多边形的凸出面相对于椭球面的高度
          // extrudedHeightReference: Cesium.HeightReference.NONE,
          stRotation: 0.0, // 多边形纹理从北方逆时针旋转
          granularity: Cesium.Math.RADIANS_PER_DEGREE, // 每个纬度和经度点之间的角距离
          fill: true,//是否填充
          material: Cesium.Color.YELLOW,//材质
          outline: false,//是否边框
          outlineColor: Cesium.Color.BLACK,//边框颜色
          outlineWidth: 1.0,//边框宽度
          perPositionHeight: false, // 是否使用每个位置的高度
          closeTop: true, // 如果为false,则将挤出的多边形顶部留空
          closeBottom: true, // 如果为false,则将挤出的多边形的底部保留为开放状态
          // 多边形边缘必须遵循的线型    type:ArcType 定义连接顶点应采用的路径。
          // NONE 与椭圆表面不符的直线;GEODESIC 遵循测地路径;RHUMB	遵循大黄蜂或恶魔般的道路。
          arcType: Cesium.ArcType.GEODESIC,
          shadows: Cesium.ShadowMode.DISABLED,
        },
      });

在这里插入图片描述

中文api

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要基于天地图服务加载Cesium底图并实现底图切换,你可以使用Cesium官方提供的`ImageryLayer`类来实现。 首先,你需要获取天地图的影像图层服务地址,例如: ```javascript var tiandituUrl = 'http://t0.tianditu.gov.cn/img_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&FORMAT=tiles&TILEMATRIXSET=w&'; var tiandituToken = 'tk=your_token'; ``` 然后,你可以使用`ImageryLayer`类来加载天地图的影像图层,并将其添加到Cesium的场景。代码如下: ```javascript var viewer = new Cesium.Viewer('cesiumContainer'); var tiandituLayer = new Cesium.ImageryLayer( new Cesium.WebMapTileServiceImageryProvider({ url: tiandituUrl + tiandituToken, layer: 'img', style: 'default', format: 'tiles', tileMatrixSetID: 'w', maximumLevel: 18, credit: new Cesium.Credit('天地图影像服务'), }) ); viewer.scene.imageryLayers.add(tiandituLayer); ``` 这样,你就可以在Cesium加载天地图的影像图层了。如果你想切换底图,只需要移除当前的影像图层,然后添加新的影像图层即可。例如,以下代码实现了在点击按钮时切换底图: ```javascript var button = document.getElementById('switchButton'); var isTianditu = true; button.onclick = function() { if (isTianditu) { viewer.scene.imageryLayers.remove(tiandituLayer); var bingLayer = new Cesium.ImageryLayer( new Cesium.BingMapsImageryProvider({ url: 'https://dev.virtualearth.net', key: 'your_bing_maps_key', mapStyle: Cesium.BingMapsStyle.AERIAL_WITH_LABELS, }) ); viewer.scene.imageryLayers.add(bingLayer); isTianditu = false; } else { viewer.scene.imageryLayers.remove(bingLayer); viewer.scene.imageryLayers.add(tiandituLayer); isTianditu = true; } }; ``` 这里的代码实现了在点击按钮时切换底图,如果当前是天地图,则切换到Bing Maps;如果当前是Bing Maps,则切换回天地图

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值