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

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

  constructor(
    private viewerService: ViewerService,
  ) { }

  ngOnInit() {
  }

  handleSightLine() {
    const viewer = this.viewerService.viewer;
    const drawHandler = new smart3d.DrawHandler(viewer, smart3d.DrawMode.Line);
    const positions = [];
    drawHandler.anchorEvent.addEventListener(position => {
      if (positions.push(position) >= 2) {
        const sightLine = new smart3d.SightLine(viewer.scene, positions[0], positions[1]);
        drawHandler.clear();
        drawHandler.destroy();
        sightLine.build();
      }
    });
    drawHandler.activate();
  }
}
