mobileorientationautodeskviewerforge

Autodesk Forge Viewer fit to view portrait/landscape


I have a Forge viewer app where I want the camera to fit the model bounding box if the orientation on mobile devices changes.

I load the model and set the camera to a specific position in the Autodesk.Viewing.MODEL_ROOT_LOADED_EVENT event. Then I fit the model with viewer.fitToView(). That works. In the Autodesk.Viewing.VIEWER_RESIZE_EVENT, which is also fired if the orientation of the screen changes, I run viewer.fitToView() again but the camera doesn't change.

The function doesn't seem to even run, but there is also no error message. If I zoom out of the model before changing the orientation the camera distance doesn't change although it should.

Maybe I use the wrong approach here but I can't find the problem.


Solution

  • Found the problem: I have locked panning of the camera:

    viewer.navigation.setLockSettings({"orbit":true, "zoom":true})
    viewer.navigation.setIsLocked(true)
    

    With those settings fitToView doesn't work. I now disable locking before fitting.