Fully loaded event of Map control

Within this forum we want to offer discussions all around our .NET based Map control including all .Net-language specific questions concerning calls of the xServer-API. Attention: xServer-relevant concepts can be found in further forums such as xRoute or xTour.
infpro_mi

Fully loaded event of Map control

Post 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
User avatar
Oliver Heilig
Posts: 154
Joined: Tue May 13, 2014 12:10 pm
Location: Karlsruhe, Germany
Contact:

Re: Fully loaded event of Map control

Post 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
infpro_mi

Re: Fully loaded event of Map control

Post 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!
User avatar
Oliver Heilig
Posts: 154
Joined: Tue May 13, 2014 12:10 pm
Location: Karlsruhe, Germany
Contact:

Re: Fully loaded event of Map control

Post 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.
infpro_mi

Re: Fully loaded event of Map control

Post 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();
User avatar
Oliver Heilig
Posts: 154
Joined: Tue May 13, 2014 12:10 pm
Location: Karlsruhe, Germany
Contact:

Re: Fully loaded event of Map control

Post 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.
infpro_mi

Re: Fully loaded event of Map control

Post 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. :(
User avatar
Oliver Heilig
Posts: 154
Joined: Tue May 13, 2014 12:10 pm
Location: Karlsruhe, Germany
Contact:

Re: Fully loaded event of Map control

Post 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.
Attachments
Imga8ee244e-f464-4b05-8257-743a3187fbb3.jpg
infpro_mi

Re: Fully loaded event of Map control

Post 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.
Attachments
Imga4af72f2-95a2-401b-b118-04d7d5a7ae2a.jpg
Img26b1259f-21b8-452d-9553-6e26049e38a1.jpg
User avatar
Oliver Heilig
Posts: 154
Joined: Tue May 13, 2014 12:10 pm
Location: Karlsruhe, Germany
Contact:

Re: Fully loaded event of Map control

Post 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
Post Reply