Skip to content

Commit

Permalink
Merge pull request #950 from mapmeld/narrative_pan
Browse files Browse the repository at this point in the history
Issue 945: fix jumpy narrative map
  • Loading branch information
jameshadfield authored Mar 14, 2020
2 parents 0043eb9 + b71d24b commit 3d89b93
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/components/map/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,15 @@ class Map extends React.Component {
maybeInvalidateMapSize(nextProps) {
/* when we procedurally change the size of the card, for instance, when we swap from grid to full */
if (this.state.map && (this.props.width !== nextProps.width || this.props.height !== nextProps.height)) {
window.setTimeout(this.invalidateMapSize.bind(this), 1500);
// first, clear any existing timeout
if (this.map_timeout) {
window.clearTimeout(this.map_timeout);
}
// delay to resize map (when complete, narrative will re-focus map on data)
this.map_timeout = window.setTimeout(
this.invalidateMapSize.bind(this),
this.props.narrativeMode ? 100 : 750
);
}
}
invalidateMapSize() {
Expand Down Expand Up @@ -499,6 +507,11 @@ class Map extends React.Component {

/* Set up leaflet events */
map.on("moveend", this.respondToLeafletEvent.bind(this));
map.on("resize", () => {
if (this.props.narrativeMode) {
this.fitMapBoundsToData(this.state.demeData, this.state.demeIndices);
}
});

this.setState({map});
}
Expand Down Expand Up @@ -582,12 +595,11 @@ class Map extends React.Component {
return;
}

if (!this.state.userHasInteractedWithMap || this.props.narrative) {
if (geoResolutionChanged) {
/* changed geo-resolution in narrative mode => reset view */
this.fitMapBoundsToData(demeData, demeIndices);
} else if (visibilityChanged) {
/* changed visiblity (e.g. filters applied) in narrative mode => reset view */
if (geoResolutionChanged || visibilityChanged) {
/* changed visiblity (e.g. filters applied) in narrative mode => reset view */
if (this.props.narrativeMode) {
this.state.map.fire("resize");
} else if (!this.state.userHasInteractedWithMap) {
this.fitMapBoundsToData(demeData, demeIndices);
}
}
Expand Down

0 comments on commit 3d89b93

Please sign in to comment.