Marco Montanari
Marco Montanari

Reputation: 114

Refreshing a source in order to update the visualized data

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

Upvotes: 3

Views: 5110

Answers (2)

dwweb0309
dwweb0309

Reputation: 104

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.

Upvotes: 1

Steve Bennett
Steve Bennett

Reputation: 126085

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.

Upvotes: 4

Related Questions