I have a canvas which is 600x600. The center of the canvas is at (300,300). I have a drawn a square at this coordinate. I have also drawn another square at (200,200). Both squares are 60x60 in size with the pivot at the centre.
Here is a screenshot below of the canvas: http://prntscr.com/ggc7mn
Without any zoom, the zoom is set to the value of 1. After increasing the zoom level to 2.3349999999999973, the view looks this: http://prntscr.com/ggc7xv
The center square's position is unchanged and still at the center at (300,300). Since the top left corner of the other square is at (0,0) in the second screen shot. I can calculate the center coordinates of the square by (length * zoom)/2 which is (60*2.33/2) = 69.9.
How can I calculate this if the square was not touching it's corner at (0,0) and if it was at any other position?
Here is a general angle of attack:
A zoom operation as you do is mathematically described as a so called "affine" transformation on each coordinate :
$$\left\{ \ \begin{array}{rcl} x'=ax+b\\y'=cy+d \end{array}\right. \ \ \ \iff \ \ \ \binom{x'}{y'}=\underbrace{\begin{pmatrix} a & 0\\0&c \end{pmatrix}}_{\text{scaling matrix}}\binom{x}{y}+\underbrace{\binom{b}{d}}_{translation}$$
with $(x,y)$ the old and $(x',y')$ the new coordinates, $a,b,c,d$ being constants that you can deduce from the images of 2 points (in order to have 4 equations in four unknowns): for example by tracking:
the image of the south-east corner (a classical handle for windows resizing : keeping track of the initial and final mouse position).
the image of the center of the window.
If it is a classical zoom, i.e. the length to width ratio is preserved: the shrinking/enlarging parameters will be the same for the $x$ and $y$ coordinates, i.e., $a=c.$
Edit: Fixed formula typos