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

Make Geocoder terrain-aware #6876

Merged
merged 4 commits into from
Aug 3, 2018
Merged

Make Geocoder terrain-aware #6876

merged 4 commits into from
Aug 3, 2018

Conversation

mramato
Copy link
Contributor

@mramato mramato commented Aug 2, 2018

Previously, if a GeocoderService returned a single point, the geocoder would slam into the ground as close as possible. If the service returned a rectangle, it would only work with when the rectangle height did not include large elevation changes (and slam into the ground otherwise).

This change queries the 4 corners and center of the rectangle (if the terrain supports it) and adjusts the geocoder final position height to be above terrain.

This is easy to test by zooming to Grand Canyon, AZ or Mount Everest, China with terrain on. In master the behavior is terrible.

We could eventually pull some of this logic out into a separate helper function, but I figured I'd start small and we can do that if we need to do similar calculations elsewhere.

Fixes #6854

Previously, if a GeocoderService returned a single point, the geocoder
would slam into the ground as close as possible. If the service returned
a rectangle, it would only work with when the rectangle height did not
include large elevation changes (and slam into the ground otherwise).

This change queries the 4 corners and center of the rectangle (if the
terrain supports it) and adjusts the geocoder final position height to
be above terrain.
@cesium-concierge
Copy link

cesium-concierge commented Aug 2, 2018

Thanks for the pull request @mramato!

  • ✔️ Signed CLA found.
  • CHANGES.md was not updated.
    • If this change updates the public API in any way, please add a bullet point to CHANGES.md.

Reviewers, don't forget to make sure that:

  • Cesium Viewer works.
  • Works in 2D/CV.
  • Works (or fails gracefully) in IE11.

I am a bot who helps you make Cesium awesome! Contributions to my configuration are welcome.

🌍 🌎 🌏

@mramato
Copy link
Contributor Author

mramato commented Aug 2, 2018

Yep, definitely doesn't work in 2D or Columbus View, thanks @cesium-concierge!

@mramato
Copy link
Contributor Author

mramato commented Aug 2, 2018

OK, updated CHANGES and fixed 2D/CV, this is ready for review.

@mramato
Copy link
Contributor Author

mramato commented Aug 3, 2018

@bagnell since this is largely camera related, can you review?

@bagnell
Copy link
Contributor

bagnell commented Aug 3, 2018

👍

@bagnell bagnell merged commit 71696ef into master Aug 3, 2018
@bagnell bagnell deleted the geocoder-terrain branch August 3, 2018 19:48
if (defined(availability)) {
var cartographics;

cartographics = [
Copy link
Contributor

Choose a reason for hiding this comment

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

@mramato These don't need to be on two separate lines but oh well. And shouldn't you use result parameters throughout this? I know it won't really impact performance but it's still a good habit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We use result parameters as a necessary evil for performance in hot areas of the code. Not using them makes the code cleaner and is perfectly OK if performance is not going to be an issue.

@hpinkos
Copy link
Contributor

hpinkos commented Aug 3, 2018

This give drastically different result when there is and is not terrain. I think it's because you're multiplying the max height by 2. I think you want to add a constant height to it instead.

Without terrain:
image

With terrain:
image

@hpinkos
Copy link
Contributor

hpinkos commented Aug 3, 2018

The pelias geocoder sometimes returns a bounding box where east === west and south === north. For example, type of Paghman Palace, Afghanistan

You should apply the same offset you did for a point destination.

// directly into the ground, even when not using terrain.
if (destination instanceof Cartesian3) {
var carto = ellipsoid.cartesianToCartographic(destination);
var offset = CesiumMath.toRadians(0.001);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not convinced this is the right thing to do. The rectangle covers a larger area closer to the equator than the poles so the camera destination will have a greater height at the equator. From experimenting, the camera height at the equator is around 500m and at the poles it's 350m.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I agree. I was just moving code over from PeliasGeocoder and the thought just didn't occur to me. Instead I'm going to apply a fixed offset of 500m to any single point rather than expanding it into a rectangle at all. I'll still query the terrain at that single point, so it will still adjust properly and this will make for consistent zooming with and without terrain.

@mramato
Copy link
Contributor Author

mramato commented Aug 4, 2018

The pelias geocoder sometimes returns a bounding box where east === west and south === north. For example, type of Paghman Palace, Afghanistan

You should apply the same offset you did for a point destination.

Good catch.

@mramato
Copy link
Contributor Author

mramato commented Aug 4, 2018

Opened #6881, thanks for the additional review @hpinkos!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Geocoder slams into terrain
4 participants