nitaliano / react-native-mapbox-gl

A Mapbox GL react native module for creating custom maps
Other
2.16k stars 697 forks source link

[Android] Offline Map Icons #1571

Open atomheartother opened 5 years ago

atomheartother commented 5 years ago

Hello all,

I'm attempting to have custom icons for a SymbolLayer displayed on a map that's been downloaded for offline use. Here are the results I'm getting when I try to display the offline map, that is when I've downloaded the map in the background without displaying the map online, cut the internet then get on the map screen:

So... 3 different behaviors depending on how I include this icon, and none of them actually work offline. Has anyone here managed to have custom icons work on an offline map?

I'm on the master branch.

kristfal commented 5 years ago

Hey,

We’ve successfully run custom styles with offline. There are some things we’ve learned:

Make sure the style you use for offline pack contains all the sprites and fonts that you expect to use while offline. For instance, we heavily rely on runtime styling and add new icons/fonts on the fly. As a result, the custom style.json we use contain “dummy” layers that references all the fonts and sprites we use at runtime.

I highly recommend that you build your own sprite sheet with the icons you need and build your own style.json for offline use. That will give you full control of what is available while offline.

So to follow up, do you use any fonts with your custom layer(s)? If so, does these fonts render while you are offline?

atomheartother commented 5 years ago

Thanks for the reply. Yes, we use custom fonts in our SymbolLayer, the fonts render just fine, it's simply the icons that don't.

You mention a style.json, I assume you mean you guys are using a custom JSON style file as opposed to a style URL? I've never tried that, I'll do it and see if it makes a difference.

I'll definitely try the dummy layer idea, it might force the offline packager to download these assets

atomheartother commented 5 years ago

After experimenting a bit more, it looks like no icons ever load with a style url, it's not just my custom icons but even the ones for bus stops, etc, built into the style. So I guess moving to a style.json might be the only choice...

kristfal commented 5 years ago

To me it sounds like something is wrong here.

Are you able to just use a plain basemap (without custom layers) offline?

Also, do make sure that you use the exact same style for the offline pack and for the MapView.

atomheartother commented 5 years ago

I use a single mapbox URL for everything yes, I just double-checked.

After you asked about basemaps, I tried this:

I also just tried to use a style.json offline but it never starts downloading, with styleUrl=asset://style.json the style displays online properly but it seems to never actually start downloading with the offlinemanager, I'll report back when I have more.

kristfal commented 5 years ago

This is the issue:

but my runtime SymbolLayer icons sre still nowhere to be found.

You need to ensure that the icons you add at runtime are statically declared in the style you download. I've never tried to load a style.json from assets:// but doing this from a remote server works just fine.

atomheartother commented 5 years ago

Sorry for the delay, I'm coming back to this issue after i had to divert to my attention to more pressing features.

@kristfal that's what I've been doing all along, However after making a small testing app I can confirm this module does behave as expected, i'll be looking into it but it's likely the error comes from my app.

atomheartother commented 5 years ago

I am reopening this as I have found what was causing it and I do believe it's related to the library. When testing this issue, you need to have a textField property set on the style you're using for the symbolLayer. Then the bug will manifest as I've described.

I've made a demo app to test and show off this bug: https://github.com/atomheartother/mapboxBugTest

And now to prove the textField is responsible:

This test app, I believe, uniquely identifies the sources of this bug, since it's as minimal as possible, so here are the factors that I think cause this:

armnugraha commented 4 years ago

hai i have same problem about this, i have symbol layer not show in offline mode. any solution ?

Kayre-Scott-Primon commented 3 years ago

Im having the same problem too, any suggestion for solve this?