Skip to content
This repository has been 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

Closed
picciano opened this issue Mar 23, 2016 · 9 comments
Closed

Usage question: How to refresh map using layer with custom data? #4446

picciano opened this issue Mar 23, 2016 · 9 comments
Labels

Comments

@picciano
Copy link

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?

Thanks much!
Tony

simulator screen shot mar 23 2016 4 40 38 pm

@1ec5 1ec5 added iOS Mapbox Maps SDK for iOS feature labels Mar 23, 2016
@1ec5
Copy link
Contributor

1ec5 commented Mar 23, 2016

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.

@picciano
Copy link
Author

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
Copy link
Contributor

1ec5 commented 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
Copy link

mb12 commented 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
Copy link
Contributor

@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.

@jfirebaugh jfirebaugh added support and removed feature iOS Mapbox Maps SDK for iOS labels Mar 23, 2016
@picciano
Copy link
Author

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=300

@jfirebaugh
Copy link
Contributor

s-maxage is for CDNs and other intermediary caches. It is not used by Mapbox GL.

@haydenkaizeta
Copy link

Any progress on this? I have the exact same requirements but on Android

@jfirebaugh
Copy link
Contributor

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.)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants