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

Lat Lays Flat - Part 1 : A Google Maps .NET Control

Rate me:
Please Sign up or sign in to vote.
4.76/5 (69 votes)
17 Oct 20056 min read 908.6K   17.3K   258  
An ASP.NET server control wrapper for the Google Maps API.
/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is WCPierce Web Controls.
 *
 * The Initial Developer of the Original Code is William C. Pierce.
 * Portions created by the Initial Developer are Copyright (C) 2005
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */
using System;
using System.Xml.Serialization;

namespace WCPierce.Web.UI.WebControls
{
	/// <summary>
	/// GSize represents a 2-dimensional size measurement. If a GSize represents 
	/// a lat/lng span, width is the number longitude degrees, and y is the 
	/// number of latitude degrees.
	/// </summary>
	[Serializable()]
	public class GSize
	{
    private float _width = 0F;
    private float _height = 0F;

    /// <summary>
    /// Default constructor required for XmlSerialization
    /// </summary>
		public GSize() { }

    /// <summary>
    ///  Creates a new size with the given measurement values
    /// </summary>
    /// <param name="Width"></param>
    /// <param name="Height"></param>
    public GSize(float Width, float Height)
    {
      _width = Width;
      _height = Height;
    }

    /// <summary>
    /// The width measurement
    /// </summary>
    [XmlAttribute()]
    public float Width
    {
      get { return _width; }
      set { _width = value; }
    }

    /// <summary>
    /// The height measurement
    /// </summary>
    [XmlAttribute()]
    public float Height
    {
      get { return _height; }
      set { _height = value; }
    }

    /// <summary>
    /// Convenience function for converting from string to GSize
    /// </summary>
    /// <param name="Size">A string in "Width,Height" or "(Width,Height)" format</param>
    /// <returns></returns>
    public static explicit operator GSize(string Size)
    {
      try
      {
        string val = Size.Replace("(", String.Empty).Replace(")", String.Empty);
        string[] vals = val.Split(',');
        return new GSize(Convert.ToSingle(vals[0], Utilities.UsCulture), Convert.ToSingle(vals[1], Utilities.UsCulture));
      }
      catch( Exception e )
      {
        throw new InvalidCastException(String.Format("Could not convert string \"{0}\" to GSize", Size), e);
      }
    }

    /// <summary>
    /// Overloaded Equals to determine if two GSizes are indentical in Width/Height values
    /// </summary>
    /// <param name="obj"></param>
    /// <returns></returns>
    public override bool Equals(object obj)
    {
      if (obj == null || GetType() != obj.GetType()) return false;
      GSize p = (GSize)obj;
      return (_width == p.Width) && (_height == p.Height);
    }

    /// <summary>
    /// Convenience operator
    /// </summary>
    /// <param name="gp1"></param>
    /// <param name="gp2"></param>
    /// <returns></returns>
    public static bool operator ==(GSize gp1, GSize gp2) 
    {
      return gp1.Equals(gp2);
    }

    /// <summary>
    /// Convenience operator
    /// </summary>
    /// <param name="gp1"></param>
    /// <param name="gp2"></param>
    /// <returns></returns>
    public static bool operator !=(GSize gp1, GSize gp2) 
    {
      return (gp1.Width != gp2.Width) || (gp1.Height != gp2.Height);
    }

    /// <summary>
    /// Used to uniquely identify this GSize
    /// </summary>
    /// <returns></returns>
    public override int GetHashCode() 
    {
      return _width.GetHashCode() ^ _height.GetHashCode();
    }

    /// <summary>
    /// Ouputs a GSize in (Width, Height) format
    /// </summary>
    /// <returns></returns>
    public override string ToString()
    {
      return String.Format("({0},{1})", _width, _height);
    }

    /// <summary>
    /// Convert a GSize to SizeF to take advantage of SizeF methods
    /// </summary>
    /// <returns>A SiseF representation of the GSize</returns>
    public System.Drawing.SizeF ToSizeF()
    {
      return new System.Drawing.SizeF(_width, _height);
    }
	}
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions