Skip to content

Commit 93e1128

Browse files
committed
Integrate with new API, Pulse animation marker
1 parent 40dc950 commit 93e1128

File tree

9 files changed

+115
-97
lines changed

9 files changed

+115
-97
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
![Geo Smart Logo](http://supanadit.com/wp-content/uploads/2019/11/Geo-Smart-Logo.png)
22

33
# GEO Smart Map
4-
This is the Front End Application which the Live Map for [Geo Smart System](https://github.com/supanadit/geosmartsystem)
4+
This is the Front End Application which is the Live Map for [Geo Smart System](https://github.com/supanadit/geosmartsystem)
55

66
## Requirements
77
- NPM

angular.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@
3131
"src/styles.scss",
3232
"node_modules/leaflet/dist/leaflet.css",
3333
"node_modules/bootstrap/dist/css/bootstrap.min.css",
34-
"node_modules/ngx-toastr/toastr.css"
34+
"node_modules/ngx-toastr/toastr.css",
35+
"node_modules/@ansur/leaflet-pulse-icon/dist/L.Icon.Pulse.css"
3536
],
36-
"scripts": []
37+
"scripts": [
38+
"node_modules/leaflet/dist/leaflet.js",
39+
"node_modules/@ansur/leaflet-pulse-icon/dist/L.Icon.Pulse.js"
40+
]
3741
},
3842
"configurations": {
3943
"production": {

package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@angular/platform-browser": "~8.2.11",
2020
"@angular/platform-browser-dynamic": "~8.2.11",
2121
"@angular/router": "~8.2.11",
22+
"@ansur/leaflet-pulse-icon": "^0.1.1",
2223
"@asymmetrik/ngx-leaflet": "^6.0.1",
2324
"bootstrap": "^4.3.1",
2425
"leaflet": "^1.5.1",

src/app/app-routing.module.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { NgModule } from '@angular/core';
2-
import { Routes, RouterModule } from '@angular/router';
1+
import {NgModule} from '@angular/core';
2+
import {Routes, RouterModule} from '@angular/router';
33

44

55
const routes: Routes = [];
66

77
@NgModule({
8-
imports: [RouterModule.forRoot(routes)],
8+
imports: [RouterModule.forRoot(routes, {useHash: true})],
99
exports: [RouterModule]
1010
})
11-
export class AppRoutingModule { }
11+
export class AppRoutingModule {
12+
}

src/app/app.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<div class="map" leaflet [leafletOptions]="options">
2-
<div *ngFor="let x of listMarker" [leafletLayer]="x"></div>
2+
<div *ngFor="let x of listMarker" [leafletLayer]="x"></div>
33
</div>

src/app/app.component.ts

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,41 @@
1-
import { Component, OnInit } from '@angular/core';
2-
import { latLng, Marker, tileLayer } from 'leaflet';
3-
import { AppService } from './app.service';
4-
import { ToastrService } from 'ngx-toastr';
1+
import {Component, OnInit} from '@angular/core';
2+
import {latLng, marker, Marker, tileLayer} from 'leaflet';
3+
import {AppService} from './app.service';
4+
import {ToastrService} from 'ngx-toastr';
5+
6+
declare const L: any;
7+
import '@ansur/leaflet-pulse-icon';
58

69
@Component({
7-
selector: 'app-root',
8-
templateUrl: './app.component.html',
9-
styleUrls: ['./app.component.scss']
10+
selector: 'app-root',
11+
templateUrl: './app.component.html',
12+
styleUrls: ['./app.component.scss']
1013
})
1114
export class AppComponent implements OnInit {
12-
token = 'pk.eyJ1Ijoic3VwYW5hZGl0IiwiYSI6ImNrMmVweWdrcTA4ZzgzY3A1NDE5ZnQwazkifQ.hK2Mz6cFk-jeIHzFBdaKTg';
13-
style = `ck1w9autf0f0r1co76j79eab7`;
15+
token = 'pk.eyJ1Ijoic3VwYW5hZGl0IiwiYSI6ImNrMmVweWdrcTA4ZzgzY3A1NDE5ZnQwazkifQ.hK2Mz6cFk-jeIHzFBdaKTg';
16+
style = `ck1w9autf0f0r1co76j79eab7`;
1417

15-
options = {
16-
layers: [
17-
tileLayer(`https://api.mapbox.com/styles/v1/supanadit/${this.style}/tiles/256/{z}/{x}/{y}@2x?access_token=${this.token}`, {
18-
maxZoom: 18,
19-
})
20-
],
21-
zoom: 12,
22-
center: latLng(-6.914744, 107.609810)
23-
};
18+
options = {
19+
layers: [
20+
tileLayer(`https://api.mapbox.com/styles/v1/supanadit/${this.style}/tiles/256/{z}/{x}/{y}@2x?access_token=${this.token}`, {
21+
maxZoom: 18,
22+
})
23+
],
24+
zoom: 12,
25+
center: latLng(-6.914744, 107.609810)
26+
};
2427

25-
// @ts-ignore
26-
listMarker: Array<Marker> = [];
28+
// @ts-ignore
29+
listMarker: Array<Marker> = [];
2730

28-
// tslint:disable-next-line:variable-name
29-
constructor(private appService: AppService, private toastr: ToastrService) {
30-
}
31+
// tslint:disable-next-line:variable-name
32+
constructor(private appService: AppService, private toastr: ToastrService) {
33+
}
3134

32-
ngOnInit(): void {
33-
this.appService.getStreamUser().subscribe((listMarker: Array<Marker>) => {
34-
this.listMarker = listMarker;
35-
});
36-
}
35+
ngOnInit(): void {
36+
this.appService.getStreamUser().subscribe((listMarker: Array<Marker>) => {
37+
this.listMarker = listMarker;
38+
});
39+
}
3740

3841
}

src/app/app.service.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import { Injectable } from '@angular/core';
2-
import { LocationModel, locationModelFromEventSource, markerListFromLocationModel } from './model/location';
3-
import { Observable } from 'rxjs';
4-
import { environment } from '../environments/environment';
5-
import { Marker } from 'leaflet';
1+
import {Injectable} from '@angular/core';
2+
import {LocationModel, locationModelFromEventSource, markerListFromLocationModel} from './model/location';
3+
import {Observable} from 'rxjs';
4+
import {environment} from '../environments/environment';
5+
import {Marker} from 'leaflet';
66

77
@Injectable({
8-
providedIn: 'root'
8+
providedIn: 'root'
99
})
1010
export class AppService {
11-
constructor() {
11+
constructor() {
1212

13-
}
13+
}
1414

15-
getStreamUser(): Observable<Array<Marker>> {
16-
return new Observable(observer => {
17-
const source = new EventSource(environment.api.concat('/stream?request=sse'));
18-
source.addEventListener('message', message => {
19-
const listLocationModel: Array<LocationModel> = locationModelFromEventSource(message);
20-
observer.next(markerListFromLocationModel(listLocationModel));
21-
});
22-
});
23-
}
15+
getStreamUser(): Observable<Array<Marker>> {
16+
return new Observable(observer => {
17+
const source = new EventSource(environment.api.concat('/point/get/stream'));
18+
source.addEventListener('message', message => {
19+
const listLocationModel: Array<LocationModel> = locationModelFromEventSource(message);
20+
observer.next(markerListFromLocationModel(listLocationModel));
21+
});
22+
});
23+
}
2424
}

src/app/model/location.ts

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,73 @@
1-
import { icon, marker, Marker } from 'leaflet';
1+
import {icon, marker, Marker} from 'leaflet';
2+
3+
declare const L: any;
4+
import '@ansur/leaflet-pulse-icon';
25

36
export interface PointInterface {
4-
type: string;
5-
coordinates: Array<number>;
7+
type: string;
8+
coordinates: Array<number>;
69
}
710

811
export class PointModel implements PointInterface {
9-
coordinates: Array<number>;
10-
type: string;
12+
coordinates: Array<number>;
13+
type: string;
1114

12-
constructor(dataLocation: PointInterface) {
13-
this.coordinates = dataLocation.coordinates;
14-
this.type = dataLocation.type;
15-
}
15+
constructor(dataLocation: PointInterface) {
16+
this.coordinates = dataLocation.coordinates;
17+
this.type = dataLocation.type;
18+
}
1619

17-
Lat(): number {
18-
return this.coordinates[1];
19-
}
20+
Lat(): number {
21+
return this.coordinates[1];
22+
}
2023

21-
Lng(): number {
22-
return this.coordinates[0];
23-
}
24+
Lng(): number {
25+
return this.coordinates[0];
26+
}
2427
}
2528

2629
export interface PointInterface {
27-
coordinates: Array<number>;
30+
coordinates: Array<number>;
2831
}
2932

3033
export interface LocationInterface {
31-
id: string;
32-
object: PointInterface;
34+
id: string;
35+
object: PointInterface;
3336
}
3437

3538
export class LocationModel implements LocationInterface {
36-
id: string;
37-
object: PointInterface;
39+
id: string;
40+
object: PointInterface;
3841

39-
constructor(location: LocationInterface) {
40-
this.id = location.id;
41-
this.object = location.object;
42-
}
42+
constructor(location: LocationInterface) {
43+
this.id = location.id;
44+
this.object = location.object;
45+
}
4346

44-
Point(): PointModel {
45-
return new PointModel(this.object);
46-
}
47+
Point(): PointModel {
48+
return new PointModel(this.object);
49+
}
4750

48-
Marker(): Marker {
49-
return marker([this.Point().Lat(), this.Point().Lng()], {
50-
icon: icon({
51-
iconSize: [20, 20],
52-
iconUrl: 'assets/markers/red.png',
53-
}),
54-
});
55-
}
51+
Marker(): Marker {
52+
const pulseMarker = L.icon.pulse({iconSize: [6, 6], color: 'red'});
53+
return marker([this.Point().Lat(), this.Point().Lng()], {
54+
icon: pulseMarker,
55+
});
56+
}
5657
}
5758

5859
export function locationModelFromEventSource(listener: any): Array<LocationModel> {
59-
const data = JSON.parse(listener.data);
60-
let locationModelList: Array<LocationModel> = [];
61-
if (data != null) {
62-
const listData: Array<any> = data.data;
63-
if (listData != null) {
64-
locationModelList = listData.map<LocationModel>((x: LocationInterface) => new LocationModel(x));
65-
}
60+
const data = JSON.parse(listener.data);
61+
let locationModelList: Array<LocationModel> = [];
62+
if (data != null) {
63+
const listData: Array<any> = data.data;
64+
if (listData != null) {
65+
locationModelList = listData.map<LocationModel>((x: LocationInterface) => new LocationModel(x));
6666
}
67-
return locationModelList;
67+
}
68+
return locationModelList;
6869
}
6970

7071
export function markerListFromLocationModel(listLocationModel: Array<LocationModel>): Array<Marker> {
71-
return listLocationModel.map<Marker>((x: LocationModel) => x.Marker());
72+
return listLocationModel.map<Marker>((x: LocationModel) => x.Marker());
7273
}

0 commit comments

Comments
 (0)