| | |
| | | return true |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 飞到中心点并且所有点在可视范围 |
| | | * @param lngLatArr |
| | | * @param viewer |
| | | * @param rangeMultiple 范围倍数越大飞的越高默认2 |
| | | */ |
| | | export function flyVisual(lngLatArr,viewer,rangeMultiple = 2) { |
| | | if (!Array.isArray(lngLatArr) || lngLatArr.length === 0) return |
| | | const positions = lngLatArr.map(([lon, lat]) => |
| | | Cesium.Cartesian3.fromDegrees(Number(lon), Number(lat)) |
| | | ) |
| | | // 计算包围盒 BoundingSphere(所有点的外接球) |
| | | const boundingSphere = Cesium.BoundingSphere.fromPoints(positions) |
| | | viewer.camera.flyToBoundingSphere(boundingSphere, { |
| | | duration: 0, |
| | | offset: new Cesium.HeadingPitchRange(0, 0, boundingSphere.radius * rangeMultiple), |
| | | }) |
| | | } |
| | | |
| | | // 获取视口地图中心点 |
| | | export function getMapCenterPoint(viewer) { |
| | | const centerResult = viewer.camera.pickEllipsoid( |
| | | new Cesium.Cartesian2( |
| | | viewer.canvas.clientWidth / 2, |
| | | viewer.canvas.clientHeight / 2 |
| | | ) |
| | | ); |
| | | const curPosition = Cesium.Ellipsoid.WGS84.cartesianToCartographic(centerResult); |
| | | const longitude = (curPosition.longitude * 180) / Math.PI; |
| | | const latitude = (curPosition.latitude * 180) / Math.PI; |
| | | return { longitude, latitude }; |
| | | } |