maplibre-gl-js icon indicating copy to clipboard operation
maplibre-gl-js copied to clipboard

Keep camera outside terrain

Open chrneumann opened this issue 1 year ago • 1 comments

Fix for #1542. Currently proof of concept, comments appreciated.

It uses the transformCameraUpdate functionality to validate the next camera position, possibly adjusting it. By using transformCameraUpdate, the changes can be kept small. The assigned function checks if the next camera position will be inside terrain. If that would be the case, the camera is moved up (keeping its center), so that it is above the terrain. The pitch is adjusted to keep the map's center. IMHO this leads to a good user experience. Tried other options (stopping the camera or just adjusting height), but this seems best.

Proof of concept: Needs some more testing. transformCameraUpdate type signature is changed to pass the whole transform. Might not be needed, did not look at this yet. If needed, an internal wrapper for transformCameraUpdate might be the solution.

Includes a temporary workaround for #4233.

Launch Checklist

  • [x] Confirm your changes do not include backports from Mapbox projects (unless with compliant license) - if you are not sure about this, please ask!
  • [ ] Briefly describe the changes in this PR.
  • [x] Link to related issues.
  • [ ] Include before/after visuals or gifs if this PR includes visual changes.
  • [ ] Write tests for all new functionality.
  • [ ] Document any changes to public APIs.
  • [ ] Post benchmark scores.
  • [ ] Add an entry to CHANGELOG.md under the ## main section.

chrneumann avatar Jun 19 '24 15:06 chrneumann

I think the approach presented here is a very elegant one. Thanks! This still needs some love and care, but otherwise a very good idea to solve this issue. Assuming we solve the questions raised in #4243

HarelM avatar Jun 19 '24 17:06 HarelM

Waiting for #4299 (fixes camera jumps) to be approved before polishing this PR.

chrneumann avatar Jul 10 '24 09:07 chrneumann

Generally, the linked PR looks like the right solution, so you can assume it will be merged, the only comments I have there are related to tests...

HarelM avatar Jul 10 '24 09:07 HarelM

Codecov Report

Attention: Patch coverage is 94.33962% with 3 lines in your changes missing coverage. Please review.

Project coverage is 87.55%. Comparing base (d9e75d2) to head (2b8f28b). Report is 202 commits behind head on main.

Files with missing lines Patch % Lines
src/ui/camera.ts 94.33% 0 Missing and 3 partials :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4300      +/-   ##
==========================================
- Coverage   87.77%   87.55%   -0.22%     
==========================================
  Files         246      246              
  Lines       33421    33446      +25     
  Branches     2206     2236      +30     
==========================================
- Hits        29334    29283      -51     
- Misses       3080     3134      +54     
- Partials     1007     1029      +22     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Jul 23 '24 09:07 codecov-commenter

Found more problems (fixed in https://github.com/maplibre/maplibre-gl-js/pull/4300/commits/f6bdf15fe07a039135755f38a231d54c40ced9c7) with the direct manipulation of the transform, which leads to jumps and other problems. One should keep in mind that there might be other places where the transform is manipulated directly instead of using the _getTransformForUpdate / _applyUpdatedTransform combo.

Moved the logic to the camera.

chrneumann avatar Jul 23 '24 13:07 chrneumann

This looks good! There are failing render tests though, please see if there's a need to update the expected image of the fog tests due to this fix.

HarelM avatar Jul 24 '24 16:07 HarelM

This looks good! There are failing render tests though, please see if there's a need to update the expected image of the fog tests due to this fix.

Yes, the pitch of the camera changed because the camera sits on the terrain surface instead of having the minimum distance to the surface. Changed the render images.

chrneumann avatar Jul 30 '24 13:07 chrneumann

Build size is bigger, I think that's fine?

chrneumann avatar Jul 30 '24 13:07 chrneumann

Yes, don't worry about it.

HarelM avatar Jul 30 '24 17:07 HarelM

the pitch of the camera changed because the camera sits on the terrain surface instead of having the minimum distance to the surface. Changed the render images.

Really? This seems strange... is the pitch this high? Are you sure the threshold is not too tight or something?

HarelM avatar Jul 30 '24 17:07 HarelM

Really? This seems strange... is the pitch this high? Are you sure the threshold is not too tight or something?

I removed the padding altogether. Makes code simpler and I don't think its needed at all for UX.

chrneumann avatar Aug 01 '24 12:08 chrneumann

Can you please add a changelog entry?

HarelM avatar Aug 01 '24 17:08 HarelM

Thanks!!

HarelM avatar Aug 02 '24 20:08 HarelM