Cesium实战系列文章总目录
:
传送门
1.实现效果
2.实现方法
这里以椭圆ellipse为例,实现旋转。
2.1官方文档
首先查看entity中ellipse中的相关属性,发现有设置实体逆时针旋转角度的属性rotation
:传送门
因此可以使用回调函数动态设置旋转角度
,即可实现实体的旋转效果。
2.2具体实现
2.2.1核心函数
/**
* @description: 旋转实体entity
* @param {*} instance :具体的实体
* @param {*} _rotation :初始旋转角度
* @param {*} _amount :旋转角度变化量
* @return {*}
*/
function rotateEntity(instance, _rotation, _amount) {
instance.rotation = new Cesium.CallbackProperty(function() {
_rotation += _amount;
if (_rotation >= 360 || _rotation <= -360) {
_stRotation = 0;
}
return Cesium.Math.toRadians(_rotation);
}, false)
}
2.2.2代码调用
// 旋转椭圆
let ellipseRotate = this.viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(113.9236839, 22.528061),
id: 'ellipseRotateTest',
ellipse: {
semiMinorAxis: 500.0,
semiMajorAxis: 1000.0,
material: new Cesium.Color(1.0, 1.0, 0.0, 1.0),
}
})
rotateEntity(ellipseRotate.ellipse, 0, 1);