Search code examples
canvasjavafxrotationzooming

Zooming and rotating in on an area of the JavaFX canvas


I have simplified my problem to the fundamentals (the real problem is more complicated than this but a solution to this could easily be generalized to my problem).

I am working with JavaFX canvas and I am working on a feature that, when a button is pressed, the canvas will zoom and rotate in on an area. The initial canvas is as follows:

Canvas Pre Rotation and Zoom

The desired canvas is as follows, I hope it is clear that this would be obtained by zooming and rotating in on the mid-point between the nodes, the degree of rotation would be relative to the angle of the edge between the nodes.

Canvas Post Rotation and Zoom

Does JavaFX canvas support this functionality? How would this functionality be achieved?

Thanks for your time.


Solution

  • This functionality can be achieved by not using canas. Instead you should use the scene-graph where this can be achieved easily by modifying the transform of a group node.