I have a D3.js Datamaps.js map with pin markers, that I've been trying to implement zooming for.
http://jsbin.com/xoferi/edit?html,output
The image pin markers are 20x20 and the point of the pin (at x+10,y+20) is over the latitude/longitude spot selected.
I'm having issues when zooming the map, with the images drifting from their relative position. For example: take a look a the Iceland pin. As you zoom in it drifts up and to the left.
How can I keep the pins the same size, and in the same relative position while zooming and click-dragging the map?
I've looked for other examples and I'm just not sure what I'm missing. Maybe the viewport size needs to be added to the calculation soemhow. Or maybe the origin of the pin markers needs to be changed from the default. I'm just not sure.
Your original calculations make use of the width/height of the marker being
20x20
pixels:Your "recalcs" need to do this to as well with the resized image. I would stash the "real" x/y positoin in your data, so you can re-perform the calculations:
And then move them in your zoom handler: