|
1 | | -import { Component } from '@angular/core'; |
| 1 | +import { Component, OnInit } from '@angular/core'; |
| 2 | +import { Http } from '@angular/http'; |
2 | 3 |
|
3 | 4 | @Component({ |
4 | 5 | selector: 'app-root', |
5 | 6 | templateUrl: './app.component.html', |
6 | 7 | styleUrls: ['./app.component.scss'] |
7 | 8 | }) |
8 | | -export class AppComponent { |
| 9 | +export class AppComponent implements OnInit { |
9 | 10 |
|
10 | 11 | public lat: Number = 24.799448; |
11 | 12 | public lng: Number = 120.979021; |
12 | 13 |
|
13 | | - public origin: any = '大潤發新竹湳雅店'; |
14 | | - public destination: any = '國立新竹高級中學'; |
| 14 | + public origin: any = 'Taichung Main Station'; |
| 15 | + public destination: any = 'Taichung City Government'; |
15 | 16 |
|
16 | | - public waypoints: object = [ |
17 | | - { |
18 | | - location: '國立新竹高級商業職業學校', |
19 | | - stopover: false, |
20 | | - }, |
21 | | - { |
22 | | - location: '新竹市立建功高級中學', |
23 | | - stopover: false, |
24 | | - }, |
25 | | - ]; |
| 17 | + public renderRoute: object = null; |
26 | 18 |
|
27 | | - public renderOptions = { |
28 | | - suppressMarkers: true, |
29 | | - }; |
| 19 | + public dir = []; |
| 20 | + public datas = []; |
30 | 21 |
|
31 | | - public markerOptions = { |
32 | | - origin: { |
33 | | - icon: 'https://i.imgur.com/7teZKif.png', |
34 | | - infoWindow: ` |
35 | | - <h4>origin<h4> |
36 | | - <a href='http://www-e.ntust.edu.tw/home.php' target='_blank'>Taiwan Tech</a> |
37 | | - `, |
38 | | - }, |
39 | | - destination: { |
40 | | - icon: 'https://i.imgur.com/7teZKif.png', |
41 | | - infoWindow: ` |
42 | | - <h4>destination<h4> |
43 | | - <a href='http://www-e.ntust.edu.tw/home.php' target='_blank'>Taiwan Tech</a> |
44 | | - `, |
45 | | - }, |
46 | | - waypoints: [ |
47 | | - { |
48 | | - icon: 'https://i.imgur.com/7teZKif.png', |
49 | | - infoWindow: ` |
50 | | - <h4>waypoints111<h4> |
51 | | - <a href='http://www-e.ntust.edu.tw/home.php' target='_blank'>Taiwan Tech</a> |
52 | | - `, |
53 | | - }, |
54 | | - { |
55 | | - icon: 'https://i.imgur.com/7teZKif.png', |
56 | | - infoWindow: ` |
57 | | - <h4>waypoints222<h4> |
58 | | - <a href='http://www-e.ntust.edu.tw/home.php' target='_blank'>Taiwan Tech</a> |
59 | | - `, |
60 | | - }, |
61 | | - ], |
62 | | - }; |
63 | | - |
64 | | - public visible: Boolean = true; |
| 22 | + constructor(private http: Http) { |
| 23 | + this.http.get('assets/data1.json').subscribe(result => { this.datas.push(result.json()); }); |
| 24 | + this.http.get('assets/data2.json').subscribe(result => { this.datas.push(result.json()); }); |
| 25 | + } |
65 | 26 |
|
66 | | - public onChange(event: any) { |
67 | | - console.log('onChange', event); |
| 27 | + async ngOnInit() { |
| 28 | + // setTimeout(() => this.direction2(), 300); |
68 | 29 | } |
69 | 30 |
|
| 31 | + // private direction2() { |
| 32 | + // this.origin = 'Taichung University of Science and Technology'; |
| 33 | + // this.destination = 'Taichung Main Station'; |
| 34 | + // } |
| 35 | + |
70 | 36 | public onResponse(event: any) { |
71 | | - console.log('onResponse', event); |
| 37 | + this.dir.push(event); |
| 38 | + } |
| 39 | + |
| 40 | + public renderfromData(index: number) { |
| 41 | + // Render from memory |
| 42 | + // this.renderRoute = this.dir[index]; |
| 43 | + |
| 44 | + // Render from json file (build from direction response) |
| 45 | + this.renderRoute = this.datas[index - 1]; |
72 | 46 | } |
73 | 47 |
|
74 | | - public hide() { |
75 | | - this.visible = !this.visible; |
| 48 | + public renderNew() { |
| 49 | + this.origin = 'Taichung Main Station'; |
| 50 | + this.destination = 'Taichung University of Science and Technology'; |
| 51 | + this.renderRoute = null; |
76 | 52 | } |
77 | 53 | } |
0 commit comments