Click here to Skip to main content
15,892,059 members
Articles / Web Development / ASP.NET

Google's MapData "Feature" WebControl

Rate me:
Please Sign up or sign in to vote.
3.00/5 (7 votes)
17 Apr 2008CPOL6 min read 41K   556   33  
Shows how to build a simple image WebControl to encapsulate the DataMap feature "from" Google.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Initia.Google.MapData;
using System.Threading;

namespace TestGMapData
{
    public partial class _Default : System.Web.UI.Page
    {
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            // Set up events
            btnAddPoint.Click += new EventHandler(btnAddPoint_Click);
            lbZoomLevel.SelectedIndexChanged += new EventHandler(lbZoomLevel_SelectedIndexChanged);
            lbImageFormat.SelectedIndexChanged += new EventHandler(lbImageFormat_SelectedIndexChanged);
            tbWidth.TextChanged += new EventHandler(tbWidth_TextChanged);
            tbHeight.TextChanged += new EventHandler(tbHeight_TextChanged);
        }

        #region Event handlers

        protected void btnAddPoint_Click(object sender, EventArgs e)
        {
            gmdTest.Points.Add(new Point(double.Parse(tbLatitude.Text), double.Parse(tbLongitude.Text), (Point.Icon)Enum.Parse(typeof(Point.Icon), lbIconType.SelectedValue)));

            UpdateUI();
        }

        protected void tbWidth_TextChanged(object sender, EventArgs e)
        {
            gmdTest.Width = int.Parse(tbWidth.Text);
        }

        protected void tbHeight_TextChanged(object sender, EventArgs e)
        {
            gmdTest.Height = int.Parse(tbHeight.Text);
        }

        protected void lbZoomLevel_SelectedIndexChanged(object sender, EventArgs e)
        {
            gmdTest.Zoom = uint.Parse(lbZoomLevel.SelectedValue);
        }

        protected void lbImageFormat_SelectedIndexChanged(object sender, EventArgs e)
        {
            gmdTest.Format = (MapDataImage.ImageFormat)Enum.Parse(typeof(MapDataImage.ImageFormat), lbImageFormat.SelectedValue);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitializeUI();
            }

            UpdateUI();
        }

        #endregion

        #region User Interface

        private void InitializeUI()
        {
            // Initialize zoom levels
            for (uint i = (uint)MapDataImage.ZoomLevel.Mini; i <= (uint)MapDataImage.ZoomLevel.Maxi; i++)
            {
                lbZoomLevel.Items.Add(new ListItem(i.ToString(), i.ToString()));
            }

            // Initialize image formats
            foreach (uint imageFormat in Enum.GetValues(typeof(MapDataImage.ImageFormat)))
            {
                lbImageFormat.Items.Add(new ListItem(Enum.GetName(typeof(MapDataImage.ImageFormat), imageFormat), ((uint)imageFormat).ToString()));
            }

            // Initialize icon types
            foreach (uint iconType in Enum.GetValues(typeof(Point.Icon)))
            {
                lbIconType.Items.Add(new ListItem(Enum.GetName(typeof(Point.Icon), iconType), ((uint)iconType).ToString()));
            }

            // For test purpose
            tbLatitude.Text = (45.728220).ToString();
            tbLongitude.Text = (4.830321).ToString();

            lbZoomLevel.SelectedIndex = 0;
            lbIconType.SelectedIndex = 0;
            lbImageFormat.SelectedIndex = 0;

            gmdTest.CountryCode = Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName;
            gmdTest.Width = int.Parse(tbWidth.Text);
            gmdTest.Height = int.Parse(tbHeight.Text);
        }

        private void UpdateUI()
        {
            gmdTest.Visible = (gmdTest.Points.Count > 0);
            lblMessage.Visible = !gmdTest.Visible;
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer Stambia
France France
I'm a 39 year old team deputy CTO, living and working near Lyon (France)

I started to write softwares in the end of 90's, when I was a teenager.

I acquired several but complementary skills, mainly (but not only) on Microsoft's technologies and platforms : assembly (x86, 68k), C, C++, .NET/C#, JavaScript/HTML/CSS, PHP, DBMS (MySQL, Oracle, SQL Server, etc.), etc.

During 2007-2012, I was particulary active on .NET, ASP.NET, C#, SQL Server and ORM (NHibernate) with a growing time spent on architecture, technical management, code review, etc.

Since 2013, I'm a full-time development team leader/manager at Everial, I stopped development at work but still love to develop some personnal programs during my spare time, mainly for domotic purposes. I use to play with Arduino, ESP8266/NodeCmu, Raspberry PI... running them with some C++ and .NET Core.

My hobbies are futsal, badminton, motorcycle, Formula One, domotic, gardening... and software developement.

Comments and Discussions