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.

Offline maps #584

Closed
Closed

Description

@ljbade

It is a personal goal to have the ability to view maps without needing an Internet connection.

Very useful for activities such as bushwalking our mountain biking.

Plus we know there are others interested in this feature too.

Activity

  1. added
    Android
    on Nov 10, 2014
  2. ljbade commented on Nov 11, 2014

    @ljbade
    ContributorAuthor

    Some discussion I had with @kkaefer about what was needed for offline maps:

    • native core does not yet support support offline maps - on roadmap
    • The cache sqlite DB can be reused for storing tiles offline
      • need to add ability to swap out the cache database and set it to a read-only mode
    • need a tool that builds an offline database that can be distributed with the app/downloaded
    • could also download all individual tiles on first launch, however this is not good strategy
    • could be useful to have a way to differentially update only the tiles that have been changed. Like some sort of patch DB, that has higher priority than main DB, and can eventually be somehow merged into the main DB.

    First things to work on:

    1. enable offline storage in cache DB
    2. create a tool to export a map to a cache DB
  3. removed
    Android
    on Nov 11, 2014
  4. incanus commented on Nov 11, 2014

    @incanus
    Contributor

    Removing label & editing title — this isn't specific to Android.

    We've accomplished a lot of this in past across various toolsets on both iOS and Android.

  5. changed the title [-]Offline maps on Android[/-] [+]Offline maps [/+] on Nov 11, 2014
  6. changed the title [-]Offline maps [/-] [+]Offline maps[/+] on Nov 11, 2014
  7. ljbade commented on Nov 12, 2014

    @ljbade
    ContributorAuthor

    MBTiles is a spec for raster or vector tiles as blobs in SQLite with a known format and metadata table. This is used for prebunding offline maps with an app. It's not designed for adding to later, but could be remedied in some way if this seems like a good idea.

    Being able to push out small update datasets will be needed if people start creating maps of whole countries, e.g. topo maps for all of Australia or NZ cause it will be annoying to redownload hundreds of MBs of map data every time the dataset gets updated (NZ updates their topo data monthly)

  8. ljbade commented on Nov 12, 2014

    @ljbade
    ContributorAuthor

    It can be a good strategy, depending on usage, and becomes much more viable with vector tiles than raster.

    True keep forgetting that vector data is a lot smaller.

  9. ljbade commented on Nov 23, 2014

    @ljbade
    ContributorAuthor

    Perhaps as a first step, we could add support for pre-caching a bbox + zoom level of data?

  10. ljbade commented on Nov 23, 2014

    @ljbade
    ContributorAuthor

    Some ideas of minimum functionality:

    • function to calculate number of tiles needed for given bounding box and zoom range
    • function to start offline caching - will take bbox, zoom max & min, some sort of callback/interface to receive progress notifications
    • notification that receives - total number of tiles, tiles downloaded so far, number of failures (and possibly list of the failures), overall finished & successful indication
  11. ljbade commented on Nov 23, 2014

    @ljbade
    ContributorAuthor

    After a quick look through the code here is a strategy:

    • build list of all Sources needed for each layer
    • for each Source tell it to fetch all needed TileData
    • ensure TileData downloads and saves data into SQLiteStore via FileSource/HTTPRequest
    • disable cache expiry check in HTTPRequest
    • ???
  12. ljbade commented on Nov 23, 2014

    @ljbade
    ContributorAuthor

    We will also need to save in cache:

    • Style JSON
    • Tile source JSON
    • PNGs for styles

    Is there anything else needed to be downloaded to render a map?

  13. ljbade commented on Nov 23, 2014

    @ljbade
    ContributorAuthor

    Hmm, going to take me a while to figure out how to do this tidily.

    Suggestions?

  14. incanus commented on Nov 24, 2014

    @incanus
    Contributor

    Perhaps as a first step, we could add support for pre-caching a bbox + zoom level of data?

    We have built this out pretty robustly on iOS, so that's a good starting spot.

    iOS SDK

    In RMTileCache:

    Estimates

    -tileCountForSouthWest:northEast:minZoom:maxZoom:

    Start/stop

    -beginBackgroundCacheForTileSource:southWest:northEast:minZoom:maxZoom:
    -cancelBackgroundCache

    Progress

    -tileCache:didBeginBackgroundCacheWithCount:forTileSource:
    -tileCache:didBackgroundCacheTile:withIndex:ofTotalTileCount:
    -tileCacheDidFinishBackgroundCache:
    -tileCacheDidCancelBackgroundCache:

    Storage format is a SQLite-based common store keyed on tile source, per the convention of the upstream project that we built this SDK off of. This same cache is used for performance caching during online use as well as offline fallback.

    MBXMapKit

    In MBXOfflineMapDownloader:

    Start/stop

    -beginDownloadingMapID:mapRegion:minimumZ:maximumZ:
    -cancel
    -resume
    -suspend

    Estimates & Progress

    -offlineMapDownloader:stateChangedTo:
    -offlineMapDownloader:totalFilesExpectedToWrite:
    -offlineMapDownloader:totalFilesWritten:totalFilesExpectedToWrite:
    -offlineMapDownloader:didEncounterRecoverableError:
    -offlineMapDownloader:didCompleteOfflineMapDatabase:withError:

    Here we had a combination of a clean slate for how to do this along with integration with an existing Apple API. Storage format is again SQLite but offline maps are treated as atomic, immutable documents.

    We don't necessarily want to mirror the APIs to Java for any sort of undue parity, but these are some ideas. I think the idea of bounding box + zoom range, start/pause/cancel, and progress callbacks are the general model we want.

    However, we should also decide whether to do this at the C++ level in some core way.

    In my eyes, despite this being eventually important, it's far lower priority than general Android parity with current iOS tools + buildout of client side data (#507) so that mobile apps can start deploying on GL in the wild.

  15. 83 remaining items

  16. zugaldia commented on Jun 7, 2016

    @zugaldia
    Member

    @rm3dbeckers could you open a separate ticket to track this issue? Thanks for the feedback.

  17. kkaefer commented on Jun 9, 2016

    @kkaefer
    Member

    @rm3dbeckers asset:// URLs are already offline, so they shouldn't be stored in the cache.

  18. rm3dbeckers commented on Jun 9, 2016

    @rm3dbeckers

    The problem is that I don't have any tiles in the assets but just the style.json which I want to use to download tiles. But using asset:// urls for the styleURL seems to only work for the mapview itself, not for the OfflineTilePyramidRegionDefinition.

    btw: I've created an extra ticket at #5271 as requested.

  19. Stophface commented on Sep 29, 2017

    @Stophface

    Is there mbtiles for ios and/or android?

  20. nitrag commented on Sep 29, 2017

    @nitrag
    Contributor
  21. Stophface commented on Sep 29, 2017

    @Stophface

    @nitrag thanks for the fast reply. I am searching for ready-to-use mbtiles for iOS or android. Although for android a solution might be osmdroid.

  22. nitrag commented on Sep 29, 2017

    @nitrag
    Contributor
  23. songyuyang0918 commented on Mar 25, 2019

    @songyuyang0918

    Everybody is good! How does the latest IOS SDK load an offline map?
    I have my own mbTiles file and don't want to download it via MapBox.
    If there is a plug-in, please give me an address, thank you very much!

  24. ssshake commented on Dec 1, 2021

    @ssshake

    Sorry to be posting on an old issue but I'm not finding a clear answer on the state of this in 2021.

    We have a react native app using mapbox-gl-js so I'm realizing now I'm in the wrong repo. We have a need to pre-cache tiles for offline use as we are producing an app to be used on ipad by workers out in remote areas. They need to cache their tiles then go out to the job site.

    To complicate matters we also need this cache to be in an application group / shared storage. Which is an ios concept to allow 2 or more applications by the same vendor to access common data storage.

    We have two applications, one using mapbox-gl-js and the other using the unity mapbox SDK. The react native application needs to download and cache the tiles in shared storage. The unity application need to be able to access the offline tiles from shared storage.

    Any help indicating where to go would be very helpful as I'm finding the number of libraries/sdks for mapbox and the supported feature set between them to be quite unclear. Thanks!

  25. hjhimanshu01 commented on May 16, 2023

    @hjhimanshu01

    @ssshake, were you able to render maps in offline mode?

  26. ssshake commented on May 16, 2023

    @ssshake

    Yes (removed an essay about my specific issues as it's off topic)

  27. hjhimanshu01 commented on May 17, 2023

    @hjhimanshu01

    @ssshake, thanks for explaining, seems like quite an intricate solution you have got there. What I'm trying to achieve is related to 1), just to cache the tile data in a DB and read it later when offline, though I'm trying to achieve it in iOS using swift. Is it possible for you to just share some pointers on how did you cached those tiles and read it back in mapbox?

    Once again thanks for explaining it in so much detail, cheers!

  28. ssshake commented on May 17, 2023

    @ssshake

    Ah I see, sorry I thought you were a maintainer of this package trying to fix my issue.

    I'm using the react-native-mapbox-gl package but I would hope it has the same methods as the native mapbox GL. You need to create a "pack" and that is implicitly saved to the mapbox sqlite DB.

    Something like this:

        MapboxGL.offlineManager.setTileCountLimit(100000)
    
        await MapboxGL.offlineManager.createPack(
            {
                name: packName,
                styleURL: mapStyleUrl,
                minZoom: 8,
                maxZoom: 16,
                bounds: [
                    [furthest.east, furthest.north],
                    [furthest.west, furthest.south]
                ]
            },
            onProgress,
            errorListener
        )
    

    Where furthest is an object containing the lat/long bounds that you want. We use two arrays of longitudes and latitudes for all of the points on the map we care about. Then we just get the min and max to construct the bounds.

    {
            north: Math.max(...latitudes),
            east: Math.max(...longitudes),
            south: Math.min(...latitudes),
            west: Math.min(...longitudes)
    }
    

    I'm redacting some info in my prior comment because it's not helpful to getting my solution and is too off topic.

  29. hjhimanshu01 commented on May 18, 2023

    @hjhimanshu01

    Perfect, thanks for the info!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions