diff --git a/src/components/SearchMap/SearchMapWithGoogleMap.js b/src/components/SearchMap/SearchMapWithGoogleMap.js index ab17456d..fd138e8f 100644 --- a/src/components/SearchMap/SearchMapWithGoogleMap.js +++ b/src/components/SearchMap/SearchMapWithGoogleMap.js @@ -365,10 +365,10 @@ class SearchMapWithGoogleMap extends Component { this.onIdle = this.onIdle.bind(this); } - componentWillReceiveProps(nextProps) { - if (!isEqual(this.props.location, nextProps.location)) { + componentDidUpdate(prevProps) { + if (!isEqual(prevProps.location, this.props.location)) { // If no mapSearch url parameter is given, this is original location search - const { mapSearch } = parse(nextProps.location.search, { + const { mapSearch } = parse(this.props.location.search, { latlng: ['origin'], latlngBounds: ['bounds'], }); @@ -383,8 +383,8 @@ class SearchMapWithGoogleMap extends Component { // Do not call fitMapToBounds if bounds are the same. // Our bounds are viewport bounds, and fitBounds will try to add margins around those bounds // that would result to zoom-loop (bound change -> fitmap -> bounds change -> ...) - if (!isEqual(nextProps.bounds, currentBounds) && !this.viewportBounds) { - fitMapToBounds(this.map, nextProps.bounds, { padding: 0 }); + if (!isEqual(this.props.bounds, currentBounds) && !this.viewportBounds) { + fitMapToBounds(this.map, this.props.bounds, { padding: 0 }); } } } diff --git a/src/components/SearchMap/SearchMapWithMapbox.js b/src/components/SearchMap/SearchMapWithMapbox.js index c8f0609b..05698981 100644 --- a/src/components/SearchMap/SearchMapWithMapbox.js +++ b/src/components/SearchMap/SearchMapWithMapbox.js @@ -249,10 +249,10 @@ class SearchMapWithMapbox extends Component { this.handleMobilePinchZoom = this.handleMobilePinchZoom.bind(this); } - componentWillReceiveProps(nextProps) { - if (!isEqual(this.props.location, nextProps.location)) { + componentDidUpdate(prevProps) { + if (!isEqual(prevProps.location, this.props.location)) { // If no mapSearch url parameter is given, this is original location search - const { mapSearch } = parse(nextProps.location.search, { + const { mapSearch } = parse(this.props.location.search, { latlng: ['origin'], latlngBounds: ['bounds'], }); @@ -267,13 +267,11 @@ class SearchMapWithMapbox extends Component { // Do not call fitMapToBounds if bounds are the same. // Our bounds are viewport bounds, and fitBounds will try to add margins around those bounds // that would result to zoom-loop (bound change -> fitmap -> bounds change -> ...) - if (!isEqual(nextProps.bounds, currentBounds) && !this.viewportBounds) { - fitMapToBounds(this.map, nextProps.bounds, { padding: 0, isAutocompleteSearch: true }); + if (!isEqual(this.props.bounds, currentBounds) && !this.viewportBounds) { + fitMapToBounds(this.map, this.props.bounds, { padding: 0, isAutocompleteSearch: true }); } } - } - componentDidUpdate(prevProps) { if (!this.map && this.state.mapContainer) { this.initializeMap();