Skip to content

Commit 0d16436

Browse files
committed
Add shelter info
1 parent cf0da13 commit 0d16436

File tree

9 files changed

+296
-17
lines changed

9 files changed

+296
-17
lines changed

client/src/app/_services/shelters.service.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,24 @@ export class SheltersService {
6161
);
6262
}
6363

64-
// public getHospitalDetails(lngLat, distance): Observable<any> {
65-
// return this.http.get(
66-
// `https://dev.virtualearth.net/REST/v1/LocalSearch/`,
67-
// {
68-
// params: {
69-
// 'query': 'hospital',
70-
// 'userLocation': lngLat,
71-
// 'key': environment.bingMapsAPIKey
72-
// }
73-
// }
74-
// );
75-
// }
64+
public getShelterInfo(id): Observable<any> {
65+
return this.http.get(
66+
`${this.apiBaseUrl}/shelters/${id}`
67+
);
68+
}
69+
70+
public getNearbyPlaces(lngLat, radius, type): Observable<any> {
71+
return this.http.get(
72+
`https://cors-anywhere.herokuapp.com/https://maps.googleapis.com/maps/api/place/nearbysearch/json`,
73+
{
74+
params: {
75+
'type': type,
76+
'location': lngLat.split(",").reverse().join(","),
77+
'key': environment.googleMapsAPIKey,
78+
'radius': radius
79+
}
80+
}
81+
);
82+
}
7683
}
84+
https://maps.googleapis.com/maps/api/place/nearbysearch/json?key=AIzaSyDoaA5lB4-JbSXElDWllnNU3QcArgxdreM&location=19.1334302,72.91326789999994&radius=5000&type=gas_station

client/src/app/request-shelter/request-shelter.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ export class RequestShelterComponent implements AfterViewInit, OnInit {
2626
}
2727

