Skip to content
This repository was archived by the owner on Apr 3, 2026. It is now read-only.

Commit 43aa4c7

Browse files
committed
[refactor] add render example
1 parent 7d31523 commit 43aa4c7

5 files changed

Lines changed: 1890 additions & 62 deletions

File tree

playground/src/app/app.component.html

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
<agm-direction
33
[origin]="origin"
44
[destination]="destination"
5-
[waypoints]="waypoints"
6-
[renderOptions]="renderOptions"
7-
[markerOptions]="markerOptions"
8-
[visible]="visible"
9-
(onChange)="onChange($event)"
5+
[renderRoute]="renderRoute"
106
(onResponse)="onResponse($event)"
117
>
128
</agm-direction>
139
</agm-map>
1410

15-
<button type="button" (click)="hide()">Hide</button>
11+
<button type="button" (click)="renderfromData(1)">Render1</button>
12+
<button type="button" (click)="renderfromData(2)">Render2</button>
13+
<button type="button" (click)="renderNew()">RenderNew</button>
Lines changed: 32 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,53 @@
1-
import { Component } from '@angular/core';
1+
import { Component, OnInit } from '@angular/core';
2+
import { Http } from '@angular/http';
23

34
@Component({
45
selector: 'app-root',
56
templateUrl: './app.component.html',
67
styleUrls: ['./app.component.scss']
78
})
8-
export class AppComponent {
9+
export class AppComponent implements OnInit {
910

1011
public lat: Number = 24.799448;
1112
public lng: Number = 120.979021;
1213

13-
public origin: any = '大潤發新竹湳雅店';
14-
public destination: any = '國立新竹高級中學';
14+
public origin: any = 'Taichung Main Station';
15+
public destination: any = 'Taichung City Government';
1516

16-
public waypoints: object = [
17-
{
18-
location: '國立新竹高級商業職業學校',
19-
stopover: false,
20-
},
21-
{
22-
location: '新竹市立建功高級中學',
23-
stopover: false,
24-
},
25-
];
17+
public renderRoute: object = null;
2618

27-
public renderOptions = {
28-
suppressMarkers: true,
29-
};
19+
public dir = [];
20+
public datas = [];
3021

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+
}
6526

66-
public onChange(event: any) {
67-
console.log('onChange', event);
27+
async ngOnInit() {
28+
// setTimeout(() => this.direction2(), 300);
6829
}
6930

31+
// private direction2() {
32+
// this.origin = 'Taichung University of Science and Technology';
33+
// this.destination = 'Taichung Main Station';
34+
// }
35+
7036
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];
7246
}
7347

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;
7652
}
7753
}

playground/src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { BrowserModule } from '@angular/platform-browser';
22
import { NgModule } from '@angular/core';
3+
import { HttpModule } from '@angular/http';
34

45
import { AppComponent } from './app.component';
56

@@ -12,6 +13,7 @@ import { AgmDirectionModule } from '../../../dist';
1213
],
1314
imports: [
1415
BrowserModule,
16+
HttpModule,
1517
AgmCoreModule.forRoot({
1618
apiKey: '',
1719
}),

0 commit comments

Comments
 (0)