cesium编程入门(九)实体 Entity

cesium编程入门(五)绘制形状提到过添加实体的方法,这一节聊一聊实体相关的一些内容:

先来看 Entity 的各个属性

  • id

    唯一标志,如果没设置,值就为一个默认给定的GUID
  • name

    名称,可以不唯一
  • availability

    可用性
  • show

    可见性
  • description

    描述
  • position

    位置
  • orientation

    方向
  • viewFrom

    查看此对象的初始偏移量
  • parent

    父节点
  • properties

    与此实体关联的任意属性。
  • Graphics

    相关的形状

    • box
    • corridor
    • cylinder
    • ellipse
    • ellipsoid
    • path
    • point
    • polygon
    • polyline
    • polylineVolume
    • rectangle
    • wall
    • billboard
    • label
    • model

第五篇中描述了部分形状,这里补充 标签,模型,广告牌

标签 label

文字标注,可以设置样式,文字内容,字体,偏移等等

label : {
text : 'Citizens Bank Park',
font : '14pt monospace',
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
outlineWidth : 2,
verticalOrigin : Cesium.VerticalOrigin.BOTTOM,
pixelOffset : new Cesium.Cartesian2(0, -9)
}

模型 model

常见的模型有glTF 和glb

model : {
uri : '../../SampleData/models/CesiumGround/Cesium_Ground.gltf'
}

广告牌 billboard

一个最简单的广告牌一般就是图片,和显示大小

billboard : {
image : 'http://localhost:81/images/2015/02-02/Philadelphia_Phillies.png',
width : 64,
height : 64
}

创建一个实体参考:

//方法一
var entity = new Entity({
id : 'uniqueId'
});
viewer.entities.add(entity); //方法一 简写
viewer.entities.add({
id : 'uniqueId'
}); //方法二
var entity = viewer.entities.getOrCreateEntity('uniqueId');

查找实体的方法:

var entity = viewer.entities.getById('uniqueId');

移除实体的方法:

//方法一,先查后删
var entity = viewer.entities.getById('uniqueId');
viewer.entities.remove(entity)
//方法二,直接删除
viewer.entities.removeById('uniqueId')
//方法三,删除所有
viewer.entities.removeAll()

实体集变化

function onChanged(collection, added, removed, changed){
var msg = 'Added ids';
for(var i = 0; i < added.length; i++) {
msg += '\n' + added[i].id;
}
console.log(msg);
}
viewer.entities.collectionChanged.addEventListener(onChanged);

描述信息 官网示例

只需要修改entity 的description 属性就可以达到目的

var viewer = new Cesium.Viewer('cesiumContainer');

var wyoming = viewer.entities.add({
name : 'Wyoming',
polygon : {
hierarchy : Cesium.Cartesian3.fromDegreesArray([
-109.080842,45.002073,
-105.91517,45.002073,
-104.058488,44.996596,
-104.053011,43.002989,
-104.053011,41.003906,
-105.728954,40.998429,
-107.919731,41.003906,
-109.04798,40.998429,
-111.047063,40.998429,
-111.047063,42.000709,
-111.047063,44.476286,
-111.05254,45.002073]),
height : 0,
material : Cesium.Color.RED.withAlpha(0.5),
outline : true,
outlineColor : Cesium.Color.BLACK
},
description:'divID'//方法一
}); viewer.zoomTo(wyoming); //方法二
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>';

选中

scene 提供了两个方法来获取选中对象,参数都是两个(viewer, windowPosition)

  • pickEntity 获取最顶层的实体
  • drillPickEntities 获取当前位置的所有实体的集合(List)

