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

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

  private pick;

  constructor(
    private viewerService: ViewerService,
  ) { }

  ngOnInit() {
  }

  handlePick(type: 'highlight' | 'offset' | 'transparent') {
    const viewer = this.viewerService.viewer;
    if (undefined !== this.pick) {
      this.pick.destroy();
    }

    this.pick = new smart3d.Pick(viewer, smart3d.PickMode[type.toUpperCase()]);
    this.pick.start();
    this.pick.clickEvent.addEventListener((pickedObject, cartesian) => {
      const degreesCartographic = this.viewerService.cartesianToDegreesCartographic(cartesian);
      alert('拾取到的坐标：(' + degreesCartographic.longitude + ', ' + degreesCartographic.latitude + ', ' + degreesCartographic.height + ')');
    });
  }

  clearPick() {
    if (undefined !== this.pick) {
      this.pick.clear();
    }
  }

  destroyPick() {
    if (undefined !== this.pick) {
      this.pick.destroy();
    }
  }
}
