This project has moved. For the latest updates, please go here.

Multiple Map control

Dec 2, 2013 at 9:31 AM
Hello,

i'm searching to understand if it possible to use different instances of map control in the same application, so meanwhile i thought to ask here directly.

Is it possible?

What i want to do is to be able to view different layers of a map simultanously, managing different zoom level in each view, but all related to each other.

Thank you very much for any answer or suggestion.

Best regards,

Adriano Albertini
Coordinator
Dec 2, 2013 at 10:24 AM
Edited Dec 2, 2013 at 10:41 AM
Did you try something at all? It should work without problems.
Dec 2, 2013 at 11:42 AM
Hello ClemensF,

thank you for your quick reply!

What i did just now is to split the Sample WpfApplication duplicating the MapControl. It starts but then an error occures when the map tries to load the layers saying that the visual tree cannot load the same tile layer.

So i was wondering if the control uses static resources for loading layers and other visual components, or if it's just a problem about the sample demo application which loads static resources.
Coordinator
Dec 2, 2013 at 4:10 PM
It's just a problem about how you modified the sample application, and it is not related to static resources. TileLayer is a visual component and is added to the visual tree of a map control. WPF allows visual components to be added to only one such tree at a time. You might easily get around that by creating separate TileLayer instances for being added to different map control instances.
Dec 2, 2013 at 4:24 PM
You are right,

the problem that i experienced was about adding the same tile layer to the same visual tree. Now i resolved it by creating completely separate tile layer for each map control used. I was worried about that such a situation replicates inside other parts of the code, but likely it doesn't seem so, as you confirmed.

Thank you very much!
Dec 3, 2013 at 4:30 PM
I found a problem about multiple control usage.

It happens that some Tiles are not loaded correctly if you load simultanously the map layer of each control. I found that an exception is generated into the CreateImage(string path) method of the TileImageLoader.WPF class, sayng that the file is already in use by another process.

I modified the code in such a way and it seems to work properly

private static ImageSource CreateImage(string path)
    {
        ImageSource image = null;

        if (File.Exists(path))
        {
            try
            {
                using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    image = BitmapFrame.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceWarning("Creating tile image failed: {0}", ex.Message);
            }
        }

        return image;
    }
Dec 3, 2013 at 4:41 PM
I found a trouble loading Tiles from a local file server too (ex: \fileserver\TilePath UNC path).

The problem is related to the method "LoadPendingTiles" of the TileImageLoader.WPF class, in this step:

var uri = tileSource.GetUri(tile.XIndex, tile.Y, tile.ZoomLevel);

if (uri != null)
{
if (uri.Scheme == "file")
{
    image = CreateImage(uri.AbsolutePath);
}
else
{
     buffer = DownloadImage(uri);
     image = CreateImage(buffer);
 }
}

the "uri.AbsolutePath" method doesn't return the right path for server unc path

I modified the code in this way adding this code inside the " if (uri.Scheme == "file")" condition code

if (uri.IsUnc)
{
image = CreateImage(uri.LocalPath);
}
else
{
image = CreateImage(uri.AbsolutePath);
}

This is my specific problem because i want to load Tiles from a local file server, but i thought it would be a good idea to signal it.
Coordinator
Dec 3, 2013 at 5:47 PM
Edited Dec 3, 2013 at 5:57 PM
Thanks for spotting this. I'll add both modifications to the next release. LocalPath is better than AbsolutePath in any case.
Coordinator
Dec 5, 2013 at 4:03 PM
Please check out the latest version.
Dec 6, 2013 at 7:57 AM
Done. Thankx!!