Question

Here's what I have so far:

const int imgSize = 210;
Map tempMap = new Map { Width = imgSize, Height = imgSize };
// ... adding some layers, setting the view
Size size = new Size(imgSize, imgSize);
tempMap.Measure(size);
tempMap.Arrange(new Rect(new Point(0, 0), size));
tempMap.UpdateLayout();

WriteableBitmap bmp = new WriteableBitmap(imgSize, imgSize);
bmp.Render(tempMap, null);
bmp.Invalidate();
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
string filename = "/Shared/ShellContent/" + /* ... file name */ ".jpg";
using (IsolatedStorageFileStream stream = store.OpenFile(filename, FileMode.OpenOrCreate))
    bmp.SaveJpeg(stream, imgSize, imgSize, 0, 100);

tile.Update(new FlipTileData
{
    // ... set other properties
    BackgroundImage = new Uri("isostore:" + filename, UriKind.Absolute)
});

I want to update a live tile with an image of a Map (the WP8 one, from Nokia). According to this answer, even UIElements that are never part of the visual tree can be rendered with a WriteableBitmap; however, my image is just black. Is that a problem with the Map control, or am I doing something wrong?

EDIT 1: The Windows Phone WriteableBitmap class seems to be completely different from the one documented on MSDN. Weird.

EDIT 2: Documentation for the Silverlight WriteableBitmap

EDIT 3: Partial progress! Add the following three lines:

tempMap.Width = imgSize // right before the measure call. DO NOT set the height.
(Content as Grid).Children.Add(tempMap) // right after creating tempMap. (your layout may vary)
(Content as Grid).Children.Remove(tempMap) // after you're done. (your layout may vary)

This results in a completely blue image instead of a completely black one. Changing tempMap.Center and tempMap.ZoomLevel has no effect on the tile; calling tempMap.SetView has no effect at all (for debugging, I left the map in my app page so I can see the effects of the calls - the tile is not what the map looks like in the page)

Was it helpful?

Solution

I tried this myself, and couldn't get it to work either. I got around it by just using Bing's static map API though. I was then able to just download a map, specified to be the exact size I want, and then use that. The following link shows how to use it, and gives the link to getting an API key (which only takes a second).

http://bingmapsdemos.sharepoint.com/Pages/BingMapsStaticMaps.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top