其他分享
首页 > 其他分享> > Cesium快速上手10-Viewer Entities组合

Cesium快速上手10-Viewer Entities组合

作者:互联网

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

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

其他

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

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