WPF - RadMap ExportToImage

1 Answer 57 Views
Map
Ohad
Top achievements
Rank 3
Bronze
Iron
Iron
Ohad asked on 01 Aug 2022, 11:26 AM

I try to save the map to the image like this:

    private MemoryStream LocationsToImage(ICollection<LocationType> locationCollection, Size size)
    {
        var map = new RadMap
        {
            Language = XmlLanguage.GetLanguage(CultureInfo.DefaultThreadCurrentCulture.Name),
            Width = size.Width,
            Height = size.Height
        };
        var layer = new InformationLayer();
        map.Items.Add(layer);
        MapHelper.DrawLocations(map, layer, locationCollection);

        //print 
        map.Arrange(new Rect(size));
        map.Measure(size);
        map.Provider = MapProviderFactory.Create();
        using var ms = new MemoryStream();
        map.ExportToImage(@"C:\New Test.png", true);
        return ms;
    }

 

And the result I get:

 

But if I use for a map that is displayed in the UI it will be printed properly

 

But also regarding a map that is not displayed in the UI and was created here (as in the code above) I can use PrintVisual and print it properly.

 

    private void LocationsToImage(ICollection<LocationType> locationCollection, Size size)
    {
        var map = new RadMap
        {
            Language = XmlLanguage.GetLanguage(CultureInfo.DefaultThreadCurrentCulture.Name),
            Width = size.Width,
            Height = size.Height
        };
        var layer = new InformationLayer();
        map.Items.Add(layer);
        MapHelper.DrawLocations(map, layer, locationCollection);

        //print 
        map.Arrange(new Rect(size));
        map.Measure(size);
        map.Provider = MapProviderFactory.Create();
        var pd = new PrintDialog();
        if (pd.ShowDialog().GetValueOrDefault())
        {
            pd.PrintVisual(map, string.Empty);
        }
    }

 

 

So how can I use ExportToImage for a map that I create in code and not in view?

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 02 Aug 2022, 10:53 AM

Hello Ohad,

Exporting the RadMap control to an image before it was rendered it is not support. This is because the multithreading nature of the map providers and also the fact that the built-in providers make web requests. There is no guarantee that the web requests that download the tile images will be executed after the control was measured and arranged. Usually they will need little more time and in some cases if you or the tile server have network-related issues, the tile download can be delayed or even time out.

So, the solution to create a screenshot that will include also the map tile images is to wait a little longer before the export, but even this won't be reliable because you can't tell when or if the tiles will be downloaded. 

Anyway, we have a feature request to research and provide this type of functionality if possible. You can find it logged here: https://feedback.telerik.com/wpf/1475517-map-allow-exporting-the-map-to-picture-without-adding-it-to-the-visual-tree

Regards,
Martin Ivanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Map
Asked by
Ohad
Top achievements
Rank 3
Bronze
Iron
Iron
Answers by
Martin Ivanov
Telerik team
Share this question
or