-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Ability to pass JSON style as a string (rather than a URL) #6335
Comments
I can't speak for the Android SDK, but with the latest iOS SDK 3.4.0 alpha, you can save that JSON file to a file (say, in the Caches folder) and refer to it by an absolute file URL. Another option is to bundle those three styles (and potentially their resources) in the application's resource bundle and refer to them by relative URLs. This works in released versions of the iOS SDK, as well as on Android by putting the styles in the APK. (If you do bundle resources like the sprite sheet alongside the style like this, be sure to refer to them in the style JSON with asset: URLs (like The core library does support setting a JSON string as the style, and indeed the iOS SDK did support that in the early days, but we removed it for maintainability reasons (too many different code paths for populating the map with content). I think we'd like to avoid restoring that API if at all possible, to avoid extra serialization or deserialization, but also because the SDK strives to be as object-oriented as possible. If neither of the two approaches above – absolute file URL or relative URL – works for your use cases, we'd love to find out why. |
Saving the JSON to a file should work perfectly. The documentation made it clear to me that |
OK, good to hear. Let’s track the Android side in #6273 then. (By the way, on iOS/macOS, you can simply use the |
Oh, and I forgot the best approach that works in the released versions of both SDKs. 😆 You may be able to use the offline map API to download the styles and all their resources – crucially, including the vector tile data – for offline usage. |
Platform: iOS and Android
I'm storing style JSON in a document database. Using the database's API I can retrieve the style JSON, but there doesn't appear to be a way to use that style JSON in the SDK if it isn't a URL. Have you considered supporting passing the JSON as a string on the iOS and Android SDKs (or possibly a dictionary)?
Another use case I need this for is for pre-fetching style JSON while I have a connection. When my app launches, and has internet connection, I want it to grab 3 different styles (modified versions of streets, dark, and satellite streets), and store them for later use if the user switches to one of them while offline.
The text was updated successfully, but these errors were encountered: