This repository has been archived on 2023-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
FoodLoop-Web/src/app/dashboard/map.component.ts

67 lines
1.6 KiB
TypeScript
Raw Normal View History

2017-09-27 12:54:10 +00:00
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
2017-09-26 16:31:40 +00:00
import { Http, Response } from '@angular/http';
import { ApiService } from '../providers/api-service';
import { AgmCoreModule } from '@agm/core';
import 'rxjs/add/operator/map';
@Component({
templateUrl: 'map.component.html',
})
export class MapComponent implements OnInit {
lat: number = 54.0466;
2017-09-26 16:51:14 +00:00
lng: number = -2.8007;
2017-09-27 11:02:46 +00:00
zoom: number = 12;
2017-09-26 16:31:40 +00:00
2017-09-27 12:54:10 +00:00
dataReceived: string = 'yes';
2017-09-27 16:46:25 +00:00
markers: Array<{latitude: number, longitude: number, name: string}>;
2017-09-27 13:34:46 +00:00
2017-09-27 12:54:10 +00:00
map: any;
2017-09-26 16:31:40 +00:00
constructor(
private http: Http,
private api: ApiService,
) { }
2017-09-27 12:54:10 +00:00
ngOnInit(): void { }
public onMapReady(map: any) {
this.map = map;
}
2017-09-26 16:31:40 +00:00
2017-09-27 12:54:10 +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 = {
2017-09-27 16:46:25 +00:00
north_east: {
latitude: resp.getNorthEast().lat(),
longitude: resp.getNorthEast().lng()
},
south_west: {
latitude: resp.getSouthWest().lat(),
longitude: resp.getSouthWest().lng()
},
}
2017-09-27 12:54:10 +00:00
this.api.getMapData(mapData).subscribe(
result => {
this.dataReceived = 'yes';
2017-09-27 16:46:25 +00:00
this.markers = result.suppliers;
2017-09-27 12:54:10 +00:00
},
error => {
// this.dataReceived = 'no';
console.log('Retrieval Error');
console.log( error._body );
}
);
2017-09-26 16:31:40 +00:00
}
2017-09-27 12:54:10 +00:00
2017-09-26 16:31:40 +00:00
}