Skip to content

Commit

Permalink
Add shouldUnregisterMapOnUnmount prop to persist map object on unmount (
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinRamsunder authored and itsmichaeldiego committed Mar 18, 2019
1 parent c8a7f56 commit 40fe3ea
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/google_map.js
Expand Up @@ -137,6 +137,7 @@ export default class GoogleMap extends Component {
style: PropTypes.any,
resetBoundsOnResize: PropTypes.bool,
layerTypes: PropTypes.arrayOf(PropTypes.string), // ['TransitLayer', 'TrafficLayer']
shouldUnregisterMapOnUnmount: PropTypes.bool,
};

static defaultProps = {
Expand All @@ -161,6 +162,7 @@ export default class GoogleMap extends Component {
layerTypes: [],
heatmap: {},
heatmapLibrary: false,
shouldUnregisterMapOnUnmount: true,
};

static googleMapLoader = googleMapLoader; // eslint-disable-line
Expand Down Expand Up @@ -424,20 +426,24 @@ export default class GoogleMap extends Component {
this.overlay_.setMap(null);
}

if (this.maps_ && this.map_) {
if (this.maps_ && this.map_ && this.props.shouldUnregisterMapOnUnmount) {
// fix google, as otherwise listeners works even without map
this.map_.setOptions({ scrollwheel: false });
this.maps_.event.clearInstanceListeners(this.map_);
}

this.map_ = null;
this.maps_ = null;
if (this.props.shouldUnregisterMapOnUnmount) {
this.map_ = null;
this.maps_ = null;
}
this.markersDispatcher_.dispose();

this.resetSizeOnIdle_ = false;

delete this.map_;
delete this.markersDispatcher_;
if (this.props.shouldUnregisterMapOnUnmount) {
delete this.map_;
delete this.markersDispatcher_;
}
}
// calc minZoom if map size available
// it's better to not set minZoom less than this calculation gives
Expand Down Expand Up @@ -662,7 +668,7 @@ export default class GoogleMap extends Component {
this_._onBoundsChanged(map, maps, !this_.props.debounced);

if (!this_.googleApiLoadedCalled_) {
this_._onGoogleApiLoaded({ map, maps });
this_._onGoogleApiLoaded({ map, maps, ref: this_.googleMapDom_ });
this_.googleApiLoadedCalled_ = true;
}

Expand Down Expand Up @@ -794,7 +800,11 @@ export default class GoogleMap extends Component {
})
.catch(e => {
// notify callback of load failure
this._onGoogleApiLoaded({ map: null, maps: null });
this._onGoogleApiLoaded({
map: null,
maps: null,
ref: this.googleMapDom_,
});
console.error(e); // eslint-disable-line no-console
throw e;
});
Expand Down

0 comments on commit 40fe3ea

Please sign in to comment.