@@ -107,31 +107,37 @@ class LocationPicker extends React.Component<IProps, IState> {
107107 zoom : 1 ,
108108 } ) ;
109109
110- // Add geolocate control to the map.
111- this . geolocate = new maplibregl . GeolocateControl ( {
112- positionOptions : {
113- enableHighAccuracy : true ,
114- } ,
115- trackUserLocation : true ,
116- } ) ;
117- this . map . addControl ( this . geolocate ) ;
110+ try {
111+ // Add geolocate control to the map.
112+ this . geolocate = new maplibregl . GeolocateControl ( {
113+ positionOptions : {
114+ enableHighAccuracy : true ,
115+ } ,
116+ trackUserLocation : true ,
117+ } ) ;
118+ this . map . addControl ( this . geolocate ) ;
118119
119- this . map . on ( 'error' , ( e ) => {
120- logger . error ( "Failed to load map: check map_style_url in config.json has a valid URL and API key" , e . error ) ;
121- this . setState ( { error : e . error } ) ;
122- } ) ;
120+ this . map . on ( 'error' , ( e ) => {
121+ logger . error ( "Failed to load map: check map_style_url in config.json has a valid URL and API key" ,
122+ e . error ) ;
123+ this . setState ( { error : e . error } ) ;
124+ } ) ;
123125
124- this . map . on ( 'load' , ( ) => {
125- this . geolocate . trigger ( ) ;
126- } ) ;
126+ this . map . on ( 'load' , ( ) => {
127+ this . geolocate . trigger ( ) ;
128+ } ) ;
127129
128- this . map . on ( 'click' , ( e ) => {
129- this . addMarker ( e . lngLat ) ;
130- this . storeManualPosition ( e . lngLat ) ;
131- this . setState ( { type : LocationShareType . Custom } ) ;
132- } ) ;
130+ this . map . on ( 'click' , ( e ) => {
131+ this . addMarker ( e . lngLat ) ;
132+ this . storeManualPosition ( e . lngLat ) ;
133+ this . setState ( { type : LocationShareType . Custom } ) ;
134+ } ) ;
133135
134- this . geolocate . on ( 'geolocate' , this . onGeolocate ) ;
136+ this . geolocate . on ( 'geolocate' , this . onGeolocate ) ;
137+ } catch ( e ) {
138+ logger . error ( "Failed to render map" , e . error ) ;
139+ this . setState ( { error : e . error } ) ;
140+ }
135141 }
136142
137143 private addMarker ( lngLat : maplibregl . LngLat ) : void {
@@ -169,7 +175,7 @@ class LocationPicker extends React.Component<IProps, IState> {
169175 }
170176
171177 componentWillUnmount ( ) {
172- this . geolocate . off ( 'geolocate' , this . onGeolocate ) ;
178+ this . geolocate ? .off ( 'geolocate' , this . onGeolocate ) ;
173179 }
174180
175181 private onGeolocate = ( position : GeolocationPosition ) => {
0 commit comments