美文网首页
SuperMap iClient3D for WebGL教程(E

SuperMap iClient3D for WebGL教程(E

作者: ayiyayiyo | 来源:发表于2019-06-28 17:39 被阅读0次

在前面的文章里面,我们讲解了关于entity的一系列实体对象;那今天就来介绍下entity的parent父实体属性特征吧。
先来看看是怎么使用的吧

var parent=new Cesium.Entity()
for (var i=0;i<3;i++){
var height = 100000.0 + (200000.0 * i);
    entities.add({
        parent : parent,
        position : Cesium.Cartesian3.fromDegrees(-106.0, 45.0, height),
        box : {
            dimensions : new Cesium.Cartesian3(90000.0, 90000.0, 90000.0),
            material : Cesium.Color.fromRandom({alpha : 1.0})
        }
    })
}

parent本身也是一个entity对象,抽象的来说,他就是一个箱子,然后可根据实际需求,将entity分布在不同的箱子里面进行归纳管理。其中最常见的就是控制显隐,

parent.show=false
parent.gif

除此之外,parent属性还是可以一层一层嵌套,接下来就通过一个简单例子来看看吧


parent嵌套.gif
var AllF=new Cesium.Entity()
var F1 = new Cesium.Entity({
    parent:AllF
});
var F2 = new Cesium.Entity({
    parent:AllF
});
var F3 = new Cesium.Entity({
    parent:AllF
});

for (var i = 0; i < 3; ++i) {
    var height = 100000.0 + (200000.0 * i);
    entities.add({
        parent : F1,
        position : Cesium.Cartesian3.fromDegrees(-106.0, 45.0, height),
        box : {
            dimensions : new Cesium.Cartesian3(90000.0, 90000.0, 90000.0),
            material : Cesium.Color.fromRandom({alpha : 1.0})
        }
    });
    entities.add({
        parent : F2,
        position : Cesium.Cartesian3.fromDegrees(-102.0, 45.0, height),
        ellipsoid : {
            radii : new Cesium.Cartesian3(45000.0, 45000.0, 45000.0),
            material : Cesium.Color.fromRandom({alpha : 1.0})
        }
    });

    entities.add({
        parent : F3,
        position : Cesium.Cartesian3.fromDegrees(-98.0, 45.0, height),
        ellipsoid : {
            radii : new Cesium.Cartesian3(67500.0, 67500.0, 67500.0),
            material : Cesium.Color.fromRandom({alpha : 1.0})
        }
    });  
}

由此可见,parent可用在需要进行分类管理控制的情况下,比如一栋楼的摄像实体,可使用parent属性对每一层楼进行管理。

相关文章

网友评论

      本文标题:SuperMap iClient3D for WebGL教程(E

      本文链接:https://www.haomeiwen.com/subject/sralxctx.html