ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Cesium快速上手10-Viewer Entities组合

2021-09-09 21:34:49  阅读:328  来源: 互联网

标签:10 entities Entities Viewer image viewer html Cesium png


Viewer/Entities的作用:

方便创建直观的对象,同时做到性能优化(billboard、point等)
提供一些方便使用的函数:flyTo/zoomTo
赋予Entity对象时间这个属性,对象具备动态特性/Primitive不具备
提供一些UI(homeButton/sceneModePicker/projectionPicker/baseLayerPicker)
大量的快捷方式,camera等未必是好事。。
Datasource模式来加载大规模数据:Geojson
Datasource结构
Entities是一个快捷方式,其实返回的是viewer.dataSourceDisplay.defaultDatasource.entities ;

Entity结构

image.png

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

示例 可参考 Geometries

image.png

box示例

http://localhost:8080/Apps/Sandcastle/index.html?src=Box.html&label=Geometries

image.png

box 就是立方体
cylinder 是圆锥 圆柱

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

var blueBox = viewer.entities.add({
    name : 'Blue box',
    position: Cesium.Cartesian3.fromDegrees(-114.0, 40.0, 300000.0),
    box : {
        dimensions : new Cesium.Cartesian3(400000.0, 300000.0, 500000.0),
        material : Cesium.Color.BLUE
    }
});

var redBox = viewer.entities.add({
    name : 'Red box with black outline',
    position: Cesium.Cartesian3.fromDegrees(-107.0, 40.0, 300000.0),
    box : {
        dimensions : new Cesium.Cartesian3(400000.0, 300000.0, 500000.0),
        material : Cesium.Color.RED.withAlpha(0.5),
        outline : true,
        outlineColor : Cesium.Color.BLACK
    }
});

var outlineOnly = viewer.entities.add({
    name : 'Yellow box outline',
    position: Cesium.Cartesian3.fromDegrees(-100.0, 40.0, 300000.0),
    box : {
        dimensions : new Cesium.Cartesian3(400000.0, 300000.0, 500000.0),
        fill : false,
        outline : true,
        outlineColor : Cesium.Color.YELLOW
    }
});

viewer.zoomTo(viewer.entities);

圆锥 圆柱

http://localhost:8080/Apps/Sandcastle/index.html?src=Cylinders%20and%20Cones.html&label=Geometries

image.png

topRadius = bottomRadius 是圆柱
topRadius=0, bottomRadius 大于0 是圆锥

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

var greenCylinder = viewer.entities.add({
    name : 'Green cylinder with black outline',
    position: Cesium.Cartesian3.fromDegrees(-100.0, 40.0, 200000.0),
    cylinder : {
        length : 400000.0,
        topRadius : 200000.0,
        bottomRadius : 200000.0,
        material : Cesium.Color.GREEN.withAlpha(0.5),
        outline : true,
        outlineColor : Cesium.Color.DARK_GREEN
    }
});

var redCone = viewer.entities.add({
    name : 'Red cone',
    position: Cesium.Cartesian3.fromDegrees(-105.0, 40.0, 200000.0),
    cylinder : {
        length : 400000.0,
        topRadius : 0.0,
        bottomRadius : 200000.0,
        material : Cesium.Color.RED
    }
});

viewer.zoomTo(viewer.entities);

API文档

Entity
Cesium.EntityCollection

对比primitives 与Entity

    1. 与primitives 相比,entity 使用更简便。一个entity可能是由多个primitives组合完成的。
    1. entity内部实现的时候还是用primitives实现的;entity更高层一点。primitive需要关注更多的细节;
  • 3.单个Primitive只能绑定一个材质Appearance,所有的GeometryInstance都使用这一个Appearance;要更换不同的Appearance,就得用不同的Primitive;初始化时还涉及坐标旋转以使绘制的图形在地图表面显示出来。

image.png

实现同样的效果,比较两种实现方式
primitive方式
entity方式

Datasource结构

image.png

每一个Datasource都挂在Entity下;

geojson

http://localhost:8080/Apps/Sandcastle/index.html?src=GeoJSON%20and%20TopoJSON.html&label=DataSources

image.png

http://localhost:8080/Apps/Sandcastle/index.html?src=GeoJSON%20simplestyle.html&label=DataSources

image.png

Custom DataSource 自定义数据源格式

http://localhost:8080/Apps/Sandcastle/index.html?src=Custom%20DataSource.html&label=DataSources

image.png

其他

  • flyTo
    viewer.flyTo(target, options) 直接飞到目标物上,如3dTiles ; 异步操作,若目前没有目标数据,会等待目标准备好之后再飞过去;
    camera.flyTo 飞到坐标点上或者某个区域上,

本文转自 https://www.jianshu.com/p/dd5e83b333a0,如有侵权,请联系删除。

标签:10,entities,Entities,Viewer,image,viewer,html,Cesium,png
来源: https://www.cnblogs.com/hustshu/p/15248854.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有