@@ -111,20 +111,7 @@ class LocationPicker extends React.Component<IProps, IState> {
111
111
this . geolocate . trigger ( ) ;
112
112
} ) ;
113
113
114
- this . geolocate . on ( 'error' , ( e : GeolocationPositionError ) => {
115
- this . props . onFinished ( ) ;
116
- logger . error ( "Could not fetch location" , e ) ;
117
- Modal . createTrackedDialog (
118
- 'Could not fetch location' ,
119
- '' ,
120
- ErrorDialog ,
121
- {
122
- title : _t ( "Could not fetch location" ) ,
123
- description : positionFailureMessage ( e . code ) ,
124
- } ,
125
- ) ;
126
- } ) ;
127
-
114
+ this . geolocate . on ( 'error' , this . onGeolocateError ) ;
128
115
this . geolocate . on ( 'geolocate' , this . onGeolocate ) ;
129
116
} catch ( e ) {
130
117
logger . error ( "Failed to render map" , e ) ;
@@ -133,6 +120,7 @@ class LocationPicker extends React.Component<IProps, IState> {
133
120
}
134
121
135
122
componentWillUnmount ( ) {
123
+ this . geolocate ?. off ( 'error' , this . onGeolocateError ) ;
136
124
this . geolocate ?. off ( 'geolocate' , this . onGeolocate ) ;
137
125
this . context . off ( ClientEvent . ClientWellKnown , this . updateStyleUrl ) ;
138
126
}
@@ -154,6 +142,20 @@ class LocationPicker extends React.Component<IProps, IState> {
154
142
) ;
155
143
} ;
156
144
145
+ private onGeolocateError = ( e : GeolocationPositionError ) => {
146
+ this . props . onFinished ( ) ;
147
+ logger . error ( "Could not fetch location" , e ) ;
148
+ Modal . createTrackedDialog (
149
+ 'Could not fetch location' ,
150
+ '' ,
151
+ ErrorDialog ,
152
+ {
153
+ title : _t ( "Could not fetch location" ) ,
154
+ description : positionFailureMessage ( e . code ) ,
155
+ } ,
156
+ ) ;
157
+ } ;
158
+
157
159
private onOk = ( ) => {
158
160
const position = this . state . position ;
159
161
0 commit comments