@@ -9,7 +9,7 @@ import TripPlanPinMarker from '$components/trip-planner/tripPlanPinMarker.svelte
9
9
import { mount , unmount } from 'svelte' ;
10
10
11
11
export default class GoogleMapProvider {
12
- constructor ( apiKey ) {
12
+ constructor ( apiKey , handleStopMarkerSelect ) {
13
13
this . apiKey = apiKey ;
14
14
this . map = null ;
15
15
this . globalInfoWindow = null ;
@@ -18,6 +18,7 @@ export default class GoogleMapProvider {
18
18
this . stopMarkers = [ ] ;
19
19
this . vehicleMarkers = [ ] ;
20
20
this . markersMap = new Map ( ) ;
21
+ this . handleStopMarkerSelect = handleStopMarkerSelect ;
21
22
}
22
23
23
24
async initMap ( element , options ) {
@@ -122,33 +123,37 @@ export default class GoogleMapProvider {
122
123
123
124
this . stopsMap . set ( stop . id , stop ) ;
124
125
125
- marker . addListener ( 'click' , ( ) => {
126
- if ( this . globalInfoWindow ) {
127
- this . globalInfoWindow . close ( ) ;
128
- }
126
+ marker . addListener ( 'click' , ( ) => this . openStopMarker ( stop , stopTime ) ) ;
129
127
130
- if ( this . popupContentComponent ) {
131
- unmount ( this . popupContentComponent ) ;
132
- }
128
+ this . markersMap . set ( stop . id , marker ) ;
129
+ this . stopMarkers . push ( marker ) ;
130
+ }
133
131
134
- const popupContainer = document . createElement ( 'div' ) ;
132
+ openStopMarker ( stop , stopTime = null ) {
133
+ if ( this . globalInfoWindow ) {
134
+ this . globalInfoWindow . close ( ) ;
135
+ }
135
136
136
- this . popupContentComponent = mount ( PopupContent , {
137
- target : popupContainer ,
138
- props : {
139
- stopName : stop . name ,
140
- arrivalTime : stopTime ? stopTime . arrivalTime : null
141
- }
142
- } ) ;
137
+ if ( this . popupContentComponent ) {
138
+ unmount ( this . popupContentComponent ) ;
139
+ }
143
140
144
- this . globalInfoWindow = new google . maps . InfoWindow ( {
145
- content : popupContainer
146
- } ) ;
141
+ const popupContainer = document . createElement ( 'div' ) ;
142
+
143
+ this . popupContentComponent = mount ( PopupContent , {
144
+ target : popupContainer ,
145
+ props : {
146
+ stopName : stop . name ,
147
+ arrivalTime : stopTime ? stopTime . arrivalTime : null ,
148
+ handleStopMarkerSelect : ( ) => this . handleStopMarkerSelect ( stop )
149
+ }
150
+ } ) ;
147
151
148
- this . globalInfoWindow . open ( this . map , marker ) ;
152
+ this . globalInfoWindow = new google . maps . InfoWindow ( {
153
+ content : popupContainer
149
154
} ) ;
150
155
151
- this . stopMarkers . push ( marker ) ;
156
+ this . globalInfoWindow . open ( this . map , this . markersMap . get ( stop . id ) ) ;
152
157
}
153
158
154
159
highlightMarker ( stopId ) {
0 commit comments