cesium编程入门(九)实体 Entity的更多相关文章

  1. cesium编程入门(八)设置材质

    cesium编程入门(八)设置材质 Cesium中为几何形状设置材质有多种方法 第一种方法 Material 直接构建Cesium.Material对象,通过设置Material的属性来进行控制,官方 ...

  2. cesium编程入门(七)3D Tiles,模型旋转

    cesium编程入门(七)3D Tiles,模型旋转 上一节介绍了3D Tiles模型的位置移动,和贴地的操作,这一节来聊一聊模型的旋转, 参考<WebGl编程指南>的第四章 假设在X轴和 ...

  3. cesium编程入门(一)cesium简介

    cesium编程入门 cesium是什么 Cesium 是一个跨平台.跨浏览器的展示三维地球和地图的 javascript 库. Cesium 使用WebGL 来进行硬件加速图形,使用时不需要任何插件 ...

  4. cesium编程入门(七)3D Tiles,模型旋转

    cesium编程入门(七)3D Tiles,模型旋转 上一节介绍了3D Tiles模型的位置移动,和贴地的操作,这一节来聊一聊模型的旋转, 参考<WebGl编程指南>的第四章 假设在X轴和 ...

  5. cesium编程入门(六)添加 3D Tiles,并调整位置,贴地

    添加 3D Tiles,并调整位置 3D Tiles 是什么 3DTiles数据集是cesium小组AnalyticlGraphics与2016年3月定义的一种数据集,3DTiles数据集以分块.分级 ...

  6. cesium编程入门(五)绘制形状

    通过Entity添加形状 先来看一个添加立方体的例子 var viewer = new Cesium.Viewer('cesiumContainer'); var redBox = **viewer. ...

  7. cesium编程入门(六)添加 3D Tiles,并调整位置,贴地

    添加 3D Tiles,并调整位置 3D Tiles 是什么 3DTiles数据集是cesium小组AnalyticlGraphics与2016年3月定义的一种数据集,3DTiles数据集以分块.分级 ...

  8. cesium编程入门(五)绘制形状

    通过Entity添加形状 先来看一个添加立方体的例子 var viewer = new Cesium.Viewer('cesiumContainer'); var redBox = **viewer. ...

  9. cesium编程入门(四)界面介绍及小控件隐藏

    感性认识 界面介绍,viewer Geocoder : 查找位置工具,查找到之后会将镜头对准找到的地址,默认使用bing地图 Home Button :视角返回初始位置. Scene Mode Pic ...

随机推荐

  1. Vue基础知识之vue-resource和axios(三)

    vue-resource Vue.js是数据驱动的,这使得我们并不需要直接操作DOM,如果我们不需要使用jQuery的DOM选择器,就没有必要引入jQuery.vue-resource是Vue.js的 ...

  2. Java——复制txt文件

    将源文件复制到目标文件,同时输出源文件内容,需要提供一个源文件和目标文件路径参数(如果不存在则自动创建) public static void copyTxt(String sourceFile, S ...

  3. Java各种Utils小结

    原文地址:http://trinea.iteye.com/blog/1533616 最新内容建议直接访问原文:Android常用的工具类 主要介绍总结的Android开发中常用的工具类,大部分同样适用 ...

  4. How to Integrate JCaptcha in Spring Security

    The repository for JCaptcha is this one: <repository> <id>sourceforge-releases</id> ...

  5. 寄存器CPU存储地址信息和数据信息的地方 CPU通过地址寄存器区分指令和数据

  6. thinkphp 3.2.3 addAll方法的坑

    在批量插入一组数据的时候,总是提示以下错误 Insert value list does not match column list: Column count doesn't match value ...

  7. python报OperationalError: (1366, "Incorrect string value..."的问题解决

    一.环境及问题描述 1. 环境 操作系统:win10,64bit. python版本:2.7.15 mysql版本:5.7.23 2. 问题描述 使用python从某个数据文件读取数据,处理后,用My ...

  8. Flannel网络部署

    一.Flannel网络部署 为Flannel生成证书 [root@linux-node1 ssl]# vim flanneld-csr.json { "CN": "fla ...

  9. 手工kill掉VNC进程的故障处理

    1.模拟Kill掉已经启动的VNC服务 1)启动桌面1的服务 [root@testdb ~]# vncserver :1 New 'testdb:1 (root)' desktop is testdb ...

  10. oracle触发器--if else demo

    CREATE OR REPLACE Trigger trig_solr_index_el_lesson After Update of lessonid, lessonname, lessongoal ...