-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Preloading tiles for camera animation #11328
Conversation
That's a nice approach! One thing I noticed if we analyze the video is that at:
That means we're left with no visual feedback for about 2.5 seconds after you interacted with the map. I assume this was on a fast network, so possibly the optimistic case. Could you try the same with simulated slow mode or on mobile network? I wonder if this idea could also be extended to improve the default use case to benefit more users (when not setting explicit option to The above wouldn't always ensure that all tiles are always downloaded, but redistributes the work we know we will have to do ahead of time. |
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.
Per discussion in a call: first of all, this looks awesome, and I'd use it extensively myself — especially for demo video recordings through our debug/video-export.html
page. Especially impressive how little code it takes for a substantial feature!
The main thing it's missing right now is being able to separate the two stages — preloading and animation. One option that comes to mind is to make it so that if preload: true
is set, flyTo
will only do preloading without animating afterwards — then you can do await map.once('idle')
to wait until all tiles load, do something (e.g. start the video recording), and then call flyTo
again with the same options but preload: false
so that the actual animation happens.
Also, if we're going with this route, for consistency, all other camera movement methods like easeTo
will need to support the option. Maybe we could even enable the "preload bbox" use case by supporting it for instant methods like jumpTo
.
I've separated the preloading and animation stages. The You can use map.flyTo({center: [-119.5375, 37.7425], preload: true});
map.easeTo({center: [-119.5375, 37.7425], preload: true});
map.fitBounds([[-122.4943, 37.7247], [-122.34, 37.82]], {padding: 20, preload: true}); After the map finishes preloading, it becomes map.flyTo({center: [-119.5375, 37.7425], preload: true});
await map.once('idle');
map.flyTo({center: [-119.5375, 37.7425]}); You can also achieve preloading tiles for an arbitrary region with: map.jumpTo({center: [-119.5375, 37.7425], zoom: 8, preload: true});
await map.once('idle');
map.jumpTo({center: [-119.5375, 37.7425], zoom: 8}); This PR also introduces optimization for |
@stepankuzmin 👍 I think those last changes are great and give quite some flexibility. One concern about the API, when I read
I expect the original behavior of this PR (e.g. executes a flyTo after preloading, or while preloading?), instead of the current behavior of only preloading without executing the flyTo. That seems ambiguous. Instead, what do you think of the following:
This has two advantages:
Any thoughts on that? |
This feels a little Java-esque to me, and has no similarly structured methods elsewhere in the API. How about keeping the option by rename to |
preloadOnly works with me, the option Object extension is a good way to go forward if we ever need to. |
I like the idea of the renaming option to Also, I was thinking about sequential animations — when you move from one view to another and so on. We can create an API that allows users to define a list of animations between different views. Say jump to the initial animation point, then fly to the next point, ease to another, etc. What do you think about this approach as a next step? I think we can consider this after the initial implementation. |
Yeah, I thought about it too. Maybe a method to return a await map.preload().flyTo(...).easeTo(...).zoomTo(...).finish(); |
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.
This looks awesome overall. My only reservations are that we should make sure:
- That CPU performance isn't hit by cloning so many transforms at once (e.g. it recalculates all matrices on
clone
). - That there will be no race conditions due to different methods of loading tiles. E.g. if we ask to preload the last transform, then the animation finishes before preload finishes, do we request the same tiles in parallel?
Co-authored-by: Vladimir Agafonkin <[email protected]>
Co-authored-by: Vladimir Agafonkin <[email protected]>
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.
Looks good. Could you add that new page as part of release testing in https://github.com/mapbox/mapbox-gl-js/tree/main/test/release before merging? It'll help testing that feature when we do the release.
Just a tiny sneak peek of the feature. I used "fast 3G" throttling to make the distinction clearer iphone-x-fast-3g-comparison-with-full-preload-small.mp4 |
Launch Checklist
This PR adds the
preload
option toMap#fitBounds,
andMap#flyTo,
allowing deferring animation until all tiles along the easing path are loaded.fit-bounds-with-preload.mov
@mapbox/gl-native
if this PR includes shader changes or needs a native portmapbox-gl-js
changelog:<changelog></changelog>