Skip to content

Commit

Permalink
Debounce map movement handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Anand Thakker committed Jun 30, 2015
1 parent 5384d72 commit 08db89f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/assets/scripts/components/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require('mapbox.js');
var React = require('react/addons');
var Reflux = require('reflux');
var Router = require('react-router');
var _ = require('lodash');
var overlaps = require('turf-overlaps');
// Not working. Using cdn. (turf.intersect was throwing a weird error)
//var turf = require('turf');
Expand Down Expand Up @@ -483,7 +484,7 @@ var Map = React.createClass({


// Map move listener.
this.map.on('moveend', function() {
var onMoveEnd = _.debounce(function() {
// Compute new map location for the path .
var mapLocation = _this.mapViewToString();
// Preserve other params if any.
Expand All @@ -502,7 +503,9 @@ var Map = React.createClass({

actions.mapMove(_this.map);
_this.updateFauxGrid();
});
}, 300)
this.map.on('moveend', onMoveEnd);
this.map.on('movestart', onMoveEnd.cancel);

// Create fauxGrid.
this.updateFauxGrid();
Expand Down

0 comments on commit 08db89f

Please sign in to comment.