Map providers demo

This demo is a simple application to display maps from different map providers, such as OpenStreetMap, GoogleMaps, BingMaps and so on.




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using GMap;
using GMap.NET.WindowsForms;

namespace mapProviders
{
    public partial class Form1 : Form
    {
        int zoom = 3;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            cmbMapProviders.Text = "OpenStreetMap";
            cmbMapProviders.Items.Add("OpenStreetMap");
            cmbMapProviders.Items.Add("GoogleMaps");
            cmbMapProviders.Items.Add("BingMaps");
            cmbMapProviders.Items.Add("GoogleSatelliteMap");
            cmbMapProviders.Items.Add("GoogleTerrainMap");
            cmbMapProviders.Items.Add("GoogleHybridMap");
            cmbMapProviders.Items.Add("ArcGIS_Imagery_World_2D_Map");
            showMap("OpenStreetMap", zoom);
            gMapControl.SetPositionByKeywords("Europe");

        }


        void showMap(string provider, int zoom )
        {
            switch(provider)
            {
                case "GoogleMaps":
                    gMapControl.MapProvider = GMap.NET.MapProviders.GoogleMapProvider.Instance;
                    GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerAndCache;
                    break;

                case "BingMaps":
                    gMapControl.MapProvider = GMap.NET.MapProviders.BingMapProvider.Instance;
                    GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerAndCache;
                    break;

                case "OpenStreetMap":
                    gMapControl.MapProvider = GMap.NET.MapProviders.OpenStreetMapProvider.Instance;
                    GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerAndCache;
                    break;

                case "GoogleTerrainMap":
                    gMapControl.MapProvider = GMap.NET.MapProviders.GoogleTerrainMapProvider.Instance;
                    GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerAndCache;
                    break;

                case "GoogleSatelliteMap":
                    gMapControl.MapProvider = GMap.NET.MapProviders.GoogleSatelliteMapProvider.Instance;
                    GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerAndCache;
                    break;

                case "GoogleHybridMap":
                    gMapControl.MapProvider = GMap.NET.MapProviders.GoogleHybridMapProvider.Instance;
                    GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerAndCache;
                    break;

                case "ArcGIS_Imagery_World_2D_Map":
                    gMapControl.MapProvider = GMap.NET.MapProviders.ArcGIS_Topo_US_2D_MapProvider.Instance;
                    GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerAndCache;
                    break;
            }
            gMapControl.Zoom = zoom;
            gMapControl.Refresh();
        }

        private void cmbMapProviders_SelectedIndexChanged(object sender, EventArgs e)
        {
            showMap(cmbMapProviders.SelectedItem.ToString(), zoom);
        }

        private void gMapControl_MouseMove(object sender, MouseEventArgs e)
        {
            double x = gMapControl.FromLocalToLatLng(e.X, e.Y).Lng;
            string Longitude = x.ToString("0.000");
            double y = gMapControl.FromLocalToLatLng(e.X, e.Y).Lat;
            string Latitude = y.ToString("0.000");
            this.Text = "GMap demo " + "|" + "Hosszúság: " + Longitude + "     Szélesség: " + Latitude;
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                gMapControl.SetPositionByKeywords(textBox1.Text);
                gMapControl.Refresh();
            }
        }

        private void cmbZoomIn_Click(object sender, EventArgs e)
        {
            gMapControl.Zoom += 1;
            zoom += 1;
            gMapControl.Refresh();
        }

        private void cmbZoomOut_Click(object sender, EventArgs e)
        {
            gMapControl.Zoom -= 1;
            zoom -= 1;
            gMapControl.Refresh();
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }
    }
}