Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » How can i set the initial zoom factor to the InfiniteCanvas?
How can i set the initial zoom factor to the InfiniteCanvas? [message #1795513] Mon, 24 September 2018 15:13 Go to next message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 179
Registered: July 2009
Senior Member

i see i can set the scroll position with

InfiniteCanvas c = (InfiniteCanvas) viewer.getCanvas();

For setting the zoom level, i tried to use setScaleX/Y but the behavior is then strange when resizing the window.

Is there an API for this?

Re: How can i set the initial zoom factor to the InfiniteCanvas? [message #1802132 is a reply to message #1795513] Fri, 01 February 2019 17:27 Go to previous message
Matthias Wienand is currently offline Matthias WienandFriend
Messages: 230
Registered: March 2015
Senior Member
Hi Frank,

you can use the fitToSize() method and pass-in the absolute zoom level you want to achieve.

scaleX/Y are the default JavaFX properties. Therefore, the whole canvas is scaled using these properties.

Alternatively, you can manipulate the content transform to achieve the desired result. For this, I would recommend to get inspiration from fitToSize():

		// compute content center
		double cx = contentBounds.getMinX() + contentBounds.getWidth() / 2;
		double cy = contentBounds.getMinY() + contentBounds.getHeight() / 2;

		// compute visible area center
		double vx = getWidth() / 2;
		double vy = getHeight() / 2;

		// scroll to center position
		setHorizontalScrollOffset(getHorizontalScrollOffset() + vx - cx);
		setVerticalScrollOffset(getVerticalScrollOffset() + vy - cy);

		// compute pivot point for zoom within content coordinates
		Point2D pivot = getContentGroup().sceneToLocal(vx, vy);

		// restrict zoom factor to [zoomMin, zoomMax] range
		AffineTransform contentTransform = FX2Geometry
		double realZoomFactor = contentTransform.getScaleX() * zf;
		if (realZoomFactor > zoomMax) {
			zf = zoomMax / contentTransform.getScaleX();
		if (realZoomFactor < zoomMin) {
			zf = zoomMin / contentTransform.getScaleX();

		// compute scale transformation (around visible center)
		AffineTransform scaleTransform = new AffineTransform()
				.translate(pivot.getX(), pivot.getY()).scale(zf, zf)
				.translate(-pivot.getX(), -pivot.getY());

		// concatenate old transformation and scale transformation to yield the
		// new transformation
		AffineTransform newTransform = contentTransform


Best regards,
Previous Topic:Hover outline is having gap on right+bottom side
Next Topic:ViewportPolicy fitToSize method reloads css
Goto Forum:

Current Time: Wed May 22 08:30:24 GMT 2024

Powered by FUDForum. Page generated in 0.03533 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top