Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #164. Update the map with tollerance #181

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions web/client/components/map/leaflet/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,29 @@ var LeafletMap = React.createClass({
if (newProps.mousePointer !== this.props.mousePointer) {
this.setMousePointer(newProps.mousePointer);
}
const currentCenter = this.props.center;
const centerIsUpdate = newProps.center.y === currentCenter.y &&
newProps.center.x === currentCenter.x;
const currentCenter = this.map.getCenter();
// current implementation will update the map only if the movement
// between 12 decimals in the reference system to avoid rounded value
// changes due to float mathematic operations.
const isNearlyEqual = function(a, b) {
if (a === undefined || b === undefined) {
return false;
}
return ( a.toFixed(12) - (b.toFixed(12))) === 0;
};
const centerIsUpdate = isNearlyEqual(newProps.center.x, currentCenter.lng) &&
isNearlyEqual(newProps.center.y, currentCenter.lat);
const zoomChanged = newProps.zoom !== this.map.getZoom();

if (!centerIsUpdate) {
this.map.setView([newProps.center.y, newProps.center.x]);
}
if (newProps.zoom !== this.props.zoom) {
// Do the change at the same time, to avoid glitches
if (!centerIsUpdate && zoomChanged) {
this.map.setView([newProps.center.y, newProps.center.x], newProps.zoom);
} else if (zoomChanged) {
this.map.setZoom(newProps.zoom);
} else if (!centerIsUpdate) {
this.map.setView([newProps.center.y, newProps.center.x]);
}

},
componentWillUnmount() {
this.map.remove();
Expand Down