cesium常见操作:添加entity

实体常用的属性主要有如下:

id : 对象的唯一标识符。如果没有提供,则生成GUID。
name : 向用户显示的可读名称,名称可不必唯一。
show : 是否显示实体对象及其子项。
description : 实体的HTML描述。
position : 实体的位置。
billboard : 与此实体关联的广告牌。
label : 与实体关联的标签对象。
point : 与实体关联的点对象。
polygon : 与实体关联的多边形对象。
polyline : 与实体关联的折线对象。

目录

一、点point实体

二、线实体

三、面实体

四、文字label实体(渲染文字注记)

五、广告墙billboard实体(渲染图片)

六、description描述信息


一、点point实体

const point = viewer.entities.add({  // 点
 position: Cesium.Cartesian3.fromDegrees(117,32,5000), 
 name: "point",                                           
 point: {
   color:Cesium.Color.RED,
   pixelSize:30
 }
});

二、线实体

const line = viewer.entities.add({  // 线
  name: "line",
  polyline: {
    positions: Cesium.Cartesian3.fromDegreesArray([-75, 35, -125, 35]),
    width: 5,
    material: Cesium.Color.RED,
    clampToGround: true,
  },
});

三、面实体

const polygon = viewer.entities.add({  // 面
  name: "polygon",
  polygon: {
    hierarchy: Cesium.Cartesian3.fromDegreesArray([
      -115.0,
      37.0,
      -115.0,
      32.0,
      -107.0,
      33.0,
      -102.0,
      31.0,
      -102.0,
      35.0,
    ]),
    material: Cesium.Color.RED,
  },
});

四、文字label实体(渲染文字注记)

在实体上添加一个label属性即可。

 // 添加广告牌实体
    var enetity = viewer.entities.add({
        name: '标点',
        position: Cesium.Cartesian3.fromDegrees(113.122717,23.028762,10),
        label: { //文字标签
          text : '测试名称',
          font : '14pt Source Han Sans CN',    //字体样式
          fillColor:Cesium.Color.BLACK,        //字体颜色
          backgroundColor:Cesium.Color.AQUA,    //背景颜色
          showBackground:true,                //是否显示背景颜色
          style: Cesium.LabelStyle.FILL,        //label样式
          outlineWidth : 2,                    
          verticalOrigin : Cesium.VerticalOrigin.CENTER,//垂直位置
          horizontalOrigin :Cesium.HorizontalOrigin.LEFT,//水平位置
          pixelOffset:new Cesium.Cartesian2(10,0)            //偏移
        },
        billboard:{
            image: '/images/normal_point_128.png',
            horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
            verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
            scale: 0.5,
        }
    })

五、广告墙billboard实体(渲染图片)

    // 添加广告牌实体
    var enetity = viewer.entities.add({
        name: '标点',
        position: Cesium.Cartesian3.fromDegrees(113.122717,23.028762,10),
        billboard:{
            image: '/images/normal_point_128.png',
 // 图像地址,URI或Canvas的属性
                      // 设置颜色和透明度
                      color: Cesium.Color.WHITE.withAlpha(0.8),
                      // 高度(以像素为单位)
                      height: 25,
                      // 宽度(以像素为单位)
                      width: 20,
                      // 逆时针旋转
                      rotation: 0,
                      // 大小是否以米为单位
                      sizeInMeters: false,
                      // 相对于坐标的垂直位置
                      verticalOrigin: Cesium.VerticalOrigin.CENTER,
                      // 相对于坐标的水平位置
                      horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
                      // 该属性指定标签在屏幕空间中距此标签原点的像素偏移量
                      pixelOffset: new Cesium.Cartesian2(0, -10),
                      // 应用于图像的统一比例。比例大于会1.0放大标签,而比例小于会1.0缩小标签。
                      scale: 1.0,
                      // 是否显示
                      show: true
        }
    })

六、description描述信息

1、简单的描述信息

  var wyoming=viewer.entities.add({
    position: Cesium.Cartesian3.fromDegrees(-75.1647, 39.9522),
    name:'我是infobox的标题',
    description:'我是infobox的内容',
    label: {
      text: "我是标签",
      font: "24px Helvetica",
      fillColor: Cesium.Color.SKYBLUE,
      outlineColor: Cesium.Color.BLACK,
      outlineWidth: 2,
      style: Cesium.LabelStyle.FILL_AND_OUTLINE,
      backgroundColor:Cesium.Color.PINK,
      showBackground:true,
    },
  });

2、复杂的描述信息,带HTML设置样式的

wyoming.description = '\
<img\
  width="50%"\
  style="float:left; margin: 0 1em 1em 0;"\
  src="//cesiumjs.org/images/2015/02-02/Flag_of_Wyoming.svg"/>\
<p>\
  Wyoming is a state in the mountain region of the Western \
  United States.\
</p>\
<p>\
  Wyoming is the 10th most extensive, but the least populous \
  and the second least densely populated of the 50 United \
  States. The western two thirds of the state is covered mostly \
  with the mountain ranges and rangelands in the foothills of \
  the eastern Rocky Mountains, while the eastern third of the \
  state is high elevation prairie known as the High Plains. \
  Cheyenne is the capital and the most populous city in Wyoming, \
  with a population estimate of 62,448 in 2013.\
</p>\
<p>\
  Source: \
  <a style="color: WHITE"\
    target="_blank"\
    href="http://en.wikipedia.org/wiki/Wyoming">Wikpedia</a>\
</p>';

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CESIUM EPSG::900913 是指Cesium中常用的投影坐标系,也被称为Web墨卡托投影(Web Mercator)。该投影使用了EPSG:3857的代码。它是一种等距投影,用于在Web地图中显示经纬度坐标。Web墨卡托投影将地球表面投影到一个平面上,使得在地图上的距离与实际距离近似相等,从而方便进行地理数据的可视化和分析。 要在Cesium中使用EPSG::900913投影,您可以在代码中使用相应的坐标系转换库(例如proj4)来将其他坐标系转换为EPSG::900913。您还可以查找提供的地理数据文件(如geojson或json文件)中的"crs"字段,查找与EPSG::900913或EPSG::3857相关的字段名称。 请注意,虽然EPSG::900913常用于Web地图应用程序中,但它实际上是一个非正式的投影代码,因此更推荐使用EPSG::3857来表示Web墨卡托投影。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Cesium出现Unknown crs name: urn:ogc:def:crs:EPSG:xxxx](https://blog.csdn.net/weixin_43972992/article/details/127066824)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [ol-cesium:OpenLayers-Cesium集成](https://download.csdn.net/download/weixin_42121086/14949890)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值