Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

iOS: No longer able to load local Sprite resources #1208

Closed
picciano opened this issue Apr 6, 2015 · 13 comments · Fixed by #3087
Closed

iOS: No longer able to load local Sprite resources #1208

picciano opened this issue Apr 6, 2015 · 13 comments · Fixed by #3087
Assignees
Labels
iOS Mapbox Maps SDK for iOS

Comments

@picciano
Copy link

picciano commented Apr 6, 2015

I am setting a custom style in my app, as follows:

NSString *jsonFile = [[NSBundle mainBundle] pathForResource:@"tallygo-v7" ofType:@"json"];
NSURL *styleURL = [NSURL URLWithString:[NSString stringWithFormat:@"asset://%@", jsonFile]];
[self.mapView setStyleURL:styleURL];

However, the sprite sheet (in the app bundle) is no longer loading. This URL was working in previous versions by inserting the URL into the raw JSON at runtime, but is now no longer found:

asset:///Users/picciano1/Library/Developer/CoreSimulator/Devices/7A8973A8-E8B6-4D23-85BE-25B92FBC0067/data/Containers/Bundle/Application/4ECBD40F-A759-4279-AC15-C5D1C20B4316/TallyGo.app/tallygo

The files are located at the root level of the main bundle. I have tried various paths without success:

asset://tallygo
asset:///tallygo
tallygo

I have even tried hard-coding the absolute path above into the style JSON.

Is there any way to do this now?

@1ec5
Copy link
Contributor

1ec5 commented Apr 6, 2015

The asset: URL scheme looks inside MapboxGL.bundle due to #1012. To point inside your app’s main bundle, you should be able to pass in a relative or absolute path to it. Does that work for you?

@1ec5 1ec5 added the iOS Mapbox Maps SDK for iOS label Apr 6, 2015
@picciano
Copy link
Author

picciano commented Apr 6, 2015

I have tried that and it no longer seems to be working. Note that I am referring to the Sprite assets, not the style JSON. The style is loading, however, the Sprite assets are not.

@jfirebaugh jfirebaugh modified the milestone: iOS Beta 1 Apr 6, 2015
@1ec5 1ec5 self-assigned this Apr 6, 2015
@1ec5
Copy link
Contributor

1ec5 commented Apr 6, 2015

You’re right, none of this is working correctly right now. As far as the GL backend is concerned, there can only be HTTP(S) URLs backed by HTTPRequestImpl and asset: URLs backed by AssetRequestImpl. (mapbox: URLs are normalized to HTTP in mbgl::util::mapbox::normalizeURL().) Passing in a file: URL trips an assertion in HTTPRequestImpl::handleResult(), but of course we shouldn’t be in there anyways.

Passing in an asset: URL doesn’t work either because AssetRequestImpl assumes mbgl::platform::assetRoot() to be its root. #1012 changed that root from the app bundle to MapboxGL.bundle, which is where we put various things like the compass image.

@1ec5
Copy link
Contributor

1ec5 commented Apr 7, 2015

@picciano To answer your specific situation, where did you put your sprite JSON and how did you name it? If the style JSON has style set to asset://tallygo, Sprite expects the sprite JSON to exist at MapboxGL.bundle/tallygo.json or MapboxGL.bundle/[email protected], with the sprite sheet in the same place (.png instead of .json).

@1ec5
Copy link
Contributor

1ec5 commented Apr 7, 2015

(As a temporary workaround, you can also dig yourself out of MapboxGL.bundle with a bunch of ../’s, but obviously we need a way to specify relative local paths.)

@picciano
Copy link
Author

picciano commented Apr 7, 2015

I put the style JSON and sprite files at the root level of the main application bundle.
tallygo-v7.json
tallygo.json
tallygo.png
[email protected]
[email protected]

I just tried asset://../tallygo and that worked. Good workaround. Is this captured somewhere else? Or should we leave this issue open until a real fix is in place?

screen shot 2015-04-07 at 5 11 14 pm

@1ec5
Copy link
Contributor

1ec5 commented Apr 7, 2015

Let’s leave this issue open.

@incanus incanus modified the milestones: iOS Beta 2, iOS Beta 1 Apr 29, 2015
@1ec5 1ec5 removed this from the iOS Beta 2 milestone Jun 1, 2015
@incanus
Copy link
Contributor

incanus commented Jun 1, 2015

This has a workaround and is not critical for b2.

@incanus
Copy link
Contributor

incanus commented Sep 15, 2015

I am seeing style assets at the app bundle root working fine as asset://foo.json currently.

@incanus
Copy link
Contributor

incanus commented Sep 15, 2015

Ah, we do have differing code paths based on the Mapbox SDK integration method. What I mentioned above only works in the Mapbox GL.app test app, but when, say, you use Swift and CocoaPods, Xcode assembles the Foo.app and Mapbox.framework build products dynamically and the paths are different.

@friedbunny
Copy link
Contributor

The ../ path traversal workaround no longer works. Workaround for the workaround is to use HTTP(S) URLs.

@picciano
Copy link
Author

This is no longer an issue for us since we can now use client-side images for annotations. Much better than custom sprite sheets!

@1ec5
Copy link
Contributor

1ec5 commented Oct 30, 2015

This is no longer an issue for us since we can now use client-side images for annotations.

This is definitely the way to go nowadays if you want custom images.

@1ec5 1ec5 closed this as completed Oct 30, 2015
1ec5 added a commit that referenced this issue Nov 20, 2015
As of #2746, we no longer bundle any styles with the SDK, so the asset: URL scheme is unused. Instead, point asset: to the application root for developer convenience and consistency with the Android and default asset roots. Also fixed an issue that prevented relative URLs from being treated as asset: URLs.

Fixes #1208, fixes #3050.
1ec5 added a commit that referenced this issue Nov 20, 2015
As of #2746, we no longer bundle any styles with the SDK, so the asset: URL scheme is unused. Instead, point asset: to the application root for developer convenience and consistency with the Android and default asset roots. Also fixed an issue that prevented relative URLs from being treated as asset: URLs.

Fixes #1208, fixes #3050.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
iOS Mapbox Maps SDK for iOS
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants