import * as Cesium from 'cesium'

export type Pos2D = {x: number, y: number}
export type Pos3D = {x: number, y: number, z: number}

export const toScreen = (viewer: any, pos: Pos3D) => {
  const cartesian3 = new Cesium.Cartesian3(pos.x, pos.y, pos.z)
  const data = Cesium.SceneTransforms.wgs84ToWindowCoordinates(viewer.scene, cartesian3);
  return {
    x: data.x,
    y: data.y
  }
}

export const toReal = (viewer: any, pos: Pos2D): Pos3D => {
  var pick1= new Cesium.Cartesian2(pos.x, pos.y);
  var cartesian = viewer.scene.globe.pick(viewer.camera.getPickRay(pick1),viewer.scene);
  return {
    x: cartesian.x,
    y: cartesian.y,
    z: cartesian.z,
  }
}