Your initial calculations use a marker width / height of 20x20 pixels:
return latLng[0] - 10;
Your "recalcs" should do this also with the resized image. I would put the "real" x / y positoin in your data so that you can do the recalculation:
datum.realx = latLng[0]; if ( latLng ) return latLng[0] - 10;
And then move them to the zoom handler:
map.svg.selectAll("image") .attr("height", 20*(1/scale)) .attr("width", 20*(1/scale)) .attr("x", function(d){ return d.realx - (20*(1/scale)/2); }) .attr("y", function(d){ return d.realy - (20*(1/scale)); });
Mark source share