Map control not redrawing correctly after switching provider. [C#]

Topics: Windows Forms
Feb 18, 2013 at 6:15 PM
I am having some trouble with my code:

The map is only displayed in the corner of the map control when I change the map provider with comboBox_maps. I cannot figure out how to get the maps to redraw correctly after I select one.

Any help on this issue would be greatly appreciated.
public partial class main : Form
{
    public main()
    {
        InitializeComponent();
    }

    private void main_Load(object sender, EventArgs e)
    {          
    }

    private void map_Load(object sender, EventArgs e)
    {
        comboBox_maps.DataSource = GMapProviders.List;
        map.MinZoom = 3;
        map.MaxZoom = 17;
        map.Zoom = 5;
        map.Manager.Mode = AccessMode.ServerAndCache;  
    }

    private void comboBox_maps_SelectedIndexChanged(object sender, EventArgs e)
    {
        map.MapProvider = (GMapProvider)comboBox_maps.SelectedItem;
    }
}
Coordinator
Feb 18, 2013 at 6:51 PM
works fine for me, maybe you use old version ;/
Feb 20, 2013 at 4:25 PM
Edited Feb 20, 2013 at 4:25 PM
Here a picture of the problem:

Image

I am using the latest version, do you recommend using an older version ?
Coordinator
Feb 20, 2013 at 5:49 PM
set map docking to full
Feb 20, 2013 at 6:30 PM
Do you mean Fill ?

map.Dock = DockStyle.Fill;

This does not fix the problem, it just fills my main form with the image I previously posted.
Coordinator
Feb 20, 2013 at 6:36 PM
forks fine for me, try not using load event
Feb 20, 2013 at 7:11 PM
Interesting. Could you give example code without using load event ? I am not the strongest C# programmer. Thank you for all your help btw.
Coordinator
Feb 20, 2013 at 7:49 PM
just move all initial code to public main()
Feb 21, 2013 at 2:10 PM
I have moved the code to main as you suggested but the issue still remains.

My code now:

public partial class main : Form
{
    GMapControl map = new GMap.NET.WindowsForms.GMapControl();
    public main()
    {
        InitializeComponent();
        comboBox_maps.DataSource = GMapProviders.List;
        addMap();
    }

    private void addMap()
    { 
        map.Bearing = 0F;
        map.CanDragMap = true;
        map.GrayScaleMode = false;
        map.LevelsKeepInMemmory = 5;
        map.Location = new System.Drawing.Point(12, 87);
        map.MarkersEnabled = true;
        map.MaxZoom = 2;
        map.MinZoom = 2;
        map.MouseWheelZoomType = GMap.NET.MouseWheelZoomType.MousePositionAndCenter;
        map.Name = "map";
        map.NegativeMode = false;
        map.PolygonsEnabled = true;
        map.RetryLoadTile = 0;
        map.RoutesEnabled = true;
        map.ShowTileGridLines = false;
        map.Size = new System.Drawing.Size(960, 513);
        map.TabIndex = 2;
        map.Zoom = 0D;
        map.Load += new System.EventHandler(this.main_Load);
        map.MinZoom = 3;
        map.MaxZoom = 17;
        map.Zoom = 5;
        map.Manager.Mode = AccessMode.ServerAndCache;
        Controls.Add(map);
    }

    private void comboBox_maps_SelectedIndexChanged(object sender, EventArgs e)
    {
        map.MapProvider = (GMapProvider)comboBox_maps.SelectedItem;
    }
Any suggestions? This has me stumped.
Coordinator
Feb 21, 2013 at 2:16 PM
the line that is is important to be in constructor is: map.MapProvider = ...
..and set docking to fill
Feb 21, 2013 at 2:30 PM
Its Working :D.

Setting the initial combobox index to 1 seemed to resolve the Issue.

He is the working code for anyone interested:
public partial class main : Form
{
    GMapControl map = new GMap.NET.WindowsForms.GMapControl();
    public main()
    {
        InitializeComponent();
        comboBox_maps.DataSource = GMapProviders.List;
        comboBox_maps.SelectedIndex = 1;
        map.MapProvider = (GMapProvider)comboBox_maps.SelectedItem;
        addMap(); 
    }

    private void main_Load(object sender, EventArgs e)
    {
    }

    private void addMap()
    { 
        map.Bearing = 0F;
        map.CanDragMap = true;
        map.GrayScaleMode = false;
        map.LevelsKeepInMemmory = 5;
        map.Location = new System.Drawing.Point(12, 87);
        map.MarkersEnabled = true;
        map.MaxZoom = 2;
        map.BorderStyle = BorderStyle.FixedSingle;
        map.MinZoom = 2;
        map.MouseWheelZoomType = GMap.NET.MouseWheelZoomType.MousePositionAndCenter;
        map.Name = "map";
        map.NegativeMode = false;
        map.PolygonsEnabled = true;
        map.RetryLoadTile = 0;
        map.RoutesEnabled = true;
        map.ShowTileGridLines = false;
        map.Size = new System.Drawing.Size(960, 511);
        map.TabIndex = 2;
        map.Zoom = 0D;
        map.Load += new System.EventHandler(this.main_Load);
        map.MinZoom = 3;
        map.MaxZoom = 17;
        map.Zoom = 5;
        map.Manager.Mode = AccessMode.ServerAndCache;
        //map.MapProvider = GMapProviders.OpenStreetMap;
        Controls.Add(map);
    }

    private void comboBox_maps_SelectedIndexChanged(object sender, EventArgs e)
    {
        map.MapProvider = (GMapProvider)comboBox_maps.SelectedItem;
    }
Thank you radioman for all your help on the issue.
  • Dan.
Dec 4, 2013 at 4:48 PM
Thanks for the thread guys. I found this very helpful and made it easy to implement this same feature.

Chuck