import { Component, OnInit } from '@angular/core';
import { ViewerService } from 'src/app/services';

@Component({
  selector: 'app-skyline',
  templateUrl: './skyline.component.html',
  styleUrls: ['./skyline.component.css']
})
export class SkylineComponent implements OnInit {

  public showSkyline = false;
  private skyline;
  private oldDepthTestAgainstTerrainValue: boolean;

  constructor(
    private viewerService: ViewerService,
  ) { }

  ngOnInit() {
  }

  toggleSkyline() {
    this.showSkyline = !this.showSkyline;
    const viewer = this.viewerService.viewer;

    if (this.showSkyline) {
      // 需要开启 depthTestAgainstTerrain，天际线才会围住地形，否则会围住 globe
      this.oldDepthTestAgainstTerrainValue = viewer.scene.globe.depthTestAgainstTerrain;
      viewer.scene.globe.depthTestAgainstTerrain = true;
      this.skyline = new smart3d.SkyLine(viewer, {
        // width: 10,
        // lineColor: Cesium.Color.GREEN,
        // strokeDis: 1e9,
      });
    } else {
      this.skyline.destroy();
      viewer.scene.globe.depthTestAgainstTerrain = this.oldDepthTestAgainstTerrainValue;
    }
  }

}
