Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
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

Closed

Description

@picciano

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

Activity

  1. added
    iOS
    on Mar 23, 2016
  2. 1ec5 commented on Mar 23, 2016

    @1ec5
    Contributor

    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.

  3. picciano commented on Mar 23, 2016

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

  4. 1ec5 commented on Mar 23, 2016

    @1ec5
    Contributor

    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.

  5. mb12 commented on Mar 23, 2016

    @mb12

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

  6. jfirebaugh commented on Mar 23, 2016

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

  7. added and removed
    iOS
    on Mar 23, 2016
  8. picciano commented on Mar 28, 2016

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

  9. jfirebaugh commented on Mar 28, 2016

    @jfirebaugh
    Contributor

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

  10. haydenkaizeta commented on Sep 21, 2017

    @haydenkaizeta

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

  11. jfirebaugh commented on Sep 21, 2017

    @jfirebaugh
    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions