user3018981
user3018981

Reputation: 236

d3 zooming to mouse location, not the centroid

I have a map of counties in a state.

I am using the code found here http://bl.ocks.org/mbostock/2206590 to implement zooming on my map.

The original example works like this:

enter image description here

This works well enough, the user clicks on a state and it is zoomed and centered using the state centroid. Is it possible to use the mouse location as the point about which to zoom? It would seem easy enough, but I'm not sure how to get the mouse coordinates.

Upvotes: 3

Views: 1994

Answers (1)

Lars Kotthoff
Lars Kotthoff

Reputation: 109272

Use d3.event.x and d3.event.y instead of the computed centroid. See here.

Upvotes: 1

Related Questions