【超图+CESIUM】【基础API使用示例】30、超图|CESIUM -【坐标转换】弧度转经纬度

前言

	缺少前置学习使用资料,请自行查阅:[https://blog.csdn.net/weixin_44402694/article/details/123110136](https://blog.csdn.net/weixin_44402694/article/details/123110136)
	以下示例使用到的公共静态资料,不建议下载,建议官网自行下载超图Build资源,示例所涉及图片会在示例使用到时提供出来。如有需要可下载:[https://download.csdn.net/download/weixin_44402694/82180350](https://download.csdn.net/download/weixin_44402694/82180350)。
【坐标转换】弧度转经纬度。

使用

  • 效果
    【超图+CESIUM】【基础API使用示例】30、超图|CESIUM -【坐标转换】弧度转经纬度_第1张图片

  • 核心代码

// 弧度转经纬度
function convertion1(hulon, hulat, huheight) {
  const longitude = Cesium.Math.toDegrees(hulon) //将弧度转为度
  const latitude = Cesium.Math.toDegrees(hulat)
  const height = Cesium.Math.toDegrees(huheight)
  return {
    longitude,
    latitude,
    height
  }
}
  • 完整代码

<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>坐标转换 - 弧度转经纬度title>
    <link href="./public/Build/Cesium/Widgets/widgets.css" rel="stylesheet" />
    <script
      type="text/javascript"
      src="./public/Build/Cesium/Cesium.js"
    >script>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      html,
      body,
      #cesium-container {
        width: 100%;
        height: 100%;
      }
      .panel {
        width: 150px;
        position: fixed;
        left: 10px;
        top: 10px;
        z-index: 1;
        background-color: #fff;
      }
      .panel .btn {
        cursor: pointer;
        word-break: break-all;
      }
      .latlng-wrap {
        position: fixed;
        left: 200px;
        top: 10px;
        z-index: 1;
        background-color: #fff;
        display: flex;
        flex-direction: column;
      }
      .old {
        display: flex;
        flex-direction: row;
      }
      .old p {
        margin-right: 20px;
      }
      .new {
        display: flex;
        flex-direction: row;
      }
      .new p {
        margin-right: 20px;
      }
      .new p .result1 {
        color: red;
      }
    style>
  head>
  <body>
    <div id="cesium-container" />
    <div class="panel">
      <p class="btn">弧度转经纬度p>
    div>
    <div class="latlng-wrap">
      <div class="old">
        <p>经度lon:2.0943951023931953p>
        <p>纬度lat:0.5235987755982988p>
        <p>高度:0p>
      div>
      <div class="new">
        <p>
          <span>经度lon:span>
          <span class="result1">span>
        p>
        <p>
          <span>纬度lat:span>
          <span class="result1">span>
        p>
        <p>
          <span>高度:span>
          <span class="result1">span>
        p>
      div>
    div>
    <script>
      let viewer
      window.onload = function () {
        viewer = new Cesium.Viewer('cesium-container')
        initBindConversionEventHandler()
      }
      // 初始化绑定转换事件
      function initBindConversionEventHandler() {
        const btns = document.querySelectorAll('.panel .btn')
        btns[0].addEventListener('click', () => {
          const resultSpan = document.querySelectorAll('.result1')
          const { longitude, latitude, height } = convertion1(
            2.0943951023931953,
            0.5235987755982988,
            0
          )
          resultSpan[0].innerHTML = longitude
          resultSpan[1].innerHTML = latitude
          resultSpan[2].innerHTML = height
        })
      }
      // 弧度转经纬度
      function convertion1(hulon, hulat, huheight) {
        const longitude = Cesium.Math.toDegrees(hulon) //将弧度转为度
        const latitude = Cesium.Math.toDegrees(hulat)
        const height = Cesium.Math.toDegrees(huheight)
        return {
          longitude,
          latitude,
          height
        }
      }
    script>
  body>
html>

你可能感兴趣的:(超图+CESIUMJS,超图+CESIUM)