2017-11-27 16:56:09 +00:00
import { Component , OnInit , AfterViewInit , Input , Output , EventEmitter , ViewChild , TemplateRef } from '@angular/core' ;
2017-11-14 12:47:28 +00:00
import { ApiService } from '../providers/api-service' ;
import { AgmCoreModule } from '@agm/core' ;
2017-11-27 17:20:22 +00:00
import { BsModalService , ModalDirective } from 'ngx-bootstrap/modal' ;
2017-11-23 17:16:46 +00:00
import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service' ;
2017-11-14 12:47:28 +00:00
import 'rxjs/add/operator/map' ;
@Component ( {
2017-11-14 17:12:07 +00:00
templateUrl : 'trail-map.component.html' ,
2017-11-14 12:47:28 +00:00
} )
2017-11-27 16:56:09 +00:00
export class TrailMapComponent implements OnInit , AfterViewInit {
@ViewChild ( 'statusModal' ) myStatusModal : ModalDirective ;
2017-11-14 12:47:28 +00:00
lat : number = 54.0466 ;
lng : number = - 2.8007 ;
zoom : number = 12 ;
2017-11-23 17:16:46 +00:00
public modalRef : BsModalRef ;
clickedMarker : any ;
2017-11-14 12:47:28 +00:00
2017-11-27 16:56:09 +00:00
dataReceived : string = 'loading' ;
2017-11-14 12:47:28 +00:00
markers : Array < { latitude : number , longitude : number , name : string } > ;
map : any ;
constructor (
private api : ApiService ,
2017-11-23 17:16:46 +00:00
private modalService : BsModalService ,
) { }
2017-11-14 12:47:28 +00:00
ngOnInit ( ) : void { }
2017-11-27 16:56:09 +00:00
ngAfterViewInit() {
this . myStatusModal . show ( ) ;
}
2017-11-14 12:47:28 +00:00
public onMapReady ( map : any ) {
this . map = map ;
}
2017-11-23 17:16:46 +00:00
openModal ( template : TemplateRef < any > ) {
this . modalRef = this . modalService . show ( template ) ;
}
public onMarkerClick ( clickedMarker , template : TemplateRef < any > ) {
console . log ( clickedMarker ) ;
this . clickedMarker = clickedMarker ;
this . openModal ( template ) ;
}
2017-11-14 12:47:28 +00:00
public viewBoundsChanged() {
console . log ( "finding bounds" ) ;
const resp = this . map . getBounds ( ) ;
console . log ( "found bounds" ) ;
console . log ( resp . getNorthEast ( ) . lat ( ) ) ;
console . log ( resp . getNorthEast ( ) . lng ( ) ) ;
console . log ( resp . getSouthWest ( ) . lat ( ) ) ;
console . log ( resp . getSouthWest ( ) . lng ( ) ) ;
const mapData = {
north_east : {
latitude : resp.getNorthEast ( ) . lat ( ) ,
longitude : resp.getNorthEast ( ) . lng ( )
} ,
south_west : {
latitude : resp.getSouthWest ( ) . lat ( ) ,
longitude : resp.getSouthWest ( ) . lng ( )
} ,
}
2017-11-23 17:16:46 +00:00
this . api . getLisData ( mapData ) . subscribe (
2017-11-14 12:47:28 +00:00
result = > {
2017-11-27 16:56:09 +00:00
this . myStatusModal . hide ( ) ;
2017-11-23 17:16:46 +00:00
this . markers = result . locations ;
2017-11-14 12:47:28 +00:00
} ,
error = > {
2017-11-23 17:16:46 +00:00
this . dataReceived = 'no' ;
2017-11-14 12:47:28 +00:00
console . log ( 'Retrieval Error' ) ;
console . log ( error . _body ) ;
}
) ;
}
}