Can intialize MapProvider async?

Topics: Windows Forms
Nov 14, 2011 at 4:48 PM

Cool control!

A newbie question.  I am using the Winform control and having this in the Form constructor

        public MainForm()
            this.gMapControl1.MapProvider = GMap.NET.MapProviders.BingMapProvider.Instance;
            this.gMapControl1.MinZoom = 3;
            this.gMapControl1.MaxZoom = 17;
            this.gMapControl1.Zoom = 4;
            this.gMapControl1.Manager.Mode = AccessMode.ServerAndCache;
            this.gMapControl1.CanDragMap = true;
            this.gMapControl1.DragButton = MouseButtons.Left;

The form takes a few seconds on the MapProvider line.


1.  Is there a way to run that line async?  If not, how to avoid this start up delay?

2. If I put all the gMapControl lines above on the Application_Idle event, then subsequent setting of the position


will not position the map.  What else do I need to do in order to put the initialization code in the Application_Idle event?

Nov 14, 2011 at 5:46 PM

SetCurrentPositionByKeywords calls web service, so move this function somewhere else

Nov 14, 2011 at 6:42 PM

SetCurrentPositionByKeywords is pretty fast so that's not the problem.  It's the line before it that's taking the longer time.

Nov 14, 2011 at 6:48 PM

you can assign it later, like OnFormLoad event

Nov 14, 2011 at 11:06 PM

Aren't OnFormLoad and Form Constructor both have the same effect?  Unless it's done in another thread, the delay is unavoidable.  But since it's a UI control, there is no way that the UI can be initialized in a different thread by the caller.  However, the control itself should be able to isolate the slow process which I think is the web service call to Bing or Google.  Thus I think a better solution would be to provide an async call for the initialization of the control so the UI will be more responsive.

Nov 15, 2011 at 7:58 AM

does the other providers have the same issue? Anyway you can use splash screen while everything is loading

Nov 15, 2011 at 2:20 PM

I have the same issue. Put a break point before the "this.gMapControl1.MapProvider = GMap.NET.MapProviders.BingMapProvider.Instance;" line. Step over...wait.....wait.....then gets to next line.


Close form, reopen form, second time the same form containing the control is loaded it is normal fast speed.

Any ideas where to look?

All map providers the same. For me mapcontrol is inside app and cant be covered by splash screen.

Nov 15, 2011 at 2:31 PM

bing/google has integrated version number check functionality, each 8 hours it refresh the cached value

you can disable this by setting TryCorrectVersion to false, but without correct version number it might stop working, i guess you can call async later: provider.OnInitialized();

..but if you load first time, and probably with old version numbers async doesn't help much...

Nov 16, 2011 at 7:12 PM

So I figured out how to cheat a little.  During Form Load, I run the map init code async and I guess behind the scene, it will cache up the map for subsequent loading of the real map.  It works out great!


        delegate void InitMapDeleteGate();
        IAsyncResult _ia = null;
        InitMapDeleteGate d = new InitMapDeleteGate(InitMap);
        _ia = d.BeginInvoke(null, null);

        private void InitMap()
            GMap.NET.WindowsForms.GMapControl dummy = new GMap.NET.WindowsForms.GMapControl();
            dummy.MapProvider = GMap.NET.MapProviders.BingMapProvider.Instance;