-
-
Notifications
You must be signed in to change notification settings - Fork 767
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
Method for cameraoptions from camera and center #1427
Conversation
Thanks for taking the time to do this! |
Thank you. It doesn't really matter. If it would take LngLat there would be the need for a 3rd parameter: cameraAltitude. |
The general API is around lat lng, so I prefer to keep it this way. I'm not even sure if mercator coordinates is actually exported publicly at this point, so I would feel better if the API will remain with latlng, and latitude. |
Bundle size report: Size Change: +258 B
ℹ️ View DetailsNo major changes |
Okay, done :) |
Thanks for your PR! Very useful :D. I created a route-flight test-page which uses your method. Basically it works great when using it with Regrads. Max |
Thank you Max. There actually was an error, because I forgot to add the toAltitude after changing to LngLat. |
When comment out:
the |
Another interesting usecase of this method would be: When the camera goes below terrain (f.e. during dragging), rise the camera above terrain, but let it look onto the same center-point. |
I think the freeze elevation was due to the fact that the camera was "giggling" when you moved the map around (i.e. the camera would go up when you go up a mountains and go down when you go down to a valley), I'm not sure though... |
yes you are right, but the freeze logic is implemented already in handler_manager.ts which handles the user-dragging interactions. |
created a new pull-request for the freezeElevation logic problem, so from my perspective this pull request is ready for merge. |
@@ -600,6 +600,13 @@ class Map extends Camera { | |||
return this._controls.indexOf(control) > -1; | |||
} | |||
|
|||
calculateCameraOptionsFromTo(from: LngLat, altitudeFrom: number, to: LngLat, altitudeTo?: number) : CameraOptions { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be tested as well?
Also there's a need to resolve conflicts. Thanks for taking the time to write this! |
I'll take a look at it tomorrow. I've been to a festival the last week and need today to recharge. |
Should be all done now. I added test cases for calling it on map with a stubbed terrain and additionally I added test cases for the returned zoom. Could you please take a look at it? Should I put constants for expectedZoom? Furthermore i covered an edge case (From the same as To => division by 0) by throwing an error and wrote a test for it. |
Please fix lint. |
What? My local Lint doesn't catch everything? :o |
@@ -774,6 +775,41 @@ abstract class Camera extends Evented { | |||
return this.fire(new Event('moveend', eventData)); | |||
} | |||
|
|||
/** | |||
* Calculates pitch, zoom and bearing for looking at @param newCenter with the camera position being @param newCenter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation needs improvement. The summary refers to params that don't exist. It's confusing that 'from' is referred to as a camera, but 'to' is referred to as a center. If I'm understanding correctly, 'from' is where the camera is located; 'to' is where it's pointing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to open a PR, it's easier to understand it this way :-) Docs can always be improved.
As requested in #1414 I created a method to calculate the cameraoptions from a given center and camera, which can then be used in jumpTo, flyTo and so on.
Sadly it's not easy to know if the new center would be visible (or if there's a mountain inbetween), as this requires a redraw of the coordsframebuffer. Also note, that the returned cameraOptions could be beyond the constraints.
Launch Checklist
maplibre-gl-js
changelog:<changelog></changelog>
.