@@ -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 } ,
0 commit comments