Forma Developer Forum
Welcome to Autodesk Forma Developer Forum. Share your knowledge, ask questions, and explore popular Forma API topics.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do I zoom in to an area?

Message 1 of 5
287 Views, 4 Replies

How do I zoom in to an area?

Hello Forma team,

In our extension I am trying to achieve a "focus to area" functionality where the user can click a button and the camera comes closer in the center of the project area, thus simulating a focusing effect. 

In order to make this possible I use the forma camera move() method where I take the z property of the current state and move the camera 400 ms like this following code.

However, I am encountering some inconsistencies with this approach. In certain instances, the camera either overshoots or doesn't reach close enough to the designated area.

Could you suggest any refinements to this method, or perhaps propose another solution?


  async focusOnPreviewArea() {
    const { target: {z} } = await;
      position: { x: 0, y: 0, z: (400 + z) },
      target: { x: 0, y: 0, z: z },
      transitionTimeMs: 1500


Also can you provide more info (or add to the docs) about what exactly are x,y,z properties of the Camera State as I noticed the z property in the target property is the real elevation of the point.

Tags (2)
Labels (2)
Message 2 of 5
in reply to: iklimis

This is an interesting problem.


So first of all: the X is the offset in meters from the ref point of the project in the horizontal direction (looking at the map north aligned from the top down). The Y is the vertical offset. The Z is the elevation from sea level at this point. A fact that you should not rely on is that the reference point will be the center of the terrain after project creation. This will be the case in 90% of projects. But when someone modifies the terrain, then this assumption is broken. 


Now moving the camera intelligently is a composition of a few different concepts. First you need to find the x,y location you want to move the camera to, then you need to compute the z elevation of the camera. And lastly you need to compute the target that the camera should point toward. In your example code you are placing the camera at the ref point, and you are getting the existing z location of the camera and adding 400 meters to this. Then you set the target 0,0,z which means the camera will point downwards. But the z location is not set reliably. 

Now if you are only looking at zooming to the center I would advice you to get the bounding box of the terrain (`Forma.terrain.getBbox()`), compute the center point for x and y. Get the elevation of the terrain at the center point (`Forma.terrain.getElevationAt()`), and add a offset to this. Fix the target to the original value from `getElevationAt`. If you want the user to be able to select a point to zoom in on you could use the `Forma.designTool.getPoint()` and then zoom in on this point. 


Please let me know if this helps explain these concepts and if it solves your use-case 🙂 I will think about how to add this to the documentation. 

Message 3 of 5
in reply to: havard.hoiby

Hey @havard.hoiby thank for this information it really helped a lot

I realize that i mistakenly relied on the center of the area being the (0,0,z). 
You said the X is the offset in meters from the ref point of the project in the horizontal direction 

Can you explain what is and how does the ref point of the project is set? 
Is it the placemark upon project creation in the map or something else? Can i use a method to get it?

Thanks again

Message 4 of 5
in reply to: iklimis

Happy to help 🙂 


When you create a Forma project you select a bounding box for you project. You navigate in WGS84 (aka epsg:4326 aka lat/long). Then we figure out the closest UTM zone for your project and reproject an axis-alinged bounding box for your project in your local UTM zone. What is great the UTM coordinate systems is that the base unit is meters, while WGS84 is degrees. From the bounding box we compute the geometrical center and call set this as the reference point of the project. You can read this from ProjectAPI, where `Forma.project.getGeoLocation()` is the reference point as lat/long and `Forma.project.getProject().refPoint` is the reference point in the UTM zone and `Forma.project.getProject().srid` is the epsg code for the UTM zone used in your project. 


If you want to reproject all the local geometry into a given coordinate system you start by adding the x,y coordinates with the `refPoint` of the UTM zone and now you have all the coordinates in the UTM zone projection. `Forma.project.getProject().projString` is a shorthand to the specific Proj.4 projection string that we use. 


Hope this is helpful 🙂 let me know if it solves your case or not, and I'm looking forward to meeting you in Oslo in February 😄

Message 5 of 5
in reply to: havard.hoiby


Thanks a lot @havard.hoiby , that was really insightful and helped clearing things out

tried the new way of calculating the center and adding an offset to the given elevation, works great!

Thanks again, looking forward to meeting you in Oslo!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums