Cesium基础知识-Entity管理

//普通entity加载模型

  1. function LoadEntityModel() {
  2.     var redPolygon = viewer.entities.add({
  3.         name: "Red polygon on surface",
  4.         polygon: {
  5.             hierarchy: Cesium.Cartesian3.fromDegreesArray([
  6.                 113.490283, 28.884350000000005,
  7.                 113.53232437057214, 28.86366476861567,
  8.                 113.52849410091294, 28.789783075024378,
  9.                 113.33021641184426, 28.783389028027322,
  10.                 113.490283, 28.884350000000005,
  11.             ]),
  12.             material: Cesium.Color.RED,
  13.         },
  14.     });
  15.     viewer.zoomTo(redPolygon);
  16. }
  17. //LoadEntityModel();

//DataSource管理entity模型

  1. function UseDataSourceEntity() {
  2.     //先创建一个CustomDataSource源,然后把entity存入这里面
  3.     let Polygon = new Cesium.CustomDataSource("paowuxian");
  4.     viewer.dataSources.add(Polygon);
  5.     //添加数据的方式
  6.     Polygon.entities.add({
  7.         polygon: {
  8.             hierarchy: Cesium.Cartesian3.fromDegreesArray([
  9.                 113.490283, 28.884350000000005,
  10.                 113.53232437057214, 28.86366476861567,
  11.                 113.52849410091294, 28.789783075024378,
  12.                 113.33021641184426, 28.783389028027322,
  13.                 113.490283, 28.884350000000005,
  14.             ]),
  15.             material: Cesium.Color.BLUE,
  16.         },
  17.     });
  18.     //清除数据的方式  这样就不会清除上面的数据
  19.     //Polygon.entities.removeAll()
  20.     viewer.zoomTo(Polygon);
  21. }
  22. //UseDataSourceEntity();

//图元管理entity模型

  1. function UseDataSourceTuYuanEntity() {
  2.     let ldCollection = new Cesium.PrimitiveCollection("tuyuan");
  3.     viewer.scene.primitives.add(ldCollection);
  4.     //先创建一个CustomDataSource源,然后把entity存入这里面
  5.     let Polygon = new Cesium.CustomDataSource("paowuxian");
  6.     viewer.dataSources.add(Polygon);
  7.     //添加数据的方式
  8.     Polygon.entities.add({
  9.         polygon: {
  10.             hierarchy: Cesium.Cartesian3.fromDegreesArray([
  11.                 113.490283, 28.884350000000005,
  12.                 113.53232437057214, 28.86366476861567,
  13.                 113.52849410091294, 28.789783075024378,
  14.                 113.33021641184426, 28.783389028027322,
  15.                 113.490283, 28.884350000000005,
  16.             ]),
  17.             material: Cesium.Color.GREEN,
  18.         },
  19.     });
  20.     ldCollection.add(Polygon);
  21.     
  22.     //清除图元
  23.     // ldCollection.clear()
  24.     viewer.zoomTo(Polygon);
  25. }
  26. //UseDataSourceTuYuanEntity();

//使用图元Primitive

  1. function UsePrimitive() {
  2.     var scene = viewer.scene
  3.         var instance = new Cesium.GeometryInstance({
  4.             geometry: new Cesium.RectangleGeometry({
  5.                 rectangle: Cesium.Rectangle.fromDegrees(-100.0, 20.0, -90.0, 30.0),
  6.                 vertexFormat: Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT
  7.             })
  8.         });
  9.         let primitive1 = new Cesium.Primitive({
  10.             geometryInstances: instance,
  11.             appearance: new Cesium.EllipsoidSurfaceAppearance({
  12.                 material: new Cesium.Material({
  13.                     fabric: {
  14.                         type: 'Image',
  15.                         uniforms: {
  16.                             image: '../img/earth.png',
  17.                             color: new Cesium.Color(1.0, 1.0, 0.0, 1.0),
  18.               cellAlpha: 1
  19.                         },
  20.                         source: `
  21.                         uniform vec4 color;
  22.             uniform float cellAlpha;
  23.                 czm_material czm_getMaterial(czm_materialInput materialInput)
  24.                     {
  25.                       czm_material material = czm_getDefaultMaterial(materialInput);
  26.                       vec2 st = materialInput.st;
  27.                       float aa = st.s * st.t;
  28.                       vec3 halfColor = color.rgb * aa + texture2D(image, materialInput.st).rgb * (1.0 - aa);
  29.                       halfColor *= 0.5;
  30.                       material.diffuse = halfColor;
  31.                       material.emission = halfColor;
  32.                       // material.alpha = color.a * aa;
  33.                       material.alpha = 1.0;
  34.                       return material;
  35.                 }
  36.             `
  37.                     }
  38.                 })
  39.             })
  40.         })
  41.         scene.primitives.add(primitive1);
  42. }
  43. //UsePrimitive();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值