最近用cesium做的一些效果,加載的entity對象,希望通過鼠標操作,或者信息輸入,實現位置移動以及圍繞中心位置的旋轉。網上搜了很多案例,沒有解決這個問題。今天偶然解決了,把解決辦法梳理如下。
我的使用場景是把視頻信息帖合到entity上,然後調整entity的位置角度,與周圍地形建築信息“”融合“”。加載entity對象方法如下
viewer.entities.add({
id: 'Blue rectangle, zIndex 3',
rectangle: {
coordinates: Cesium.Rectangle.fromDegrees(111.8665, 40.9382, 111.8675, 40.9387),
material: element, //Cesium.Color.BLUE,
zIndex: 3,
rotation: Cesium.Math.toRadians(180),
stRotation: Cesium.Math.toRadians(180)
}
});
位置旋轉主要看這兩個屬性
rotation: Cesium.Math.toRadians(180), // 整體旋轉entity的角度,圍繞中心點
stRotation: Cesium.Math.toRadians(180) // 旋轉entity上的材質信息
如果entity幾何形狀和材質信息需要一起旋轉,需要一起調用才能保持同步。
如果需要支持鼠標移動entity對象,這個鏈接實現的很好,可以參考https://blog.csdn.net/weixin_40184249/article/details/93633337。