Page 1 of 2

Fully loaded event of Map control

Posted: Tue Oct 13, 2015 8:22 am
by infpro_mi
Hello,

we would like to know when the .NET Form Map control is fully loaded including all layers.

We have tried the Loaded event, but this seems to be fired before the layers are fully loaded.
Loaded: Occurs when the element is laid out, rendered, and ready for interaction.
Which event is fired when the map control is fully loaded? (the background and label layer are downloaded)

Thanks!
Best regards
Martin

Re: Fully loaded event of Map control

Posted: Tue Oct 13, 2015 11:41 am
by Oliver Heilig
Hello Martin,

the loded event is a standard WPF event. The imagery data is loaded asynchrounously in separate threads. There's no event like TilesLoaded in for the MapControl-layers. However there is a "synchronous mode" which can be used if you want to use the control to print or export the map content. See the sample "PieChartsAndExport" here: https://github.com/ptv-logistics/xservernet-bin

Regards
Oliver

Re: Fully loaded event of Map control

Posted: Tue Oct 13, 2015 12:42 pm
by infpro_mi
Hello Oliver,

is it possible to switch between synchronous and asynchronous mode during execution?
How can I set the "synchronous mode" of the Map control?

Thanks!

Re: Fully loaded event of Map control

Posted: Tue Oct 13, 2015 1:16 pm
by Oliver Heilig
Yes you can change this at runtime with the printing property, see https://github.com/ptv-logistics/xserve ... #L195-L201. The puprose of this property is to grab the map content for print and export. But i guess the map isn't very responsive when the Printing property is set.

Re: Fully loaded event of Map control

Posted: Tue Oct 13, 2015 1:51 pm
by infpro_mi
Thank you very much!

But the following code, does not work on start up!
The background is black because the Map control is still loading the background and label layer.

Code: Select all

mapView.Printing = true;
mapView.UpdateLayout();

RenderTargetBitmap rtb = new RenderTargetBitmap((int)newSize.Width, (int)newSize.Height, 96d, 96d, PixelFormats.Default);
rtb.Render(mapView);

mapView.Printing = false;
I would like to export the Map control immediately after the control has fully loaded. (including background and labels)

The following lines do not ensure, that the control is fully loaded: :(

Code: Select all

mapView.Printing = true;
mapView.UpdateLayout();

Re: Fully loaded event of Map control

Posted: Wed Oct 14, 2015 12:52 pm
by Oliver Heilig
Have you tried just to add the Export-Function here and call it just after initialization https://github.com/ptv-logistics/xserve ... ml.cs#L176? This should do exactly what you expect.

Re: Fully loaded event of Map control

Posted: Wed Oct 14, 2015 1:01 pm
by infpro_mi
Yes, I'm using exactly this export function already.
But the problem is to find the point when the Map control is fully initialized.

I'm calling this function after the parent Form has been shown. But the Map control is still fetching the background layer asynchronously. Therefore, at this point this export function returns a black background layer. :(

Re: Fully loaded event of Map control

Posted: Wed Oct 14, 2015 4:01 pm
by Oliver Heilig
OK, can reproduce that. The problem is not the asynchronous loading, the PrintMode-Flag disables async-loading + animations. The trick is the initialization directly inside the constructor before actually displaying the control. A solution would be this:

Code: Select all

public Window1()
        {
            InitializeComponent();

            Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() => exportCustom_Click(null, null)));
        }
As you see this shows the xMap images correctly, but not the pie charts, because these fade-in with an animation. But that's not a problem of the control itself. What would be interesting though is how to use the Map in a "headless mode" without actually attaching any window to it, so you could use it as pure rendering component.

Re: Fully loaded event of Map control

Posted: Thu Oct 15, 2015 5:40 am
by infpro_mi
Thank you very much for your explanations!
I have tried your solution inside the constructor but I still get an unfinished background. :(
It seems your internet is faster than my connection and therefore, the background is able to load before the export is executed.

Re: Fully loaded event of Map control

Posted: Thu Oct 15, 2015 2:06 pm
by Oliver Heilig
I don't think the networks speed is a problem. I simulated modem speed with fiddler and didn't have a problem there. but i also had a black tile once. I also disabled animation explicitly in the constructor.

Code: Select all

  
        public Window1()
        {
            InitializeComponent();

            Map.UseAnimation = false;
            Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() => exportCustom_Click(null, null)));
        }
I cannot reproduce it with that. If you still have problems, maybe an explicit initialization of the layers will help, see CustomInit sample here: https://github.com/ptv-logistics/xservernet-bin

Note: I your aim is only to render static map images, i don't recommend doing it with the control anyway. The xServer.NET control and WPF are targeted for interactive applications and not for map rendering. So if you want to autogenerate maps with .NET, i recommend using a immediate engine like GDI instead. We have a tutorial that uses SharpMap to generate map images here: https://github.com/ptv-logistics/ajaxmaps-shapefile