Blame view

src/services/road.service.ts 1.55 KB
ad296a58   Yarik   Road
1
2
3
4
5
6
  import { Injectable } from '@angular/core';
  import { Http } from '@angular/http';
  
  import { StatementBaseService } from './statement.base.service';
  
  import { Road } from '../models/road';
dc9a0e3c   Yarik   Road fatality
7
8
9
  import {Way} from "../models/way";
  import {Node} from "../models/node";
  import {id} from "@swimlane/ngx-charts/release/utils/id";
ad296a58   Yarik   Road
10
11
12
13
14
15
16
17
18
19
  
  @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();
    }
dc9a0e3c   Yarik   Road fatality
20
21
22
23
24
25
    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);
    }
ad296a58   Yarik   Road
26
    protected parseModels(json: any): any[] {
366f081e   Yarik   Filters
27
       return json.roadEditDsM as Road[];
ad296a58   Yarik   Road
28
29
30
31
    };
    protected parseModel(json: any): any {
       return json as Road;
    };
dc9a0e3c   Yarik   Road fatality
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
    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;
    }
ad296a58   Yarik   Road
51
  }