Click here to Skip to main content
15,894,343 members
Articles / Web Development / XHTML

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

Rate me:
Please Sign up or sign in to vote.
5.00/5 (12 votes)
17 Oct 200512 min read 279K   2.8K   98  
Creating 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>
  /// An icon specifies the images used to display a marker on the map. For 
  /// browser compatibility reasons, specifying an icon is actually quite 
  /// complex. See the discussion above for more information.
  ///
  /// At a minimum, you must specify the image, shadowImage, iconSize, 
  /// shadowSize, and iconAnchor properties of an icon before it can be 
  /// displayed on the map. If you use info windows, you must also specify the 
  /// infoWindowAnchor property of the icon. 
  /// </summary>
  [Serializable()]
	public class GIcon
	{
    private string _id;
    private Uri _image;
    private Uri _shadow;
    private GSize _iconSize;
    private GSize _shadowSize;
    private GPoint _iconAnchor;
    private GPoint _infoWindowAnchor;
    private Uri _printImage;
    private Uri _mozPrintImage;
    private Uri _printShadow;
    private Uri _transparent;
    private Points _imageMap = new Points();

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

    /// <summary>
    ///  Creates a copy of the current icon, resetting the Id
    /// </summary>
    public GIcon Copy()
    {
      GIcon cpy = (GIcon)this.MemberwiseClone();
      cpy.Id = String.Empty;
      return cpy;
    }

    /// <summary>
    /// Identifies this GIcon.  Must be a a valid javascript variable name i.e.
    ///  cannot start with a number, avoid javascript reserved words, cannot
    ///  contain punctuation, etc.
    /// </summary>
    [XmlAttribute()]
    public string Id
    {
      get { return _id; }
      set { _id = value; }
    }

    /// <summary>
    /// The foreground image URL of the icon
    /// </summary>
    [XmlIgnore()]
    public Uri Image
    {
      get { return _image; }
      set { _image = value; }
    }

    /// <summary>
    /// 
    /// </summary>
    [XmlAttribute("Image")]
    public string ImageUrl
    {
      get 
      {
        if( _image == null )
          return String.Empty;
        else
          return _image.AbsoluteUri; 
      }
      set { _image = new Uri(value); }
    }

    /// <summary>
    /// The shadow image URL of the icon
    /// </summary>
    [XmlIgnore()]
    public Uri Shadow
    {
      get { return _shadow; }
      set { _shadow = value; }
    }

    /// <summary>
    /// 
    /// </summary>
    [XmlAttribute("Shadow")]
    public string ShadowUrl
    {
      get 
      { 
        if( _shadow == null )
          return String.Empty;
        else
          return _shadow.AbsoluteUri; 
      }
      set { _shadow = new Uri(value); }
    }

    /// <summary>
    /// The pixel size of the foreground image of the icon
    /// </summary>
    public GSize IconSize
    {
      get { return _iconSize; }
      set { _iconSize = value; }
    }

    /// <summary>
    /// The pixel size of the shadow image
    /// </summary>
    public GSize ShadowSize
    {
      get { return _shadowSize; }
      set { _shadowSize = value; }
    }

    /// <summary>
    /// The pixel coordinate relative to the top left corner of the icon image 
    /// at which we should anchor this icon to the map
    /// </summary>
    public GPoint IconAnchor
    {
      get { return _iconAnchor; }
      set { _iconAnchor = value; }
    }

    /// <summary>
    /// The pixel coordinate relative to the top left corner of the icon image 
    /// at which we should anchor the info window to this icon
    /// </summary>
    public GPoint InfoWindowAnchor
    {
      get { return _infoWindowAnchor; }
      set { _infoWindowAnchor = value; }
    }

    /// <summary>
    /// The URL of the foreground icon image we should use for printed maps. It 
    /// should be the same size as the main icon image.
    /// </summary>
    [XmlIgnore()]
    public Uri PrintImage
    {
      get { return _printImage; }
      set { _printImage = value; }
    }

    /// <summary>
    /// 
    /// </summary>
    [XmlAttribute("PrintImage")]
    public string PrintImageUrl
    {
      get 
      { 
        if( _printImage == null )
          return String.Empty;
        else
          return _printImage.AbsoluteUri; 
      }
      set { _printImage = new Uri(value); }
    }

    /// <summary>
    /// The URL of the foreground icon image we should use for printed maps in 
    /// Firefox/Mozilla. It should be the same size as the main icon image.
    /// </summary>
    [XmlIgnore()]
    public Uri MozPrintImage
    {
      get { return _mozPrintImage; }
      set { _mozPrintImage = value; }
    }

    /// <summary>
    /// 
    /// </summary>
    [XmlAttribute("MozPrintImage")]
    public string MozPrintImageUrl
    {
      get 
      { 
        if( _mozPrintImage == null )
          return String.Empty;
        else
          return _mozPrintImage.AbsoluteUri; 
      }
      set { _mozPrintImage = new Uri(value); }
    }

    /// <summary>
    /// The URL of the shadow image we should use for printed maps. It should 
    /// be a GIF image since most browsers cannot print PNG images.
    /// </summary>
    [XmlIgnore()]
    public Uri PrintShadow
    {
      get { return _printShadow; }
      set { _printShadow = value; }
    }

    /// <summary>
    /// 
    /// </summary>
    [XmlAttribute("PrintShadow")]
    public string PrintShadowUrl
    {
      get 
      { 
        if( _printShadow == null )
          return String.Empty;
        else
          return _printShadow.AbsoluteUri; 
      }
      set { _printShadow = new Uri(value); }
    }

    /// <summary>
    /// The URL of a virtually transparent version of the foreground icon image 
    /// used to capture IE click events. This image should be a 24-bit PNG 
    /// version of the main icon image with 1% opacity, but the same shape and 
    /// size as the main icon.
    /// </summary>
    [XmlIgnore()]
    public Uri Transparent
    {
      get { return _transparent; }
      set { _transparent = value; }
    }

    /// <summary>
    /// 
    /// </summary>
    [XmlAttribute("Transparent")]
    public string TransparentUrl
    {
      get 
      { 
        if( _transparent == null )
          return String.Empty;
        else
          return _transparent.AbsoluteUri; 
      }
      set { _transparent = new Uri(value); }
    }

    /// <summary>
    ///  An array of integers representing the x/y coordinates of the image map 
    ///  we should use to specify the clickable part of the icon image in 
    ///  non-IE browsers.
    /// </summary>
    [XmlArray()]
    public Points ImageMap
    {
      get { return _imageMap; }
      set { _imageMap = value; }
    }
	}
}

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