Return above-sea-level elevation from queryTerrainElevation + Pass lowered mercator matrix to custom layer #3854
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes #3736 without introducing breaking changes.
I think it would also be "the proper way" in terms of positioning custom layer objects.
Actually it creates changes to public API.
But I'll argue that they are non-breaking in a sense that all existing user-written code will work as before.
CHANGELOG.md
under the## main
section.Solution is to
queryTerrainElevation
(instead of returning this strange offset between the elevation of a given point and elevation of centerPoint).render()
method of a custom layer. "Lowered" means that mercator matrix is translated by the same Z distance as proj matrix. And this allows to use intuitive above-sea-level elevation to position custom layer objects.These 2 changes together ensure that:
Technically this PR changes the public API (queryTerrainElevation returns a different number + different matrix passed to
render
) but I believe that these 2 changes compensate each other, with all existing code working as before.That is, there is no change in how these values can be used.
So far the only sensible way to use them was to translate a given matrix by "x" (whatever is returned from queryTerrainElevation). From the user's POV, this "x" in itself was a meaningless number (some cryptic offset). And the Z component of the matrix (based on the elevation of the centerPoint) is meaningless too.
So it seems very unlikely that anyone uses them for anything other than translation of Z by x.
And this translation doesn't change, only now these values make more sense, "x" being just above-sea-level elevation. And we no longer need to explain this weird offset .
If this approach looks ok, I'll try add some tests about custom layer rendering.