score:-1

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
})

score:0

here's what worked for me

 var timeout ;
function mouseDown(geography){

    timeout = setInterval( function(){


            if(data[geography.id]){

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

    return false;
}


function mouseUp(geography){

clearInterval(timeout);
    return false;
}

score:2

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) {
    return;
  }
  // perform while mouse is moving
})

Related Query