@@ -137,6 +137,7 @@ export default class GoogleMap extends Component {
137
137
style : PropTypes . any ,
138
138
resetBoundsOnResize : PropTypes . bool ,
139
139
layerTypes : PropTypes . arrayOf ( PropTypes . string ) , // ['TransitLayer', 'TrafficLayer']
140
+ shouldUnregisterMapOnUnmount : PropTypes . bool ,
140
141
} ;
141
142
142
143
static defaultProps = {
@@ -161,6 +162,7 @@ export default class GoogleMap extends Component {
161
162
layerTypes : [ ] ,
162
163
heatmap : { } ,
163
164
heatmapLibrary : false ,
165
+ shouldUnregisterMapOnUnmount : true ,
164
166
} ;
165
167
166
168
static googleMapLoader = googleMapLoader ; // eslint-disable-line
@@ -424,20 +426,24 @@ export default class GoogleMap extends Component {
424
426
this . overlay_ . setMap ( null ) ;
425
427
}
426
428
427
- if ( this . maps_ && this . map_ ) {
429
+ if ( this . maps_ && this . map_ && this . props . shouldUnregisterMapOnUnmount ) {
428
430
// fix google, as otherwise listeners works even without map
429
431
this . map_ . setOptions ( { scrollwheel : false } ) ;
430
432
this . maps_ . event . clearInstanceListeners ( this . map_ ) ;
431
433
}
432
434
433
- this . map_ = null ;
434
- this . maps_ = null ;
435
+ if ( this . props . shouldUnregisterMapOnUnmount ) {
436
+ this . map_ = null ;
437
+ this . maps_ = null ;
438
+ }
435
439
this . markersDispatcher_ . dispose ( ) ;
436
440
437
441
this . resetSizeOnIdle_ = false ;
438
442
439
- delete this . map_ ;
440
- delete this . markersDispatcher_ ;
443
+ if ( this . props . shouldUnregisterMapOnUnmount ) {
444
+ delete this . map_ ;
445
+ delete this . markersDispatcher_ ;
446
+ }
441
447
}
442
448
// calc minZoom if map size available
443
449
// it's better to not set minZoom less than this calculation gives
@@ -662,7 +668,7 @@ export default class GoogleMap extends Component {
662
668
this_ . _onBoundsChanged ( map , maps , ! this_ . props . debounced ) ;
663
669
664
670
if ( ! this_ . googleApiLoadedCalled_ ) {
665
- this_ . _onGoogleApiLoaded ( { map, maps } ) ;
671
+ this_ . _onGoogleApiLoaded ( { map, maps, ref : this_ . googleMapDom_ } ) ;
666
672
this_ . googleApiLoadedCalled_ = true ;
667
673
}
668
674
@@ -794,7 +800,11 @@ export default class GoogleMap extends Component {
794
800
} )
795
801
. catch ( e => {
796
802
// notify callback of load failure
797
- this . _onGoogleApiLoaded ( { map : null , maps : null } ) ;
803
+ this . _onGoogleApiLoaded ( {
804
+ map : null ,
805
+ maps : null ,
806
+ ref : this . googleMapDom_ ,
807
+ } ) ;
798
808
console . error ( e ) ; // eslint-disable-line no-console
799
809
throw e ;
800
810
} ) ;
0 commit comments