定位
相机坐标定位
Javascript
// 经纬度
viewer.camera.flyTo({
destination: new LSGlobe.Cartesian3.fromDegrees(120, 30, 10000)
});
// 世界坐标(可以使用坐标转换)
viewer.camera.flyTo({
destination: new LSGlobe.Cartesian3(
311194.90239811136, 5645828.957550833, 2968798.9842634676
)
});
// 定位相机位置和方向1,相关参数可以查看相机信息
viewer.camera.flyTo({
destination : LSGlobe.Cartesian3.fromDegrees(-122.19, 46.25, 5000.0),
orientation : {
direction : new LSGlobe.Cartesian3(-0.04231243104240401, -0.20123236049443421, -0.97862924300734),
up : new LSGlobe.Cartesian3(-0.47934589305293746, -0.8553216253114552, 0.1966022179118339)
}
});
// 定位相机位置和方向2,相关参数可以查看相机信息
viewer.camera.flyTo({
destination : LSGlobe.Cartesian3.fromDegrees(-122.19, 46.25, 5000.0),
orientation : {
heading : LSGlobe.Math.toRadians(175.0),
pitch : LSGlobe.Math.toRadians(-35.0),
roll : 0.0
}
});
// 定位相机位置3,reactangle可以从影像地形中获取
// 影像图层.imageryProvider.rectangle
// 地形图层.terrainProvider.rectangle
viewer.camera.flyTo({
destination : reactangle
});
// 利用点集合定位,positions世界坐标数组
const boundingSphere = LSGlobe.BoundingSphere.fromPoints(positions);
viewer.camera.flyToBoundingSphere(boundingSphere, {
offset: new LSGlobe.HeadingPitchRange(0, -LSGlobe.Math.PI_OVER_TWO, 0)
});
注意
上面positions可以通过:
含有面的entity
.polygon.hierarchy.getValue().positions获取
含有线的entity
..polyline.positions.getValue()获取
boundingSphere属性:
boundingSphere.center
是中心点,boundingSphere.radius
是半径
对象定位(不够准确)
Javascript
// oTarget是对应对象,可以使Entity,Cesium3DTileset,ImageLayer,Terrainlayer,primitive,datasource;
viewer.flyTo(oTarget, {
duration: 2, //飞行时间
maximumHeight: 50000, // 相机的最高高度
// heading,pitch,range三个值分别代表,
// heading:目标物体坐标系的z轴旋转,单位是弧度,0代表正北方向,
// pitch:Y轴旋转,顺时针是正的,单位是弧度,-90代表从顶部往下看,
// range代表距离目标的距离
offset: new LSGlobe.HeadingPitchRange(LSGlobe.Math.toRadians(0), LSGlobe.Math.toRadians(-45), 2000)
});
定位对象优化
zoomto 代表直接跳转到目的地,没有中间的飞行时间这些参数,只有一个偏移量
Javascript
viewer.zoomTo(oNewMark,
new LSGlobe.HeadingPitchRange(
LSGlobe.Math.toRadians(0),
LSGlobe.Math.toRadians(-45), 2000
)
);