This project has moved and is read-only. For the latest updates, please go here.

Render mapcontrol on background

Oct 4, 2014 at 8:40 AM
Hi ClemensF,

Firstly, I like to thank you for your wonderful control.
It is working like a charm and it is easy to implement!
Unfortunately, I have one issue that I cannot solve...

I have a console application that renders and saves a screenshot from the mapcontrol (via the wpf 'RenderTargetBitmap' function).
My (custom) tiles of the mapcontrol are loaded from a sqlce database. Furthermore, the mapcontrol is loaded with polygons.
After rendering the map, I can only see the polygons and the background color of the map. The tiles are not visible. I think the rendering process is to fast and the tiles are not loaded yet before making the screenshot. I have already turned off the asyncload property but without success.

Could you please lead me in the right direction to solve this issue.

Thank you in advance,

Oct 6, 2014 at 10:44 PM
As you already have a derived ImageTileSource class, you may just check if all current tiles have been downloaded and then render the screenshot. However, there is no public property that would tell you what the current tile set is. A quick hack may be to make the grid and zoomLevel fields of class TileLayer public. In a future release of the map control I may then convert them to public properties.
Oct 15, 2014 at 3:12 PM
Edited Oct 15, 2014 at 3:15 PM
Hi ClemensF,

I have checked that all tiles in the TileLayer have been downloaded (I use a sqlce database to get the tiles from a local database file).
Unfortunately, they remain invisible (with other controls it works fine).

I load the map within a console application (started with commandline arguments to specify the size of the map).
The map is therefore not added to the visual tree, I have to to that by myself by calling Measure() and Arrange().
Could it be possible that more visual controls (e.g. the tiles) within the map needs this Measure() and Arrange() call?

Below the code that I use to render the map.
        private void SaveScreenShot(Map map, Size size, string filename)
            // Give the map the right size
            map.Width = size.Width;
            map.Height = size.Height;
            // Call Measure and Arrange, because the controls does not yet exist 
            // in the visual tree and the size has not been calculated yet.
            map.Arrange(new Rect(0, 0, size.Width, size.Height));

            //Render the map
            RenderTargetBitmap rtb = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Pbgra32);

            //Save the map
            using (MemoryStream stream = new MemoryStream())
                PngBitmapEncoder encoder = new PngBitmapEncoder();
Oct 15, 2014 at 4:14 PM
Perhaps you also need to set the static TileAnimationDuration property to TimeSpan.Zero.
Oct 16, 2014 at 7:22 AM
Goodday ClemensF,

I have set the AnimationDuration within the Tile class to:
public static TimeSpan AnimationDuration = TimeSpan.Zero;
I also played with some other settings but still get an empty image.
The MapGraticule and other controls are however that not weird?!
I will continue to play around with the mapcontrol and see if I can find a fix...


Kind regards,