2017-11-27 16:56:09 +00:00
import { Component , OnInit , AfterViewInit , Input , Output , EventEmitter , ViewChild , TemplateRef } from '@angular/core' ;
2017-09-26 17:31:40 +01:00
import { ApiService } from '../providers/api-service' ;
import { AgmCoreModule } from '@agm/core' ;
2017-11-27 16:56:09 +00:00
import { BsModalService , ModalDirective } from 'ngx-bootstrap/modal' ;
import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service' ;
2018-06-04 15:23:16 +01:00
2017-09-26 17:31:40 +01:00
@Component ( {
templateUrl : 'map.component.html' ,
} )
2017-11-27 16:56:09 +00:00
export class MapComponent implements OnInit , AfterViewInit {
@ViewChild ( 'statusModal' ) myStatusModal : ModalDirective ;
2017-09-26 17:31:40 +01:00
lat : number = 54.0466 ;
2017-09-26 17:51:14 +01:00
lng : number = - 2.8007 ;
2017-09-27 12:02:46 +01:00
zoom : number = 12 ;
2017-11-27 16:56:09 +00:00
public modalRef : BsModalRef ;
clickedMarker : any ;
2017-09-26 17:31:40 +01:00
2017-11-27 16:56:09 +00:00
dataReceived : string = 'loading' ;
2017-09-27 13:54:10 +01:00
2017-09-27 17:46:25 +01:00
markers : Array < { latitude : number , longitude : number , name : string } > ;
2017-09-27 14:34:46 +01:00
2017-09-27 13:54:10 +01:00
map : any ;
2017-09-26 17:31:40 +01:00
constructor (
private api : ApiService ,
2017-11-27 16:56:09 +00:00
private modalService : BsModalService ,
2017-09-26 17:31:40 +01:00
) { }
2017-09-27 13:54:10 +01:00
ngOnInit ( ) : void { }
2017-11-27 16:56:09 +00:00
ngAfterViewInit() {
this . myStatusModal . show ( ) ;
}
2017-09-27 13:54:10 +01:00
public onMapReady ( map : any ) {
this . map = map ;
}
2017-09-26 17:31:40 +01:00
2017-11-27 16:56:09 +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-09-27 13:54:10 +01: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 = {
2017-09-27 17:46:25 +01:00
north_east : {
latitude : resp.getNorthEast ( ) . lat ( ) ,
longitude : resp.getNorthEast ( ) . lng ( )
} ,
south_west : {
latitude : resp.getSouthWest ( ) . lat ( ) ,
longitude : resp.getSouthWest ( ) . lng ( )
} ,
}
2017-09-27 13:54:10 +01:00
this . api . getMapData ( mapData ) . subscribe (
result = > {
2017-11-27 16:56:09 +00:00
this . myStatusModal . hide ( ) ;
2017-09-27 17:46:25 +01:00
this . markers = result . suppliers ;
2017-09-27 13:54:10 +01:00
} ,
error = > {
2017-11-23 17:16:46 +00:00
this . dataReceived = 'no' ;
2017-09-27 13:54:10 +01:00
console . log ( 'Retrieval Error' ) ;
console . log ( error . _body ) ;
}
) ;
2017-09-26 17:31:40 +01:00
}
2017-09-27 13:54:10 +01:00
2017-09-26 17:31:40 +01:00
}