Click here to Skip to main content
15,896,606 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 912.8K   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>
  /// GMarker is a type of map overlay that shows an icon at a single point on 
  /// the map. The constructor takes an instance of GIcon, which can be shared 
  /// among many markers, and the point at which it should be displayed. 
  /// GMarker also includes some convenience methods to open info windows over 
  /// the marker, which is common for Google Maps hacks.
  /// 
  /// 2005-09-09
  /// + Changed getMarkerById to getOverlayById
  /// </summary>
  [Serializable()]
	public class GMarker : GOverlay
	{
    /// <summary>
    /// 
    /// </summary>
    protected string _iconId = String.Empty;

    /// <summary>
    /// 
    /// </summary>
    protected GPoint _point = new GPoint(0, 0);

    /// <summary>
    /// Default constructor required for XmlSerialization
    /// </summary>
    public GMarker() : this(new GPoint(0,0), String.Empty, String.Empty) { } 

    /// <summary>
    /// 
    /// </summary>
    /// <param name="Point"></param>
		public GMarker(GPoint Point) : this(Point, String.Empty, String.Empty) { }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="Point"></param>
    /// <param name="Id"></param>
    public GMarker(GPoint Point, string Id) : this(Point, Id, String.Empty) { }

    /// <summary>
    /// Creates a marker with the given icon at the given point. If no icon is 
    /// given, we use the default Google Maps icon.
    /// </summary>
    /// <param name="Point"></param>
    /// <param name="Id"></param>
    /// <param name="IconId"></param>
    public GMarker(GPoint Point, string Id, string IconId)
    { 
      _point = Point;
      _id = Id;
      _iconId = IconId;
    }

    #region Public Properties

    /// <summary>
    /// The point at which the GMarker is located
    /// </summary>
    public override GPoint Point
    {
      get { return _point; }
      set { _point = value; }
    }

    /// <summary>
    /// The user assignable Id give to this Marker
    /// </summary>
    [XmlAttribute()]
    public override string Id
    {
      get { return _id; }
      set { _id = value; }
    }

    /// <summary>
    /// Used for XmlSerialization
    /// </summary>
    [XmlAttribute()]
    public string IconId
    {
      get { return _iconId; }
      set { _iconId = value; }
    }

    /// <summary>
    /// Used for databinding
    /// </summary>
    public float Longitude
    {
      get { return _point.X; }
    }

    /// <summary>
    /// Used for databinding
    /// </summary>
    public float Latitude
    {
      get { return _point.Y; }
    }

    #endregion

    #region Public Methods

    /// <summary>
    /// Opens an info window with the given HTML content over the given GMarker. 
    /// </summary>
    /// <param name="HtmlElem">An HTML DOM element</param>
    /// <returns></returns>
    public string OpenInfoWindow(string HtmlElem)
    {
      //string initStr = String.Format(Utilities.UsCulture, "{0}.getOverlayById('{1}').openInfoWindow({2});", this.JsId, this.Id, HtmlElem);
      string retStr = String.Format(Utilities.UsCulture, "this.getOverlayById('{0}').openInfoWindow({1});", this.Id, HtmlElem);
      //initJs.Append(initStr);
      return retStr;
    }

    /// <summary>
    /// Like OpenInfoWindow, but takes an HTML string rather than an HTML DOM element
    /// </summary>
    /// <param name="HtmlStr">The string of HTML to show in the info window</param>
    /// <returns></returns>
    public string OpenInfoWindowHtml(string HtmlStr)
    {
      //string initStr = String.Format(Utilities.UsCulture, "{0}.getOverlayById('{1}').openInfoWindowHtml('{2}');", this.JsId, this.Id, HtmlStr);
      string retStr = String.Format(Utilities.UsCulture, "this.getOverlayById('{0}').openInfoWindowHtml('{1}');", this.Id, HtmlStr);
      //initJs.Append(initStr);
      return retStr;
    }

    /// <summary>
    /// Like openInfoWindow, but takes an XML element and the URI of an XSLT 
    /// document to produce the content of the info window. The first time a 
    /// URI is given, it is downloaded with GXmlHttp and subsequently cached.
    /// </summary>
    /// <param name="Xml"></param>
    /// <param name="XsltUri"></param>
    /// <returns></returns>
    public string OpenInfoWindowXslt(string Xml, Uri XsltUri)
    {
      //string initStr = String.Format(Utilities.UsCulture, "{0}.getOverlayById('{1}').openInfoWindowXslt(GXml.parse('{2}'), '{3}');", this.JsId, this.Id, Xml, XsltUri.AbsoluteUri);
      string retStr = String.Format(Utilities.UsCulture, "this.getOverlayById('{0}').openInfoWindowXslt(GXml.parse('{1}'), '{2}');", this.Id, Xml, XsltUri.AbsoluteUri);
      //initJs.Append(initStr);
      return retStr;
    }

    /// <summary>
    /// Shows a blowup of the map over this marker. We use a default zoom level
    /// of 1 and the current map type if the zoomLevel and mapType parameters 
    /// are not given.
    /// </summary>
    /// <param name="ZoomLevel"></param>
    /// <param name="MapType"></param>
    /// <returns></returns>
    public string ShowMapBlowup(int ZoomLevel, GMapType MapType)
    {
      //string initStr = String.Format(Utilities.UsCulture, "{0}.getOverlayById('{1}').showMapBlowup({2}, {3});", this.JsId, this.Id, ZoomLevel, MapType);
      string retStr = String.Format(Utilities.UsCulture, "this.getOverlayById('{0}').showMapBlowup({1}, {2});", this.Id, ZoomLevel, MapType);
      //initJs.Append(initStr);
      return retStr;
    }
    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public string ShowMapBlowup()
    {
      return ShowMapBlowup(1, GMapType.G_MAP_TYPE);
    }

    #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 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