Question

I'm using Raphael to build a map-like site. when panning and zooming I want some objects to be in the middle, there for I need to know where is the middle in perspective to the current viewbox (not the paper). How can I know the center of the paper's viewbox after a lot of manipulations?

Was it helpful?

Solution

The center of the viewbox can be calculated by dividing the viewbox width and height by 2 and adding the x/y offsets.

//  viewbox x + half viewbox width
var vx = (paper._viewBox[0] + (paper._viewBox[2] / 2))

// viewbox y + half viewbox height
var vy = (paper._viewBox[1] + (paper._viewBox[3] / 2))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top