road.service.ts
2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import {Injectable} from '@angular/core';
import {Http} from '@angular/http';
import {StatementBaseService} from './statement.base.service';
import {Road} from '../models/road';
import {Way} from "../models/way";
import {Node} from "../models/node";
import {id} from "@swimlane/ngx-charts/release/utils/id";
@Injectable()
export class RoadService extends StatementBaseService {
protected url: string = 'http://localhost:5000/road';
constructor(protected http: Http) {
super(http);
}
public createModel(): Object {
return new Road();
}
public getRelation(id: number): Promise<any> {
return this.http.get(this.url + '/relation?id=' + id, {headers: this.headers})
.toPromise()
.then(x => this.decodeWays(x.json()))
.catch(this.handleError);
}
public getRoadByWay(id: number): Promise<any> {
return this.http.get(this.url + '/roadbyway?id=' + id, {headers: this.headers})
.toPromise()
.then(x => this.parseModel(x.json()))
.catch(this.handleError);
};
public getRoadByNode(id: number): Promise<any> {
return this.http.get(this.url + '/roadbynode?id=' + id, {headers: this.headers})
.toPromise()
.then(x => this.parseModel(x.json()))
.catch(this.handleError);
};
protected parseModels(json: any): any[] {
return json.roadEditDsM as Road[];
};
protected parseModel(json: any): any {
return json as Road;
};
protected decodeWays(json: Object[]): Way[] {
let result: Way[] = [];
json.forEach((way: Way) => {
let nodes: Node[] = [];
way.nodes.forEach((node: Node) => {
let nodeObj: Node = new Node();
nodeObj.id = node.id;
nodeObj.index = node.index;
nodeObj.lat = node.lat;
nodeObj.lon = node.lon;
nodes.push(nodeObj);
});
let wayObj: Way = new Way();
wayObj.id = way.id;
wayObj.nodes = nodes;
result.push(wayObj);
});
return result;
}
}