-
-
Notifications
You must be signed in to change notification settings - Fork 825
Add refreshTiles() to map public API #5806
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
Conversation
This PR solves the following feature request, doesn't it? |
I believe so, now that I've added a source-global refresh option. |
There is a report about flashing tiles here: #415, does this PR solves the requested feature? |
I'm not sure. I've only tested with raster tiles. With raster tiles, I don't see any flashing and the refresh happens immediately. In my implementation, |
* Reload any currently renderable tiles that are match one of the incoming `tileId` x/y/z | ||
*/ | ||
refreshTiles(tileIds: Array<ICanonicalTileID>) { | ||
for (const id in this._tiles) { |
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.
Is it possible to do some .filter(...)
to the array to remove some indentation in this method?
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.
I removed some indentation without using filter
.
Added a minor nit-picking. |
I'm confident that this works in my use-case, which is raster tiles. I'm not confident that it works for vector tiles or geojson sources. |
In geojson you can simply update the data and it will reload I believe, for vector I hope it will work as expected. |
Nice! I might give it a test with vector tiles... |
This PR adds
refreshTiles()
to the map public API.This allows tiles to be force-reloaded from outside MapLibre. The use case I've got in mind is that when tiles on the server change, a WebSocket message is sent to the client (using a to-be-developed plugin) notifying it of changed tiles. The plugin can then call
map.refreshTiles()
with the modified tile IDs, causing the map to reload the tiles and display the new data.You can check out a demo here. Clicking on a tile will call
map.refreshTiles()
on the tile. I'm usingaddProtocol()
to draw a timestamp (fromperformance.now()
) on each tile, representing the time it was loaded. Zoom all the way out to see that it behaves correctly for wrapped tiles (all tiles sharing an x/y/z are updated when a tile is clicked). Zoom past z3 to see that it behaves correctly for overscaled tiles.Marginally related to #5799, which is also intended to help with the use case where server-side data is changing rapidly.
CHANGELOG.md
under the## main
section.