Skip to content

Commit

Permalink
detect change in geoRegion via filter too
Browse files Browse the repository at this point in the history
  • Loading branch information
emmahodcroft authored and jameshadfield committed Feb 5, 2020
1 parent bde3d87 commit 8a213ac
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/components/map/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,16 @@ class Map extends React.Component {
this.props.pieChart
);

const SWNE = this.getGeoRange(demeIndices, demeData);
const maybeNewBounds = L.latLngBounds(SWNE[0], SWNE[1]);
if (!this.state.boundsSet) { // we are doing the initial render -> set map to the range of the data
const SWNE = this.getGeoRange(demeIndices, demeData);
// L. available because leaflet() was called in componentWillMount
this.state.map.fitBounds(L.latLngBounds(SWNE[0], SWNE[1]));
this.state.currentBounds = maybeNewBounds;
this.state.map.fitBounds(maybeNewBounds);
} else if (!this.state.currentBounds.equals(maybeNewBounds)) {
// check to see if the new bounds would be different for any reason - if so, change them!
this.state.currentBounds = maybeNewBounds;
this.state.map.fitBounds(maybeNewBounds);
}

/* Set up leaflet events */
Expand Down Expand Up @@ -551,6 +557,7 @@ class Map extends React.Component {
fitMapBoundsToData() {
const SWNE = this.getGeoRange();
// window.L available because leaflet() was called in componentWillMount
this.state.currentBounds = window.L.latLngBounds(SWNE[0], SWNE[1]);
this.state.map.fitBounds(window.L.latLngBounds(SWNE[0], SWNE[1]));
}
resetZoomButtonClicked() {
Expand Down

0 comments on commit 8a213ac

Please sign in to comment.