dylanmac
dylanmac

Reputation: 353

d3 maps: how to disable zoom on scrollwheel but retain panning by dragging

d3 has zoom and pan rolled into the zoom behavior. Is there a way to disable zoom on scrollwheel but retain the ability to pan, i.e. move the map when dragging?

Upvotes: 4

Views: 2993

Answers (2)

Lars Kotthoff
Lars Kotthoff

Reputation: 109242

The zoom behaviour really only provides the framework for what you need for zoom, the handling of the generated events is entirely up to you. You are free to ignore parts of the events, or all of them. In this case, you could simply not use the zoom, e.g. like this.

function zoomed() {
  svg.attr("transform", "translate(" + d3.event.translate + ")");
  // d3.event.scale is ignored
}

Upvotes: 4

user1614080
user1614080

Reputation: 2874

You can simply constrain the zoom with zoom.scaleExtent([extent]) and the documentation is here

Upvotes: 2

Related Questions