Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not update camera zoom when DEM data isn't available yet #11461

Merged
merged 2 commits into from
Feb 22, 2022

Conversation

karimnaaji
Copy link
Contributor

@karimnaaji karimnaaji commented Feb 1, 2022

Make sure to not update camera zoom when the terrain DEM data isn't available at center point, which is the reference to calculate the camera zoom over terrain. This fixes the following issue that was reported by customer:

Edited-gljs.mov

More description of the issue and a reproducible case is available here https://github.com/mapbox/gl-js-team/issues/341

Launch Checklist

  • briefly describe the changes in this PR
  • write tests for all new functionality
  • manually test the debug page
  • apply changelog label ('bug', 'feature', 'docs', etc) or use the label 'skip changelog'
  • add an entry inside this element for inclusion in the mapbox-gl-js changelog: <changelog>Fix a potential issue with camera going under the terrain when the DEM data isn't available at center point.</changelog>

Sorry, something went wrong.

Copy link
Contributor

@SnailBones SnailBones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still recreate the linked issue in this PR by zooming before terrain loads. This makes me think that the issue might be in the camera transformation algorithm itself.

@karimnaaji
Copy link
Contributor Author

Thanks for testing and the catch @SnailBones ! I'll close that tentative fix for now, until we find a more appropriate one as it's still possible to trigger that issue when zooming in before the terrain is loaded (resulting in the camera being below ground).

@karimnaaji karimnaaji closed this Feb 2, 2022
@karimnaaji karimnaaji changed the title Do not constraint camera when DEM data isn't available yet Do not update camera zoom when DEM data isn't available yet Feb 18, 2022
Copy link
Contributor

@SnailBones SnailBones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @karimnaaji!

A few nits: thoughts on changing the variable names to make the code more clear?

For instance, cameraZoom could perhaps be cameraHeight since zoom suggests a relationship to map zoom.

And perhaps _updateCameraOnTerrain could be called _resetCameraIfNoTerrain.

The unit tests look great. Have you looked into render tests for this? Would it be possible to simulate the case that was causing this bug by placing the camera at high pitch and zoom and loading terrain after a wait?

@karimnaaji
Copy link
Contributor Author

karimnaaji commented Feb 22, 2022

For instance, cameraZoom could perhaps be cameraHeight since zoom suggests a relationship to map zoom.

That's a good point, cameraZoom is a bit of a misleading name. It is the zoom based on MSL (Mean Sea Level), which is also the default zoom when terrain is disabled. When terrain is enabled, the default zoom (transform._zoom) is the zoom at the center point, which accounts for the altitude at this given point. I've renamed it to be seaLevelZoom to better reflect the reference point.

And perhaps _updateCameraOnTerrain could be called _resetCameraIfNoTerrain.

Hmm 🤔 I've kept _updateCameraOnTerrain as it is more generic about what this function does. I found _resetCameraIfNoTerrain less clear, as it may only reflect one branch of that function.

The unit tests look great. Have you looked into render tests for this? Would it be possible to simulate the case that was causing this bug by placing the camera at high pitch and zoom and loading terrain after a wait?

Good call, although I think the unit test to be enough in that particular instance. The original issue is network-dependent and more difficult to recreate in a render test the way it is done in the unit test without introducing flakiness. Render tests are a better fit for visual testing or to be on-par with gl-native rather than a fine-grained data order/network testing.

Copy link
Contributor

@SnailBones SnailBones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the change to _seaLevelZoom, LGTM!

@karimnaaji karimnaaji merged commit 8e13b51 into main Feb 22, 2022
@karimnaaji karimnaaji deleted the karim/onx-fix branch February 22, 2022 20:03
astojilj pushed a commit that referenced this pull request Mar 9, 2022
Fixes issues when camera center would not change altitude if exaggeration changed and that camera could appear under terrain.

Similar to #11461, the customer was affected (https://github.com/mapbox/mapbox-maps-android-internal/issues/850) by camera moved underground when animating exaggeration, increasing it from 0 in high altitude areas. In such an use case, we didn't adjust center and camera MSL altitude with exaggeration change.

Extended usage of Transform._centerAltitudeValid to renamed _centerAltitudeValidForExaggeration: while data is not available, _centerAltitudeValidForExaggeration is 0. As soon as center elevation is available, new value for _centerAltitudeValidForExaggeration would trigger camera altitude adjustment in updateElevation.
karimnaaji pushed a commit that referenced this pull request Mar 11, 2022
* Fix camera under terrain when exaggeration changes

Fixes issues when camera center would not change altitude if exaggeration changed and that camera could appear under terrain.

Similar to #11461, the customer was affected (mapbox/mapbox-maps-android-internal#850) by camera moved underground when animating exaggeration, increasing it from 0 in high altitude areas. In such an use case, we didn't adjust center and camera MSL altitude with exaggeration change.

Extended usage of Transform._centerAltitudeValid to renamed _centerAltitudeValidForExaggeration: while data is not available, _centerAltitudeValidForExaggeration is 0. As soon as center elevation is available, new value for _centerAltitudeValidForExaggeration would trigger camera altitude adjustment in updateElevation.

* Fog demo: change exaggeration by pitch and zoom options

Added exaggeration change on zoom (issue  #11044 is still open) and pitch (bug #11589) to fog demo.

Fixes: #11589

Co-authored-by: Aleksandar Stojiljković <aleksandar.stojijkovic@mapbox.com>
ahocevar pushed a commit to ahocevar/mapbox-gl-js that referenced this pull request Mar 23, 2022
* Fix camera under terrain when exaggeration changes

Fixes issues when camera center would not change altitude if exaggeration changed and that camera could appear under terrain.

Similar to mapbox#11461, the customer was affected (https://github.com/mapbox/mapbox-maps-android-internal/issues/850) by camera moved underground when animating exaggeration, increasing it from 0 in high altitude areas. In such an use case, we didn't adjust center and camera MSL altitude with exaggeration change.

Extended usage of Transform._centerAltitudeValid to renamed _centerAltitudeValidForExaggeration: while data is not available, _centerAltitudeValidForExaggeration is 0. As soon as center elevation is available, new value for _centerAltitudeValidForExaggeration would trigger camera altitude adjustment in updateElevation.

* Fog demo: change exaggeration by pitch and zoom options

Added exaggeration change on zoom (issue  mapbox#11044 is still open) and pitch (bug mapbox#11589) to fog demo.

Fixes: mapbox#11589

Co-authored-by: Aleksandar Stojiljković <aleksandar.stojijkovic@mapbox.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants