You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Usage question: How to refresh map using layer with custom data? #4446
We have created a custom map style that include traffic data displayed on the map. The data is refreshed every five minutes or so, but how do we get the map to reflect those changes? Is there a way to force the cache to be cleared and the map tiles reloaded or redrawn from the updated data?
The iOS SDK doesn’t currently have an API for refreshing the map. The OS X SDK’s MGLMapView has a -reloadStyle method that works by setting the style URL to a bogus value then back to the original URL. But that hits the cache instead of clearing it. We’ve previously had requests for a more thorough reload method for use cases like reloading after a connection failure (#3102) and live previewing while developing styles in Mapbox Studio. Per @jfirebaugh:
This will require cooperation and API additions from mbgl core and iOS bindings. The HTTP request to the Mapbox Style API needs to carry the fresh=true parameter in order to bypass CDN caches.
Can you explain a bit more what you mean by "works by setting the style URL to a bogus value then back to the original URL. But that hits the cache instead of clearing it"
Are you saying that if I set the style to something then switch it back that it would not clear the cache? Or is that a possible workaround I can use.
I’m not sure how reliable it is as a workaround. The osxapp demo app uses it solely for the purpose of forcing a reload after an access token change. But in your case, it sounds like you want the same style URL and the same sources to reload. Perhaps you could add a timestamp to the style URL to evade the cache with respect to the style, but I suspect that the vector tiles themselves would still hit the cache.
@1ec5 The in-memory cache is per Source. So if the client generates a style where in the source name for the traffic data is changed, it should ensure that the in-memory cache is not hit. For cache busting timestamp parameter, you probably meant tile url template (and not the style url).
@picciano It's not the style you need refreshed, it's the vector tiles or GeoJSON containing the data correct?
For all resources including vector tiles and GeoJSON resources, Mapbox GL obeys standard HTTP cache headers. If you serve your tiles with Cache-Control: max-age=300, Mapbox GL will revalidate them every five minutes, and show the new data if it has changed.
Tiles which refresh every five minutes should be served with Cache-Control: max-age=300. Mapbox GL will refresh tiles on the schedule specified by max-age. (Alternatively, you can use the Expires header if you want to specify an absolute time.)
Activity
1ec5 commentedon Mar 23, 2016
The iOS SDK doesn’t currently have an API for refreshing the map. The OS X SDK’s MGLMapView has a
-reloadStylemethod that works by setting the style URL to a bogus value then back to the original URL. But that hits the cache instead of clearing it. We’ve previously had requests for a more thorough reload method for use cases like reloading after a connection failure (#3102) and live previewing while developing styles in Mapbox Studio. Per @jfirebaugh:picciano commentedon Mar 23, 2016
Can you explain a bit more what you mean by "works by setting the style URL to a bogus value then back to the original URL. But that hits the cache instead of clearing it"
Are you saying that if I set the style to something then switch it back that it would not clear the cache? Or is that a possible workaround I can use.
1ec5 commentedon Mar 23, 2016
I’m not sure how reliable it is as a workaround. The osxapp demo app uses it solely for the purpose of forcing a reload after an access token change. But in your case, it sounds like you want the same style URL and the same sources to reload. Perhaps you could add a timestamp to the style URL to evade the cache with respect to the style, but I suspect that the vector tiles themselves would still hit the cache.
mb12 commentedon Mar 23, 2016
@1ec5 The in-memory cache is per Source. So if the client generates a style where in the source name for the traffic data is changed, it should ensure that the in-memory cache is not hit. For cache busting timestamp parameter, you probably meant tile url template (and not the style url).
jfirebaugh commentedon Mar 23, 2016
@picciano It's not the style you need refreshed, it's the vector tiles or GeoJSON containing the data correct?
For all resources including vector tiles and GeoJSON resources, Mapbox GL obeys standard HTTP cache headers. If you serve your tiles with
Cache-Control: max-age=300, Mapbox GL will revalidate them every five minutes, and show the new data if it has changed.picciano commentedon Mar 28, 2016
We are using custom data hosted by Mapbox for this.
Do you know if this respects the s-maxage value as well?
Cache-Control: max-age=43200,s-maxage=300jfirebaugh commentedon Mar 28, 2016
s-maxageis for CDNs and other intermediary caches. It is not used by Mapbox GL.haydenkaizeta commentedon Sep 21, 2017
Any progress on this? I have the exact same requirements but on Android
jfirebaugh commentedon Sep 21, 2017
Tiles which refresh every five minutes should be served with
Cache-Control: max-age=300. Mapbox GL will refresh tiles on the schedule specified bymax-age. (Alternatively, you can use theExpiresheader if you want to specify an absolute time.)