Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refreshing a source in order to update the visualized data

Tags:

mapbox-gl-js

I am implementing a time based mvt service with data from different time periods and the possibility to navigate through that data. Based on the year the tile server sends an mvt of that specific timeframe and a coherent styling gives the visualization. I would need to be able to update the data (invalidate and reload) in the viewport without resetting the style (and as such avoiding the flicker effect) considering the changing date and not only the changing coordinates.

https://map.openhistorymap.org/867.906/4.320382571983785/49.43846097119561/6.200660841932859

like image 452
Marco Montanari Avatar asked Oct 24 '25 12:10

Marco Montanari


2 Answers

There seems to be a problem with the documentation, but the feature you want is apparently available in Mapbox-GL-JS within the last couple of months, according to this commit.

You should be able to do something like:

map.getSource('myvectortiles').setTiles(..)

or

map.getSource('myvectortiles').setSourceProperty(..)

to trigger an update. You may need to look at the source code for more details.

like image 150
Steve Bennett Avatar answered Oct 27 '25 03:10

Steve Bennett


If you just want to update tiles source url, you can just use setTiles function.

map.getSource('source-id').setTiles(['https://newtilesourceurl']);

This updates the source url and re-renders the layer.

like image 40
dwweb0309 Avatar answered Oct 27 '25 04:10

dwweb0309



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!