3

I need to load custom map tiles into my UWP Bing Maps app, and I need to load them from ApplicationData.Current.LocalFolder.

What happens is that tiles are not loaded and the map is completely black.

While doing some troubleshooting I noticed that tiles from app package were loaded fine, and the issue was related to LocalFolder and LocalCacheFoler only.

So what I did was to copy the same image from app package to local folder (I'm copying to the correct one, even tested with images generated at runtime and stored in LocalFolder) and use this code as tile source:

var localTileSource = new LocalMapTileDataSource();
localTileSource.UriRequested += async (s, e) =>
{
    var deferral = e.Request.GetDeferral();                                                           
    e.Request.Uri = (new Random().NextDouble() < 0.5) ? new Uri("ms-appdata:///local/background.png") : new Uri("ms-appx:///Assets/background.png");
    deferral.Complete();
};

and this is what happens:

enter image description here

As you can see, local tiles are not loaded and thy're plain black while the very same file inside app package is loaded correctly.

Does anyone know what's going on?

StepTNT
  • 3,867
  • 7
  • 41
  • 82

2 Answers2

3

Thanks for your feedback. It seems there is some problem when providing a custom source that points to app's local storage for LocalMapTileDataSource. We've reported this issue internally and I will update my answer once there is any progress.

Besides, LocalMapTileDataSource can load tiles from local storage. We can specify the Uri in the constructor of LocalMapTileDataSource like following:

LocalMapTileDataSource localTileSource = new LocalMapTileDataSource("ms-appdata:///local/background.png");

Or set the UriFormatString like:

LocalMapTileDataSource localTileSource = new LocalMapTileDataSource();
localTileSource.UriFormatString = "ms-appdata:///local/background.png";

In these ways, you should be able to load tiles from local app data.

Jay Zuo
  • 15,653
  • 2
  • 25
  • 49
  • Thanks for the reply. I know how to set `UriFormatString`, the code in the OP was just an example. The real case scenario was related to building a custom tile renderer, so I'm generating tiles in the `UriRequested` handler and I'm saving them in cache to re-use them later. If I save them to `LocalData` everything's fine, but they shouldn't be added to OneDrive backup and that's why I needed to save them into `LocalCache`. – StepTNT Sep 14 '16 at 11:28
  • 1
    @StepTNT Thank you for your feedback, we have logged this issue internally and the related team is investigating it. – Franklin Chen - MSFT Oct 03 '16 at 03:45
  • @FranklinChen-MSFT Was this issue ever fixed? – JKennedy Nov 23 '16 at 16:33
0

For your scenario, why don't you try using a CustoMapTileSource? Instead of writing tiles to the cache folder and supplying the URI to a LocalMapTileDataSource, you can just supply the bitmap directly.

Duncan Lawler
  • 1,772
  • 8
  • 13