Files
maptology/web/angular/src/app/location.service.ts
T

46 lines
1.6 KiB
TypeScript
Executable File

import { Injectable } from '@angular/core';
import { LatLng } from 'leaflet';
import { ApiClientService } from '../api/index';
import { ConsoleService } from './console.service';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { HttpErrorResponse } from '@angular/common/http';
import { Location } from '../api/models/location.model';
import {HelperService} from "./Utils/helper.service";
@Injectable()
export class LocationService {
randomLocations: LatLng[] = [
new LatLng(51.45165788, 7.00388614),
new LatLng(51.46000194, 7.01869371),
new LatLng(51.45517929, 7.02048384),
new LatLng(51.45978196, 7.01042728),
new LatLng(51.46385009, 7.01619635),
new LatLng(51.44816853, 7.01816195),
new LatLng(51.45525145, 7.00986632),
new LatLng(51.45425852, 7.01005042)
];
location: BehaviorSubject<Location> = new BehaviorSubject<Location>(null);
error: BehaviorSubject<string> = new BehaviorSubject<string>(null);
constructor(private consoleService: ConsoleService,
private apiClientService: ApiClientService,
private helperService:HelperService) { }
getLocation(shareId: string): void {
this.apiClientService.getShareLocation(shareId).subscribe(result => {
this.location.next(result.body);
}, error => {
this.consoleService.log(`Error finding the share with id ${shareId}.`);
this.helperService.handleError(error);
});
}
resetLocation() {
this.consoleService.log('LocationService reset');
this.location = new BehaviorSubject<Location>(null);
this.error = new BehaviorSubject<string>(null);
}
}