Q:

How to target object coordinates after zoom using fabricjs?

Currently I am trying to create connectors between objects added on the canvas. This works as intended for the default zoom.
After the default zoom changes I cannot target the correct coordinates of the objects. I tried using setCoords() after each zoom action but with no success.
See the fiddle bellow for details:
canvas.setZoom(canvas.getZoom() * 1.1 ) ;

for (var i in objects) {
  objects[i].setCoords();
}

canvas.renderAll();
canvas.calcOffset();

https://jsfiddle.net/sgeax159/
Regards,
Alex

A:

https://jsfiddle.net/sgeax159/3/
Trying to draw things using oCoords is generally wrong.
oCoords are for mouse interaction and updated with setCoords().
setCoords() is called most of the time by fabric at the end of mouse interactions.
Trying to guess the canvas absolute coordinates from oCoords when there is zoom and pan is possible, but requires:

to udpate oCoords manually called setCoords for all objects after zoom and pan
to multiply the coords by the inverse of the viewportTransform

Fabric since 1.7.X offers aCoords that are the absolute coords of the objects, independent of the zoom level or the pan. Those sets of coordinates are very usefull for this kind of operation.
Sadly they come just for the four main corners ( tl, tr, bl, br ) but you can figure out the middle ones by adding and dividing:
ml is  x = (tl.x + bl.x) / 2  and y = (tl.x + bl.y) / 2 or you can extend calcCoords to add them to calculation.
check the updated fiddle.

