Skip to content

Commit 9736aa1

Browse files
committed
Add markers for nearby places
1 parent a0dc503 commit 9736aa1

File tree

10 files changed

+61
-8
lines changed

10 files changed

+61
-8
lines changed

client/src/app/home/home.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ export class HomeComponent implements AfterViewInit {
4747
for (i = 0; i < res.length; i++) {
4848
var shelterMarkerDiv = document.createElement('div');
4949
shelterMarkerDiv.style.backgroundImage = 'url("assets/shelter.png")';
50-
shelterMarkerDiv.style.width = '50px';
51-
shelterMarkerDiv.style.height = '50px';
50+
shelterMarkerDiv.style.width = '64px';
51+
shelterMarkerDiv.style.height = '64px';
5252
shelterMarkerDiv.style.backgroundRepeat = 'no-repeat'
5353

5454
const shelter = res[i];

client/src/app/shelters/shelter-info/shelter-info.component.ts

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,29 @@ export class ShelterInfoComponent implements OnInit {
5959
}
6060
}
6161

62+
addMarkerToMap(map, places, type) {
63+
var maxIter = Math.min(5, places.length);
64+
65+
var i = 0;
66+
for (i = 0; i < maxIter; i++) {
67+
var shelterMarkerDiv = document.createElement('div');
68+
shelterMarkerDiv.style.backgroundImage = `url("assets/${type}.png")`;
69+
shelterMarkerDiv.style.width = '32px';
70+
shelterMarkerDiv.style.height = '32px';
71+
shelterMarkerDiv.style.backgroundRepeat = 'no-repeat'
72+
73+
const place = places[i];
74+
75+
new mapboxgl.Marker(shelterMarkerDiv)
76+
.setLngLat([place.geometry.location.lng, place.geometry.location.lat])
77+
.setPopup(
78+
new mapboxgl.Popup({ offset: 25 }) // add popups
79+
.setHTML('<h3 class="subtitle">' + place.name + '</h3>')
80+
)
81+
.addTo(map);
82+
}
83+
}
84+
6285
ngOnInit() {
6386
const shelterId = this.route.snapshot.paramMap.get('id');
6487

@@ -71,41 +94,71 @@ export class ShelterInfoComponent implements OnInit {
7194

7295
var map = new mapboxgl.Map({
7396
container: 'map',
74-
style: 'mapbox://styles/mapbox/satellite-streets-v10',
97+
style: 'mapbox://styles/mapbox/navigation-guidance-night-v4',
7598
center: this.shelter.lngLat.split(","),
7699
zoom: 12
77100
});
101+
102+
var _tempShelterMarker = [
103+
{
104+
geometry: {
105+
location: {
106+
lat: this.shelter.lngLat.split(',')[1],
107+
lng: this.shelter.lngLat.split(',')[0],
108+
}
109+
},
110+
name: this.shelter.name
111+
}
112+
];
113+
114+
this.addMarkerToMap(map, _tempShelterMarker, 'shelter');
78115

79116
this.shelterService.getNearbyPlaces(this.shelter.lngLat, 5000, 'hospital')
80117
.subscribe(
81-
(res) => this.nearByHospitals = res.results,
118+
(res) => {
119+
this.nearByHospitals = res.results;
120+
this.addMarkerToMap(map, this.nearByHospitals, 'hospital');
121+
},
82122
this.alertService.error
83123
);
84124
this.shelterService.getNearbyPlaces(this.shelter.lngLat, 5000, 'atm')
85125
.subscribe(
86126
(res) => {
87127
this.nearByAtms = res.results;
128+
this.addMarkerToMap(map, this.nearByAtms, 'atm')
88129
},
89130
this.alertService.error
90131
);
91132
this.shelterService.getNearbyPlaces(this.shelter.lngLat, 5000, 'airport')
92133
.subscribe(
93-
(res) => this.nearByAirports = res.results,
134+
(res) => {
135+
this.nearByAirports = res.results;
136+
this.addMarkerToMap(map, this.nearByAirports, 'airport');
137+
},
94138
this.alertService.error
95139
);
96140
this.shelterService.getNearbyPlaces(this.shelter.lngLat, 5000, 'police')
97141
.subscribe(
98-
(res) => this.nearByPoliceStations = res.results,
142+
(res) => {
143+
this.nearByPoliceStations = res.results;
144+
this.addMarkerToMap(map, this.nearByPoliceStations, 'police_station');
145+
},
99146
this.alertService.error
100147
);
101148
this.shelterService.getNearbyPlaces(this.shelter.lngLat, 5000, 'train_station')
102149
.subscribe(
103-
(res) => this.nearByTrainStations = res.results,
150+
(res) => {
151+
this.nearByTrainStations = res.results;
152+
this.addMarkerToMap(map, this.nearByTrainStations, 'train_station');
153+
},
104154
this.alertService.error
105155
);
106156
this.shelterService.getNearbyPlaces(this.shelter.lngLat, 5000, 'fire_station')
107157
.subscribe(
108-
(res) => this.nearByFireStations = res.results,
158+
(res) => {
159+
this.nearByFireStations = res.results;
160+
this.addMarkerToMap(map, this.nearByFireStations, 'fire_station');
161+
},
109162
this.alertService.error
110163
);
111164
},

client/src/assets/airport.png

3.34 KB
Loading

client/src/assets/atm.png

2.6 KB
Loading

client/src/assets/fire_station.png

2.58 KB
Loading

client/src/assets/hospital.png

857 Bytes
Loading
3.09 KB
Loading

client/src/assets/shelter.png

-1.33 KB
Loading

client/src/assets/shelter_2.png

4.04 KB
Loading
2.82 KB
Loading

0 commit comments

Comments
 (0)