用C#创建一个封装Google Map API的GoogleMap Web服务器控件(一)
2008-04-23 12:58
411 查看
最近想搞两个基于Google Map的网站玩玩,觉得直接操作Google Map API实在麻烦,于是就想用C#写一个封装Google
Map API的GoogleMap Web服务器控件,这样,用ASP.NET创建基于Google Map的网站就非常简单啦!
下面就让我们从头开始吧!
一. 首先打开Visual Studio 2008(其他IDE也可以),创建一个C#类库项目,命名为WindEagle.GoogleMap,勾选"创建解决方案目录"选项.
二. 删除默认的Class1.cs,修改项目属性,设置默认命名空间为"WindEagle.Web.UI.Controls".
打开AssemblyInfo.cs,作如下修改:
using System.Reflection;
[assembly: AssemblyTitle("WindEagle.GoogleMap")]
[assembly: AssemblyDescription("封装Google Map API的GoogleMap ASP.NET Web服务器控件")]
[assembly: AssemblyCompany("WindEagle")]
[assembly: AssemblyProduct("WindEagle.GoogleMap")]
[assembly: AssemblyCopyright("Copyright © WindEagle 2008")]
[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.0.0")]
三. 在项目中添加一个ASP.NET Server Control,命名为GoogleMap.cs.
导入如下命名空间:
using System;
using System.ComponentModel;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Drawing.Design;
我们初步设计的GoogleMap控件应该有以下这些属性:
1. Height和Width, 因为Google Map的大小不能为零,且高宽比例一定,所以我决定重写继承于WebControl的Height和Width属性.
private static readonly Unit DefaultWidth = new Unit("1200px");
private static readonly Unit DefaultHeight = new Unit("960px");
public override Unit Height
public override Unit Width
[
Bindable(true),
Category("Google"),
DefaultValue(0),
Description("The zoom.")
]
public virtual int Zoom
[
Bindable(true),
Category("Google"),
DefaultValue(0),
Description("The latitude.")
]
public virtual double Latitude
[
Bindable(true),
Category("Google"),
DefaultValue(0),
Description("The longitude.")
]
public virtual double Longitude
[
Bindable(true),
Category("Google"),
DefaultValue(""),
Description("The address."),
Localizable(true)
]
public virtual string Address
[
Bindable(true),
Category("Google"),
DefaultValue(""),
Description("The user key obtained from google map api.")
]
public virtual string Key
protected override HtmlTextWriterTag TagKey
using System.Web.UI.Design;
namespace WindEagle.Web.UI.Controls
[AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[ToolboxData("<{0}:GoogleMap runat=\"server\"></{0}:GoogleMap>")]
[Designer(typeof(GoogleMapDesigner))]
public class GoogleMap : WebControl
好了,下一篇文章中我将给GoogleMap类添加更多实用的属性.
Map API的GoogleMap Web服务器控件,这样,用ASP.NET创建基于Google Map的网站就非常简单啦!
下面就让我们从头开始吧!
一. 首先打开Visual Studio 2008(其他IDE也可以),创建一个C#类库项目,命名为WindEagle.GoogleMap,勾选"创建解决方案目录"选项.
二. 删除默认的Class1.cs,修改项目属性,设置默认命名空间为"WindEagle.Web.UI.Controls".
打开AssemblyInfo.cs,作如下修改:
using System.Reflection;
[assembly: AssemblyTitle("WindEagle.GoogleMap")]
[assembly: AssemblyDescription("封装Google Map API的GoogleMap ASP.NET Web服务器控件")]
[assembly: AssemblyCompany("WindEagle")]
[assembly: AssemblyProduct("WindEagle.GoogleMap")]
[assembly: AssemblyCopyright("Copyright © WindEagle 2008")]
[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.0.0")]
三. 在项目中添加一个ASP.NET Server Control,命名为GoogleMap.cs.
导入如下命名空间:
using System;
using System.ComponentModel;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Drawing.Design;
我们初步设计的GoogleMap控件应该有以下这些属性:
1. Height和Width, 因为Google Map的大小不能为零,且高宽比例一定,所以我决定重写继承于WebControl的Height和Width属性.
private static readonly Unit DefaultWidth = new Unit("1200px");
private static readonly Unit DefaultHeight = new Unit("960px");
public override Unit Height
public override Unit Width
[
Bindable(true),
Category("Google"),
DefaultValue(0),
Description("The zoom.")
]
public virtual int Zoom
[
Bindable(true),
Category("Google"),
DefaultValue(0),
Description("The latitude.")
]
public virtual double Latitude
[
Bindable(true),
Category("Google"),
DefaultValue(0),
Description("The longitude.")
]
public virtual double Longitude
[
Bindable(true),
Category("Google"),
DefaultValue(""),
Description("The address."),
Localizable(true)
]
public virtual string Address
[
Bindable(true),
Category("Google"),
DefaultValue(""),
Description("The user key obtained from google map api.")
]
public virtual string Key
protected override HtmlTextWriterTag TagKey
using System.Web.UI.Design;
namespace WindEagle.Web.UI.Controls
[AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[ToolboxData("<{0}:GoogleMap runat=\"server\"></{0}:GoogleMap>")]
[Designer(typeof(GoogleMapDesigner))]
public class GoogleMap : WebControl
好了,下一篇文章中我将给GoogleMap类添加更多实用的属性.
相关文章推荐
- 用C#创建一个封装Google Map API的GoogleMap Web服务器控件(二) (转)
- 用C#创建一个封装Google Map API的GoogleMap Web服务器控件(二)
- 用C#创建一个封装Google Map API的GoogleMap Web服务器控件(一) (转)
- 【C#】对异步请求处理程序IHttpAsyncHandler的理解和分享一个易用性封装 【手记】走近科学之为什么明明实现了IEnumerable<T>的类型却不能调用LINQ扩展方法 【手记】手机网页弹出层后屏蔽底层的滑动响应 【手记】ASP.NET提示“未能创建类型”处理 【Web】一个非常简单的移动web消息框 【手记】解决EXCEL跑SQL遇“查询无法运行或数据库表无法打开...”
- C# Generator 2D map (随机创建一个2D地表)
- Google Map API使用详解(十)——使用JavaScript创建地图详解(上)
- google map api javascript xml 生成一个简单的地图
- jQuery Google Charts----一个封装google chart api的jquery插件
- 将创建线程的API-pthread_create封装成一个线程类
- Google Map API使用详解(十)——使用JavaScript创建地图详解(上)
- jQuery Google Charts----一个封装google chart api的jquery插件
- jQuery Google Charts----一个封装google chart api的jquery插件 饼状图
- java1.8一个不错的api调用栈(1)从Stream<?>创建一个Map
- 将创建进程的API-posix_spawn封装成一个进程类
- 在 Linux 上使用 Google Maps API Version 2、DB2/Informix、PHP 和 JMeter 创建地图
- 使用PHP创建一个REST API(译)
- 关于注册Google Map api key的方法和解决网页无法显示的问题
- jquery与google map api结合使用 控件,监听器
- 在C#中使用Ribbon界面(一)——创建一个Ribbon窗口
- keytool输出sha1,造成Google Map API Key无法获取的解决办法