StepTNT
StepTNT

Reputation: 3967

Bing Maps not loading tiles from local app data

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?

Upvotes: 3

Views: 334

Answers (2)

Duncan Lawler
Duncan Lawler

Reputation: 1772

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.

Upvotes: 0

Jay Zuo
Jay Zuo

Reputation: 15758

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.

Upvotes: 3

Related Questions