import type { Viewer } from 'cesium';

import * as Cesium from 'cesium';

export function demo_卫星加站点(viewer: Viewer) {
  // 1. 添加一个卫星
  const satellite = viewer.entities.add({
    label: {
      font: '14pt monospace',
      pixelOffset: new Cesium.Cartesian2(0, 20),
      text: '卫星',
    },
    name: '测试卫星',
    point: {
      color: Cesium.Color.RED,
      pixelSize: 10, // 卫星显示为一个点
    },
    position: Cesium.Cartesian3.fromDegrees(114, 40, 500_000), // 经度、纬度、高度（500km）
  });

  // 2. 添加一个地面检测站点
  const detectionSite = viewer.entities.add({
    label: {
      font: '14pt monospace',
      pixelOffset: new Cesium.Cartesian2(0, 20),
      text: '检测站',
    },
    name: '检测站点',
    point: {
      color: Cesium.Color.BLUE,
      pixelSize: 8,
    },
    position: Cesium.Cartesian3.fromDegrees(116, 39, 0), // 北京附近的一个地面站点
  });

  // 3. 可选：绘制卫星与站点之间的连线
  viewer.entities.add({
    polyline: {
      material: Cesium.Color.YELLOW.withAlpha(0.5),
      positions: new Cesium.CallbackProperty(() => {
        const satellitePosition = satellite.position?.getValue(Cesium.JulianDate.now());
        const sitePosition = detectionSite.position?.getValue(Cesium.JulianDate.now());

        if (!satellitePosition || !sitePosition) {
          return [];
        }

        return [satellitePosition, sitePosition];
      }, false),
      width: 2,
    },
  });
}
