• cesium 一些功能


    1.获取相机参数

    1. function getcameraPosInfo () {
    2. // 获取 相机姿态信息
    3. let head = viewer.scene.camera.heading
    4. let pitch = viewer.scene.camera.pitch
    5. let roll = viewer.scene.camera.roll
    6. let info = { head: head, pitch: pitch, roll: roll }
    7. // 获取位置 wgs84的地心坐标系,x,y坐标值以弧度来表示
    8. let position = viewer.scene.camera.positionCartographic // with longitude and latitude expressed in radians and height in meters.
    9. // 以下方式也可以获取相机位置只是返回的坐标系不一样
    10. // var position = viewer.scene.camera.position //cartesian3 空间直角坐标系
    11. // var ellipsoid = scene.globe.ellipsoid;
    12. // var position
    13. =ellipsoid.cartesianToCartographic(viewer.scene.camera.position)//
    14. // 弧度转经纬度
    15. let longitude = Cesium.Math.toDegrees(position.longitude)
    16. let latitude = Cesium.Math.toDegrees(position.latitude)
    17. let height = position.height
    18. return { lng: longitude, lat: latitude, h: height, mat: info }
    19. }

    2.获取相机中心点坐标 

    1. /* 获取camera高度 */
    2. function getHeight () {
    3. if (viewer) {
    4. let scene = viewer.scene
    5. let ellipsoid = scene.globe.ellipsoid
    6. let height = ellipsoid.cartesianToCartographic(viewer.camera.position).height
    7. return height
    8. }
    9. }
    10. /* 获取屏幕中心点坐标 */
    11. function getCenterPosition () {
    12. let result = viewer.camera.pickEllipsoid(new Cesium.Cartesian2(viewer.canvas.clientWidth / 2, viewer.canvas.clientHeight / 2))
    13. let curPosition = Cesium.Ellipsoid.WGS84.cartesianToCartographic(result)
    14. let lon = curPosition.longitude * 180 / Math.PI
    15. let lat = curPosition.latitude * 180 / Math.PI
    16. let height = getHeight()
    17. return {
    18. lon: lon,
    19. lat: lat,
    20. height: height
    21. }
    22. }

    3.锁定和解除锁定相机视角

    1. let center = Cesium.Cartesian3.fromDegrees(prosition.lon, prosition.lat)// camera视野中心点坐标
    2. let heading = Cesium.Math.toRadians(parseFloat(heading_show.value))
    3. let pitch = Cesium.Math.toRadians(-45.0)
    4. let range = prosition.height
    5. //锁定视角
    6. viewer.camera.lookAt(center, new Cesium.HeadingPitchRange(heading, pitch, range))
    7. //解除锁定
    8. viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY)

    4.3D场景和2D场景切换

    1. viewer.scene.mode = Cesium.SceneMode.SCENE3D // 三维场景
    2. viewer.scene.mode = Cesium.SceneMode.SCENE2D // 平面场景

    5.获取相机位置,姿态 

    1. // 获取相机位置,姿态等
    2. function getcameraPosInfo () {
    3. // 获取 相机姿态信息
    4. let head = viewer.scene.camera.heading
    5. let pitch = viewer.scene.camera.pitch
    6. let roll = viewer.scene.camera.roll
    7. let info = { head: head, pitch: pitch, roll: roll }
    8. // 获取位置 wgs84的地心坐标系,x,y坐标值以弧度来表示
    9. let position = viewer.scene.camera.positionCartographic // with longitude and latitude expressed in radians and height in meters.
    10. // 以下方式也可以获取相机位置只是返回的坐标系不一样
    11. // var position = viewer.scene.camera.position //cartesian3 空间直角坐标系
    12. // var ellipsoid = scene.globe.ellipsoid;
    13. // var position =ellipsoid.cartesianToCartographic(viewer.scene.camera.position)//
    14. // 弧度转经纬度
    15. let longitude = Cesium.Math.toDegrees(position.longitude)
    16. let latitude = Cesium.Math.toDegrees(position.latitude)
    17. let height = position.height
    18. return { lon: longitude, lat: latitude, height: height, mat: info }
    19. }

  • 相关阅读:
    C# wpf 实现截屏框热键截屏功能
    RFID技术引领汽车零部件加工新时代
    泛型机制和增强for循环
    微信小程序rich-text里面写多行溢出显示省略号在ios中不显示的问题
    LeetCode 67. Add Binary
    【Java基础】面向对象进阶
    YZ系列工具之YZ13:VBA_过滤数据并行删除
    金仓数据库 KingbaseGIS 使用手册(6.10. 几何对象操作运算符)
    成功解决:Xshell 无法连接虚拟机。如何使用Xshell连接CentOS7虚拟机(详细步骤过程)
    基于javaweb的幼儿园管理系统(java+jsp+html+javascript+mysql)
  • 原文地址:https://blog.csdn.net/weixin_41012767/article/details/127704426