<template>
  <div>{{ coordinate }}</div>
</template>

<script>
import { getParent, mapReady } from "utils/util";

export default {
  name: "CPointer",
  data() {
    return {
      coordinate: null,
      map: null,
    };
  },
  methods: {
    setPoint() {
      var handler = new Cesium.ScreenSpaceEventHandler(
        this.map.scene.canvas
      );
      handler.setInputAction((movement) => {
        //捕获椭球体，将笛卡尔二维平面坐标转为椭球体的笛卡尔三维坐标，返回球体表面的点
        var cartesian = this.map.camera.pickEllipsoid(
          movement.endPosition,
          this.map.scene.globe.ellipsoid
        );
        if (cartesian) {
          //将笛卡尔三维坐标转为地图坐标（弧度）
          var cartographic = this.map.scene.globe.ellipsoid.cartesianToCartographic(
            cartesian
          );
          //将地图坐标（弧度）转为十进制的度数
          var lat_String = Cesium.Math.toDegrees(cartographic.latitude).toFixed(
            4
          );
          var log_String = Cesium.Math.toDegrees(
            cartographic.longitude
          ).toFixed(4);
          var alti_String = (
            this.map.camera.positionCartographic.height / 1000
          ).toFixed(2);
          this.coordinate = log_String + "," + lat_String + "," + alti_String;
        }
      }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
    },
  },
  created() {},
  mounted() {
    this.parent = getParent.call(this);
    mapReady.call(this, (map) => {
    this.map = map;
      console.log(map,this.map);
    });

    // console.log(this.parent.map);
    // this.setPoint();
  },
};
</script>

<style scoped lang="scss">
</style>