2828
ngAfterViewInit() {
29-
console.log(this.requestCoordinates);
3029
Object.getOwnPropertyDescriptor(mapboxgl, "accessToken").set(this.mapboxAccessToken);
3130

3231
var map = new mapboxgl.Map({
3332
container: 'map',
34-
style: 'mapbox://styles/mapbox/navigation-guidance-night-v4',
33+
style: 'mapbox://styles/mapbox/nsatellite-streets-v10',
3534
center: [72.914294, 19.130722],
3635
zoom: 12
3736
});

client/src/app/shelters/shelter-card/shelter-card.component.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
<p class="subtitle">
1414
{{ shelter.contact }}
1515
</p>
16-
<pre>{{shelter | json}}</pre>
17-
<a routerLink="/{{shelter._id}}" class="button is-outlined is-info">Click here for more info</a>
16+
<a routerLink="{{shelter._id}}" class="button is-outlined is-info">Click here for more info</a>
1817
</div>
1918
<div class="column is-4">
2019
<div class="content">
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.shelter-info-container {
2+
display: flex;
3+
min-height: 100vh;
4+
flex-direction: column;
5+
}
6+
7+
#map {
8+
width: 100%;
9+
height: 40vh;
10+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<div class="shelter-info-container">
2+
<div id="map"></div>
3+
<div class="section">
4+
<div class="columns">
5+
<div class="column">
6+
<div class="card">
7+
<div class="card-content">
8+
<div class="columns">
9+
<div class="column is-4">
10+
<p class="title">
11+
{{ shelter.name }}
12+
</p>
13+
<p class="subtitle">
14+
{{ shelter.contact }}
15+
</p>
16+
</div>
17+
<div class="column is-4">
18+
<div class="content">
19+
<span class="has-text-info">Address:</span> {{shelter.address}}
20+
<br>
21+
<span class="has-text-info">City:</span> {{shelter.city}}
22+
<br>
23+
<span class="has-text-info">State:</span> {{shelter.state}}
24+
<br><br>
25+
</div>
26+
</div>
27+
</div>
28+
<div class="columns has-text-centered">
29+
<div class="column">
30+
<div class="content">
31+
<h2>Nearby Places</h2>
32+
</div>
33+
</div>
34+
</div>
35+
<div class="columns is-multiline">
36+
<div class="column is-4">
37+
<div class="content">
38+
<h4>Hospitals</h4>
39+
<ul class="has-text-grey">
40+
<li *ngFor="let hospital of nearByHospitals">
41+
{{hospital.name}}, &nbsp;<span class="has-text-weight-bold">{{distance(hospital)}} kms</span>
42+
</li>
43+
</ul>
44+
</div>
45+
</div>
46+
<div class="column is-4">
47+
<div class="content">
48+
<h4>ATMs</h4>
49+
<ul class="has-text-grey">
50+
<li *ngFor="let atm of nearByAtms">
51+
{{atm.name}}, &nbsp;<span class="has-text-weight-bold">{{distance(atm)}} kms</span>
52+
</li>
53+
</ul>
54+
</div>
55+
</div>
56+
<div class="column is-4">
57+
<div class="content">
58+
<h4>Airports</h4>
59+
<ul class="has-text-grey">
60+
<li *ngFor="let airport of nearByAirports">
61+
{{airport.name}}, &nbsp;<span class="has-text-weight-bold">{{distance(airport)}} kms</span>
62+
</li>
63+
</ul>
64+
</div>
65+
</div>
66+
<div class="column is-4">
67+
<div class="content">
68+
<h4>Train Stations</h4>
69+
<ul class="has-text-grey">
70+
<li *ngFor="let trainStation of nearByTrainStations">
71+
{{trainStation.name}}, &nbsp;<span class="has-text-weight-bold">{{distance(trainStation)}} kms</span>
72+
</li>
73+
</ul>
74+
</div>
75+
</div>
76+
<div class="column is-4">
77+
<div class="content">
78+
<h4>Police Stations</h4>
79+
<ul class="has-text-grey">
80+
<li *ngFor="let policeStation of nearByPoliceStations">
81+
{{policeStation.name}}, &nbsp;<span class="has-text-weight-bold">{{distance(policeStation)}} kms</span>
82+
</li>
83+
</ul>
84+
</div>
85+
</div>
86+
<div class="column is-4">
87+
<div class="content">
88+
<h4>Fire Stations</h4>
89+
<ul class="has-text-grey">
90+
<li *ngFor="let fireStation of nearByFireStations">
91+
{{fireStation.name}}, &nbsp;<span class="has-text-weight-bold">{{distance(fireStation)}} kms</span>
92+
</li>
93+
</ul>
94+
</div>
95+
</div>
96+
</div>
97+
</div>
98+
</div>
99+
</div>
100+
</div>
101+
102+
</div>
103+
</div>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { ShelterInfoComponent } from './shelter-info.component';
4+
5+
describe('ShelterInfoComponent', () => {
6+
let component: ShelterInfoComponent;
7+
let fixture: ComponentFixture<ShelterInfoComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ ShelterInfoComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(ShelterInfoComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import { ActivatedRoute } from '@angular/router';
3+
import * as mapboxgl from 'mapbox-gl';
4+
import * as MapboxGeocoder from '@mapbox/mapbox-gl-geocoder';
5+
import { environment } from 'src/environments/environment';
6+
import { SheltersService } from 'src/app/_services/shelters.service';
7+
import { Shelter } from '../shelter';
8+
import { AlertService } from 'src/app/_services/alert.service';
9+
10+
@Component({
11+
selector: 'app-shelter-info',
12+
templateUrl: './shelter-info.component.html',
13+
styleUrls: ['./shelter-info.component.css']
14+
})
15+
export class ShelterInfoComponent implements OnInit {
16+
17+
mapboxAccessToken = environment.mapboxAccessToken;
18+
shelter: Shelter;
19+
nearByHospitals = [];
20+
nearByAtms = [];
21+
nearByAirports = [];
22+
nearByPoliceStations = [];
23+
nearByTrainStations = [];
24+
nearByFireStations = [];
25+
26+
shelterLng: any;
27+
shelterLat: any;
28+
29+
constructor(
30+
private route: ActivatedRoute,
31+
private shelterService: SheltersService,
32+
private alertService: AlertService
33+
) { }
34+
35+
distance(place) {
36+
const unit = 'K';
37+
const lon1 = place.geometry.location.lng;
38+
const lat1 = place.geometry.location.lat;
39+
const lon2 = +this.shelter.lngLat.split(",")[0];
40+
const lat2 = +this.shelter.lngLat.split(",")[1];
41+
42+
if ((lat1 == lat2) && (lon1 == lon2)) {
43+
return 0;
44+
}
45+
else {
46+
var radlat1 = Math.PI * lat1 / 180;
47+
var radlat2 = Math.PI * lat2 / 180;
48+
var theta = lon1 - lon2;
49+
var radtheta = Math.PI * theta / 180;
50+
var dist = Math.sin(radlat1) * Math.sin(radlat2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta);
51+
if (dist > 1) {
52+
dist = 1;
53+
}
54+
dist = Math.acos(dist);
55+
dist = dist * 180 / Math.PI;
56+
dist = dist * 60 * 1.1515;
57+
if (unit == "K") { dist = dist * 1.609344 }
58+
if (unit == "N") { dist = dist * 0.8684 }
59+
return dist.toFixed(2);
60+
}
61+
}
62+
63+
ngOnInit() {
64+
const shelterId = this.route.snapshot.paramMap.get('id');
65+
66+
this.shelterService.getShelterInfo(shelterId)
67+
.subscribe(
68+
(res) => {
69+
this.shelter = res;
70+
71+
Object.getOwnPropertyDescriptor(mapboxgl, "accessToken").set(this.mapboxAccessToken);
72+
73+
var map = new mapboxgl.Map({
74+
container: 'map',
75+
style: 'mapbox://styles/mapbox/satellite-streets-v10',
76+
center: this.shelter.lngLat.split(","),
77+
zoom: 12
78+
});
79+
80+
this.shelterService.getNearbyPlaces(this.shelter.lngLat, 5000, 'hospital')
81+
.subscribe(
82+
(res) => this.nearByHospitals = res.results,
83+
this.alertService.error
84+
);
85+
this.shelterService.getNearbyPlaces(this.shelter.lngLat, 5000, 'atm')
86+
.subscribe(
87+
(res) => {
88+
this.nearByAtms = res.results;
89+
},
90+
this.alertService.error
91+
);
92+
this.shelterService.getNearbyPlaces(this.shelter.lngLat, 5000, 'airport')
93+
.subscribe(
94+
(res) => this.nearByAirports = res.results,
95+
this.alertService.error
96+
);
97+
this.shelterService.getNearbyPlaces(this.shelter.lngLat, 5000, 'police')
98+
.subscribe(
99+
(res) => this.nearByPoliceStations = res.results,
100+
this.alertService.error
101+
);
102+
this.shelterService.getNearbyPlaces(this.shelter.lngLat, 5000, 'train_station')
103+
.subscribe(
104+
(res) => this.nearByTrainStations = res.results,
105+
this.alertService.error
106+
);
107+
this.shelterService.getNearbyPlaces(this.shelter.lngLat, 5000, 'fire_station')
108+
.subscribe(
109+
(res) => this.nearByFireStations = res.results,
110+
this.alertService.error
111+
);
112+
},
113+
(err) => this.alertService.error(err)
114+
);
115+
116+
}
117+
118+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const Shelter = require('../model/Shelter')
2+
const User = require('../../users/model/User')
3+
var ObjectId = require('mongoose').Types.ObjectId;
4+
5+
module.exports = {
6+
method: 'GET',
7+
path: '/api/shelters/{id}',
8+
options: {
9+
handler: async (request, h) => {
10+
const shelter = await Shelter.findOne({_id: new ObjectId(request.params.id)}).lean()
11+
12+
return shelter;
13+
},
14+
description: 'Returns requested shelter info'
15+
}
16+
}

server/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
},
2828
"devDependencies": {},
2929
"scripts": {
30-
"test": "echo \"Error: no test specified\" && exit 1"
30+
"test": "echo \"Error: no test specified\" && exit 1",
31+
"start": "node app.js"
3132
},
3233
"author": "",
3334
"license": "ISC"

0 commit comments

Comments
 (0)