fix:修改客户端无人船第一视角
This commit is contained in:
@@ -535,8 +535,38 @@ const CenterView: React.FC<CenterViewProps> = ({ deviceSn, routes, selectedRoute
|
|||||||
const setInitialSailingView = (waypoints: BoatWaypointDTO[]) => {
|
const setInitialSailingView = (waypoints: BoatWaypointDTO[]) => {
|
||||||
if (!selectedRouteId || !waypoints || waypoints.length < 2) return false;
|
if (!selectedRouteId || !waypoints || waypoints.length < 2) return false;
|
||||||
try {
|
try {
|
||||||
flyToRouteLibrary(selectedRouteId);
|
const wp0 = waypoints[0];
|
||||||
viewer.scene.requestRender();
|
const wp1 = waypoints[1];
|
||||||
|
|
||||||
|
// 计算从点0到点1的航向角
|
||||||
|
const dLon = (wp1.longitude - wp0.longitude) * Math.PI / 180;
|
||||||
|
const lat1 = wp0.latitude * Math.PI / 180;
|
||||||
|
const lat2 = wp1.latitude * Math.PI / 180;
|
||||||
|
const y = Math.sin(dLon) * Math.cos(lat2);
|
||||||
|
const x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLon);
|
||||||
|
const headingRad = Math.atan2(y, x);
|
||||||
|
|
||||||
|
// 为了让第一个航点在视野中可见,我们需要将相机放置在第一个航点“后方”一段距离,并抬高一定高度
|
||||||
|
// 根据 headingRad 将相机向反方向平移
|
||||||
|
const offsetDistance = 60; // 距离航点 60 米远
|
||||||
|
const height = 40; // 相机高度 40 米
|
||||||
|
|
||||||
|
// 使用简单的经纬度偏移近似(适用于小范围),也可以用球体推算
|
||||||
|
// 1纬度大约111公里,1经度随纬度变化。使用简单的三角函数反推相机位置
|
||||||
|
const R = 6378137; // 地球半径
|
||||||
|
const camDLat = -offsetDistance * Math.cos(headingRad) / R;
|
||||||
|
const camDLon = -offsetDistance * Math.sin(headingRad) / (R * Math.cos(Math.PI * wp0.latitude / 180));
|
||||||
|
|
||||||
|
const camLat = wp0.latitude + camDLat * 180 / Math.PI;
|
||||||
|
const camLon = wp0.longitude + camDLon * 180 / Math.PI;
|
||||||
|
viewer.camera.setView({
|
||||||
|
destination: Cesium.Cartesian3.fromDegrees(camLon, camLat, height),
|
||||||
|
orientation: {
|
||||||
|
heading: headingRad,
|
||||||
|
pitch: Cesium.Math.toRadians(-25), // 稍微向下俯视
|
||||||
|
roll: 0
|
||||||
|
}
|
||||||
|
}); viewer.scene.requestRender();
|
||||||
return true;
|
return true;
|
||||||
} catch {
|
} catch {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user