The two conditions for your event are that the code executes every time there is an update in mouse position AND the mouse button is pressed.

Addressing the first part can be done with the 'mousemove' event, which fires when the mouse is moved over the element.

The second filter can be solved, by checking the mouse event, on if the button is pressed. If not, we don't execute the following code.

window.addEventListener('mousemove', function() { // Attach listener
  if (event.buttons == 0)  // Check event for button
    return;                // Button not pressed, exit
  // perform while mouse is moving


here's what worked for me

 var timeout ;
function mouseDown(geography){

    timeout = setInterval( function(){


              data[] ++;
              data[] = 1;
            var m = {};                                        
            m[] = color(data[]);
            map.updateChoropleth(m);}, 100);

    return false;

function mouseUp(geography){

    return false;


You could try to use mousemove instead, mousedown will only fire once.

var mouseDown = false;
window.addEventListener('mousedown', function() { mouseDown = true })
window.addEventListener('mouseup', function() { mouseDown = false })
window.addEventListener('mousemove', function() { 
  if (!mouseDown) {
  // perform while mouse is moving

Related Query