lixaokui
路人甲
路人甲
  • 注册日期2003-12-25
  • 发帖数768
  • QQ28796446
  • 铜币27枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:2823回复:7

MapObjects 2.2在Visual Studio.Net环境里的开发

楼主#
更多 发布于:2004-09-22 15:49
<TABLE cellSpacing=6 cellPadding=6 width="100%" border=0>

<TR>
<TD width="100%">
<P align=center><FONT face=黑体 size=3>MapObjects 2.2</FONT><FONT size=3>在</FONT><FONT face=黑体 size=3>Visual Studio.Net</FONT><FONT size=3>环境里的开发</FONT></P>
<HR>
</TD></TR>
<TR>
<TD width="100%"><B></B><FONT face=Arial size=3></FONT><FONT size=3></FONT><B><FONT size=3></FONT><FONT face=宋体 size=3></FONT></B><B>
<P ><FONT face=Arial size=2>MapObjects 2.2 SDK for .NET</FONT><FONT size=2>简介</FONT></P></B>
<P  align=justify><FONT size=2>虽然</FONT><FONT face=Arial size=2>.NET</FONT><FONT size=2>应用程序不能直接使用</FONT><FONT face=Arial size=2>ActiveX</FONT><FONT size=2>控件,但是</FONT><FONT face=Arial size=2>.NET</FONT><FONT size=2>框架提供的与</FONT><FONT face=Arial size=2>COM</FONT><FONT size=2>协同工作的能力可以让我们在</FONT><FONT face=Arial size=2>.NET</FONT><FONT size=2>项目当中无缝地利用</FONT><FONT face=Arial size=2>ActiveX</FONT><FONT size=2>控件。</FONT></P>
<P  align=justify><FONT face=Arial size=2>ESRI</FONT><FONT size=2>为</FONT><FONT face=Arial size=2>MapObjects 2.2 ActiveX</FONT><FONT size=2>控件提供了运行环境可调用包装(</FONT><FONT face=Arial size=2>RCW</FONT><FONT size=2>),让我们可以在</FONT><FONT face=Arial size=2>.NET</FONT><FONT size=2>的项目中创建、调用</FONT><FONT face=Arial size=2>MapObjects</FONT><FONT size=2>的</FONT><FONT face=Arial size=2>Map</FONT><FONT size=2>控件和其他对象的方法。</FONT><FONT face=Arial size=2>MapObjects</FONT><FONT size=2>库里的每一个</FONT><FONT face=Arial size=2>COM</FONT><FONT size=2>类都由一个</FONT><FONT face=Arial size=2>RCW</FONT><FONT size=2>类在扮演。举个例子,</FONT><FONT face=Arial size=2>RCW</FONT><FONT size=2>类</FONT><FONT face=Arial size=2>MapLayerClass</FONT><FONT size=2>包装了</FONT><FONT face=Arial size=2>COM</FONT><FONT size=2>类</FONT><FONT face=Arial size=2>MapLayer</FONT><FONT size=2>。每一个</FONT><FONT face=Arial size=2>RCW</FONT><FONT size=2>类都包含了所有能从对应的</FONT><FONT face=Arial size=2>COM</FONT><FONT size=2>类访问到的公有成员。</FONT></P>
<P  align=justify><FONT face=Arial size=2>MapObjects 2.2</FONT><FONT size=2>的</FONT><FONT face=Arial size=2>RCW</FONT><FONT size=2>属于</FONT><FONT face=Arial size=2>ESRI.MapObjects 2.Core</FONT><FONT size=2>名称空间,它定义在名为</FONT><FONT face=Arial size=2>ESRI.MapObjects 2.Core.dll</FONT><FONT size=2>和</FONT><FONT face=Arial size=2>ESRI.MapObjects 2.Control.dll</FONT><FONT size=2>的两个互操作层组合体。除了这两个主要的,另外还有两个支持对</FONT><FONT face=Arial size=2>MapObjects</FONT><FONT size=2>软件进行扩展的互操作层组合体,</FONT><FONT face=Arial size=2>ESRI.MapObjects 2.Custom.dll</FONT><FONT size=2>和</FONT><FONT face=Arial size=2>ESRI.MapObjects 2.MemTable.dll</FONT><FONT size=2>。前者包含了用户定制自己的图符、渲染方式和投影方式的定义,后者包含了</FONT><FONT face=Arial size=2>MapObject2.1</FONT><FONT size=2>发布时推出的内存表(</FONT><FONT face=Arial size=2>MemTable</FONT><FONT size=2>)功能的扩展库。另外名称空间里也包含了以原始的类的名字来命名的接口。举个例子,</FONT><FONT face=Arial size=2>RCW</FONT><FONT size=2>类</FONT><FONT face=Arial size=2>MapLayerClass</FONT><FONT size=2>就实现了一个名为</FONT><FONT face=Arial size=2>MapLayer</FONT><FONT size=2>的接口。这个接口暴露了所有从原始的类可直接获得的成员,所以不管是接口还是原始的类都可被用来调用</FONT><FONT face=Arial size=2>COM</FONT><FONT size=2>对象的成员。不过从</FONT><FONT face=Arial size=2>ESRI</FONT><FONT size=2>的文档来看,更习惯于使用接口。</FONT></P>
<P ><FONT face=Arial size=2> [VB.NET]</FONT></P>
<P ><FONT face=Arial size=2> Dim pnt As ESRI.MapObjects2.Core.Point = New ESRI.MapObjects2.Core.PointClass()</FONT></P>
<P ><FONT face=Arial size=2> [C#]</FONT></P>
<P ><FONT face=Arial size=2> ESRI.MapObjects2.Core.Point pnt = newESRI.MapObjects2.Core.PointClass();</FONT></P>
<P ><FONT size=2>另外,需要记住的是,在使用这些包装类的同时,其实仍然在访问</FONT><FONT face=Arial size=2>MapObjects 2.2</FONT><FONT size=2><FONT>的</FONT></FONT><FONT face=Arial size=2>ActiveX</FONT><FONT size=2>控件,所以不管是你用于开发的机器,还是今后部署了你的应用的机器,仍然需要安装</FONT><FONT face=Arial size=2>MapObjects 2.2</FONT><FONT size=2>产品,当然后者一般建议安装</FONT><FONT face=Arial size=2>MapObjects 2.2</FONT><FONT size=2>的运行时安装包。</FONT></P>
<P > </P><B>
<P ><FONT face=Arial size=2>MapObjects 2.2</FONT><FONT size=2>在</FONT><FONT face=Arial size=2>Visual Studio .Net</FONT><FONT size=2>环境里的开发实例</FONT></P></B>
<P ><FONT size=2>现在,我们将在</FONT><FONT face=Arial size=2>Visual Studio.NET</FONT><FONT size=2>环境里构造一个简单的电子地图的应用。它可以增加一个图层,实现地图的放大、漫游和全景显示,并且可以实现要素的定位功能。</FONT></P><B>
<P ><FONT size=2>第一步:创建一个新的窗口应用</FONT></P></B>
<P  align=left><FONT size=2>打开</FONT><FONT face=Arial size=2>Visual Studio.NET</FONT><FONT size=2>,点击主文档窗口里</FONT><FONT face=Arial size=2><B>Start Page</B></FONT><FONT size=2>上的</FONT><FONT face=Arial size=2><B>New Project</B></FONT><FONT size=2>按钮或菜单条上</FONT><FONT face=Arial size=2><B>File</B></FONT><FONT size=2>菜单项里的</FONT><FONT face=Arial size=2><B>New</B></FONT><FONT size=2>的子项</FONT><FONT face=Arial size=2><B>Project</B></FONT><FONT size=2>,会弹出一个窗口(图〈</FONT><FONT face=Arial size=2>1</FONT><FONT size=2>〉),在窗口的左手边我们可以选择是创建一个</FONT><A><FONT face=Arial size=2>Visual Basic</FONT><FONT size=2>(</FONT><FONT face=Arial size=2>.NET</FONT><FONT size=2>)的工程</FONT></A><FONT size=2>还是</FONT><FONT face=Arial size=2>Visual C#</FONT><FONT size=2>的工程。选定了工程类别,在右手边选择</FONT><FONT face=Arial size=2><B>Windows Application</B></FONT><FONT size=2>图标,并在</FONT><FONT face=Arial size=2><B>Name</B></FONT><FONT size=2>文字输入行内输入当前工程的名称,如</FONT><FONT face=Arial size=2>GettingStarted</FONT><FONT size=2>,最后按</FONT><FONT face=Arial size=2><B>OK</B></FONT><FONT size=2>按钮确定。此时主文档窗口里就生成了一个设计状态下的空白窗体。</FONT></P>
<P  align=center><FONT size=2><IMG src="http://www.esrichina-bj.cn/library/chinanews/image/cn14-wang1.gif" border=0></FONT></P>
<P  align=left><B><FONT size=2>第二步:加入</FONT><FONT face=Arial size=2>MapObjects 2.2</FONT><FONT size=2>的</FONT><FONT face=Arial size=2>ActiveX</FONT><FONT size=2>控件</FONT></P></B>
<P ><FONT size=2>先点击</FONT><FONT face=Arial size=2><B>Tools</B></FONT><FONT size=2>菜单的</FONT><FONT face=Arial size=2><B>Customize ToolBox</B></FONT><FONT size=2>菜单子项,会弹出一个窗口,在窗口的</FONT><FONT face=Arial size=2><B>.NET Framework Components</B></FONT><FONT size=2>标签页上,选中多选框内名为</FONT><FONT face=Arial size=2>AxMap</FONT><FONT size=2>的子项,然后按</FONT><FONT face=Arial size=2><B>OK</B></FONT><FONT size=2>按钮确定。以上的操作如果以前做过,这里可以不用再重复。</FONT></P>
<P ><FONT size=2>从浮动在主文档窗口左侧的</FONT><FONT face=Arial size=2>ToolBox</FONT><FONT size=2>窗口里找到</FONT><FONT face=Arial size=2>AxMap</FONT><FONT size=2>按钮<IMG src="http://www.esrichina-bj.cn/library/chinanews/image/cn14-wang2.gif" border=0>并双击它,这时一个</FONT><FONT face=Arial size=2>AxMap</FONT><FONT size=2>控件就加到前面创建的窗体上了。</FONT></P><B>
<P ><FONT size=2>第三步:电子地图功能的实现</FONT><FONT face=Arial size=2>(</FONT><FONT size=2>这里以</FONT><FONT face=Arial size=2>Visual Basic.NET</FONT><FONT size=2>的工程为例</FONT><FONT face=Arial size=2>)</FONT></P></B>
<P ><FONT size=2>为了程序书写的方便,在代码窗口的头上加上</FONT><FONT face=Arial size=2>ImportsESRI.MapObjects2.Core</FONT></P>
<P ><FONT size=2>语句,这样做的好处可以举个例子说明,没有这行语句的时候,我们要声明一个</FONT><FONT face=Arial size=2>Symbol</FONT><FONT size=2>接口类型的变量必须很完整的写成</FONT><FONT face=Arial size=2>Dim sym AsESRI.MapObjects2.Core.Symbol</FONT><FONT size=2>,</FONT></P>
<P ><FONT size=2>若是添加了这行语句,以上的变量声明只需写成</FONT><FONT face=Arial size=2>Dim sym As Symbol</FONT><FONT size=2>就行了。接下来开始实现具体的功能。</FONT></P>
<P > </P>
<BLOCKQUOTE><B>
<P ><FONT face=Arial size=2>1</FONT><FONT size=2><FONT>.给地图控件加载图层</FONT></FONT></P></B></BLOCKQUOTE>
<P ><FONT size=2>这里以加载</FONT><FONT face=Arial size=2>shapefile</FONT><FONT size=2>格式的数据为例,先创建一个全局的方法</FONT><FONT face=Arial size=2>AddShpFile</FONT><FONT size=2>,实现如下:</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>Public</FONT> <FONT color=#0000ff size=1>Sub</FONT> AddShpFile(<FONT color=#0000ff size=1>ByVal</FONT> FilePath <FONT color=#0000ff size=1>As</FONT> <FONT color=#0000ff size=1>String</FONT>, <FONT color=#0000ff size=1>ByVal</FONT> FileName <FONT color=#0000ff size=1>As</FONT> <FONT color=#0000ff size=1>String</FONT>)</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>  Dim</FONT> dc <FONT color=#0000ff size=1>As</FONT> <FONT color=#0000ff size=1>New</FONT> DataConnection()</FONT></P>
<P ><FONT face=Arial size=2>  dc.Database() = FilePath</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>  If</FONT> dc.Connect <FONT color=#0000ff>Then</FONT></FONT></P><FONT face=Arial size=1>
<P ></FONT><FONT face=Arial size=2><FONT color=#0000ff>    Dim</FONT> lyr <FONT color=#0000ff size=1>As</FONT> <FONT color=#0000ff size=1>New</FONT> MapLayer()</FONT></P>
<P ><FONT face=Arial size=2>    lyr.GeoDataset = dc.FindGeoDataset(FileName)</FONT></P>
<P ><FONT face=Arial size=2>    AxMap1.Layers.Add(lyr)</FONT></P>
<P ><FONT face=Arial color=#0000ff size=2> Else</FONT></P>
<P ><FONT face=Arial size=2>  MsgBox("No such a file exists")</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>End</FONT> <FONT color=#0000ff>If</FONT></FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>End</FONT> <FONT color=#0000ff>Sub</FONT></FONT></P>
<P ><FONT size=2>然后在窗体上添加一个</FONT><FONT face=Arial size=2>Button</FONT><FONT size=2>控件,并在它的</FONT><FONT face=Arial size=2>Click</FONT><FONT size=2>事件里调用</FONT><FONT face=Arial size=2>AddShpFile</FONT><FONT size=2>方法:</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>Private</FONT> <FONT color=#0000ff size=1>Sub</FONT> Button1_Click(<FONT color=#0000ff size=1>ByVal</FONT> sender <FONT color=#0000ff size=1>As</FONT> System.Object, _</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff> ByVal</FONT> e <FONT color=#0000ff size=1>As</FONT> System.EventArgs) <FONT color=#0000ff size=1>Handles</FONT> Button1.Click</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff> Dim</FONT> FilePath <FONT color=#0000ff size=1>As</FONT> <FONT color=#0000ff size=1>String</FONT> = "D:\ESRI\MapObjects2.2\Samples\Data\World"</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff> Dim</FONT> FileName <FONT color=#0000ff size=1>As</FONT> <FONT color=#0000ff size=1>String</FONT> = "country.shp"</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#007f00>'</FONT></FONT><FONT color=#007f00 size=2>以上两行根据实际情况进行适当修改</FONT></P>
<P ><FONT face=Arial size=2>AddShpFile(FilePath, FileName)</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>End</FONT> <FONT color=#0000ff>Sub</FONT></FONT></P>
<P ><FONT size=2>此时按</FONT><FONT face=Arial size=2>F5</FONT><FONT size=2>键运行程序,点击窗口上的</FONT><FONT face=Arial size=2>Button1</FONT><FONT size=2>按钮,一幅世界地图就加载上来了。</FONT></P>
<P > </P>
<BLOCKQUOTE><B>
<P ><FONT face=Arial size=2>2</FONT><FONT size=2><FONT>.</FONT> <FONT>地图的放大、漫游和全景显示</FONT></FONT></P></BLOCKQUOTE></B>
<P ><FONT size=2>在</FONT><FONT face=Arial size=2>AxMap</FONT><FONT size=2>控件的</FONT><FONT face=Arial size=2>MouseDownEvent</FONT><FONT size=2>事件里加入实现地图的放大和漫游的代码,如下:</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>Private</FONT> <FONT color=#0000ff size=1>Sub</FONT> AxMap1_MouseDownEvent(<FONT color=#0000ff size=1>ByVal</FONT> sender <FONT color=#0000ff size=1>As</FONT> <FONT color=#0000ff size=1>Object</FONT>, _</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>ByVal</FONT> e <FONT color=#0000ff size=1>As</FONT> ESRI.MapObjects2.Core.MouseDownEventArgs) <FONT color=#0000ff size=1>Handles</FONT> AxMap1.MouseDownEvent</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>If</FONT> e.button = 1 <FONT color=#0000ff>Then</FONT></FONT></P><FONT face=Arial size=1>
<P ></FONT><FONT face=Arial size=2><FONT color=#007f00>'</FONT></FONT><FONT face=宋体 color=#007f00 size=2>在</FONT><FONT face=Arial color=#007f00 size=1>AxMap</FONT><FONT face=宋体 color=#007f00 size=2>控件上按下鼠标左键后做拉框操作,实现地图放大功能</FONT></P><FONT size=1>
<P ></FONT><FONT face=Arial size=2><FONT color=#0000ff>Dim</FONT> pRect <FONT color=#0000ff size=1>As</FONT> Rectangle</FONT></P>
<P ><FONT face=Arial size=2>pRect = <FONT color=#0000ff size=1>Me</FONT>.AxMap1.TrackRectangle</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>If</FONT> <FONT color=#0000ff size=1>Not</FONT> pRect <FONT color=#0000ff size=1>Is</FONT> <FONT color=#0000ff size=1>Nothing</FONT> <FONT color=#0000ff>Then</FONT></FONT></P><FONT face=Arial size=1>
<P ></FONT><FONT face=Arial size=2><FONT color=#0000ff>Me</FONT>.AxMap1.MousePointer = MousePointerConstants.moZoomIn</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>Me</FONT>.AxMap1.Extent = pRect</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>End</FONT> <FONT color=#0000ff>If</FONT></FONT></P><FONT face=Arial size=1>
<P ></FONT><FONT face=Arial color=#0000ff size=2>Else</FONT></P><FONT face=Arial size=1>
<P ></FONT><FONT face=Arial size=2><FONT color=#007f00>'</FONT></FONT><FONT face=宋体 color=#007f00 size=2>在</FONT><FONT face=Arial color=#007f00 size=1>AxMap</FONT><FONT face=宋体 color=#007f00 size=2>控件上按下鼠标右键键后做拖动操作,实现地图漫游功能</FONT></P><FONT size=1>
<P ></FONT><FONT face=Arial size=2><FONT color=#0000ff>Me</FONT>.AxMap1.MousePointer = MousePointerConstants.moPanning</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>Me</FONT>.AxMap1.Pan()</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>Me</FONT>.AxMap1.MousePointer = MousePointerConstants.moPan</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>End</FONT> <FONT color=#0000ff>If</FONT></FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>End</FONT> <FONT color=#0000ff>Sub</FONT></FONT></P><FONT face=Arial size=3>
<P ></FONT><FONT face=宋体 size=2>在</FONT><FONT face=Arial size=2>AxMap</FONT><FONT face=宋体 size=2>控件的</FONT><FONT face=Arial size=2>DblClick</FONT><FONT face=宋体 size=2>事件里加入实现地图全景显示的代码,如下</FONT><FONT face=Arial size=2>:</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>Private</FONT> <FONT color=#0000ff size=1>Sub</FONT> AxMap1_DblClick(<FONT color=#0000ff size=1>ByVal</FONT> sender <FONT color=#0000ff size=1>As</FONT> <FONT color=#0000ff size=1>Object</FONT>, _</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>ByVal</FONT> e <FONT color=#0000ff size=1>As</FONT> System.EventArgs) <FONT color=#0000ff size=1>Handles</FONT> AxMap1.DblClick</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#007f00>'</FONT></FONT><FONT color=#007f00 size=2>在</FONT><FONT face=Arial color=#007f00 size=1>AxMap</FONT><FONT color=#007f00 size=2>控件上双击,实现地图全景显示功能</FONT></P>
<P ><FONT face=Arial size=2>AxMap1.Extent = AxMap1.FullExtent</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>End</FONT> <FONT color=#0000ff>Sub</FONT></FONT></P>
<P > </P>
<BLOCKQUOTE><B>
<P ><FONT face=Arial size=2>3</FONT><FONT size=2><FONT>.</FONT> <FONT>地图要素定位</FONT></FONT></P></BLOCKQUOTE></B>
<P ><FONT size=2>在窗体上添加一个</FONT><FONT face=Arial size=2>TextBox</FONT><FONT size=2>控件,在它的</FONT><FONT face=Arial size=2>KeyDown</FONT><FONT size=2>事件里加入实现地图要素定位的代码,如下:</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>Private</FONT> <FONT color=#0000ff size=1>Sub</FONT> TextBox1_KeyDown(<FONT color=#0000ff size=1>ByVal</FONT> sender <FONT color=#0000ff size=1>As</FONT> <FONT color=#0000ff size=1>Object</FONT>, _</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>ByVal</FONT> e <FONT color=#0000ff size=1>As</FONT> System.Windows.Forms.KeyEventArgs) <FONT color=#0000ff size=1>Handles</FONT> TextBox1.KeyDown</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>If</FONT> e.KeyCode = Keys.Return <FONT color=#0000ff>Then</FONT></FONT></P><FONT face=Arial size=1>
<P ></FONT><FONT face=Arial size=2><FONT color=#0000ff>Dim</FONT> exp <FONT color=#0000ff size=1>As</FONT> <FONT color=#0000ff size=1>String</FONT> = "NAME = '" + TextBox1.Text + "'"</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>Dim</FONT> lyr <FONT color=#0000ff size=1>As</FONT> MapLayer = <FONT color=#0000ff size=1>Me</FONT>.AxMap1.Layers.Item(0)</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>Dim</FONT> recs <FONT color=#0000ff size=1>As</FONT> Recordset = lyr.SearchExpression(exp)</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>If</FONT> <FONT color=#0000ff size=1>Not</FONT> recs.EOF <FONT color=#0000ff>Then</FONT></FONT></P><FONT face=Arial size=1>
<P ></FONT><FONT face=Arial size=2><FONT color=#0000ff>Dim</FONT> res <FONT color=#0000ff size=1>As</FONT> Polygon = recs.Fields.Item("Shape").Value</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>Dim</FONT> ext <FONT color=#0000ff size=1>As</FONT> Rectangle = res.Extent</FONT></P>
<P ><FONT face=Arial size=2>ext.ScaleRectangle(2.0)</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>Me</FONT>.AxMap1.Extent = ext</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>Me</FONT>.AxMap1.CtlRefresh()</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>Me</FONT>.AxMap1.FlashShape(res, 3)</FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>End</FONT> <FONT color=#0000ff>If</FONT></FONT></P><FONT face=Arial size=1>
<P ></FONT><FONT face=Arial size=2><FONT color=#0000ff>End</FONT> <FONT color=#0000ff>If</FONT></FONT></P>
<P ><FONT face=Arial size=2><FONT color=#0000ff>End</FONT> <FONT color=#0000ff>Sub</FONT></FONT></P>
<P ><FONT size=2>此时按</FONT><FONT face=Arial size=2>F5</FONT><FONT size=2>键运行程序,点击窗口上的</FONT><FONT face=Arial size=2>Button1</FONT><FONT size=2>按钮加载世界地图,然后在</FONT><FONT face=Arial size=2>TextBox</FONT><FONT size=2>文字输入行里输入想要查询的国家的名称,比如</FONT><FONT face=Arial size=2>China</FONT><FONT size=2>,最后按回车键确定,</FONT><FONT face=Arial size=2>China</FONT><FONT size=2>就会显示到地图的中央,并高亮闪烁三次,如图〈</FONT><FONT face=Arial size=2>2</FONT><FONT size=2>〉。</FONT></P>
<P  align=center><IMG src="http://www.esrichina-bj.cn/library/chinanews/image/cn14-wang3.gif" border=0></P>
<P ><FONT size=2>到这里,一个简单的电子地图的应用程序就完成了。有过在</FONT><FONT face=Arial size=2>VB</FONT><FONT size=2>、</FONT><FONT face=Arial size=2>VC</FONT><FONT size=2>或</FONT><FONT face=Arial size=2>Delphi</FONT><FONT size=2>环境里开发</FONT><FONT face=Arial size=2>MapObjects</FONT><FONT size=2>的</FONT><FONT face=Arial size=2>GIS</FONT><FONT size=2>工作者可能会发现,了解了</FONT><FONT face=Arial size=2>.NET</FONT><FONT size=2>的工作机制之后,在</FONT><FONT face=Arial size=2>.NET</FONT><FONT size=2>环境里开发</FONT><FONT face=Arial size=2>MapObjects 2.2</FONT><FONT size=2>的应用并不会有太多的困难。尽管如此,还是有几个问题是需要我们注意的。</FONT></P>
<P > </P><B>
<P ><FONT face=Arial size=2>1.MapObjects</FONT><FONT size=2>的</FONT><FONT face=Arial size=2>Refresh</FONT><FONT size=2>方法与</FONT><FONT face=Arial size=2>AxHost</FONT><FONT size=2>的</FONT><FONT face=Arial size=2>Refresh</FONT><FONT size=2>方法的比较</FONT></P></B>
<P ><FONT face=Arial size=2>.NET</FONT><FONT size=2>框架提供了一个名叫</FONT><FONT face=Arial size=2>AxHost</FONT><FONT size=2>的类,它是一种控件。凡是以</FONT><FONT face=Arial size=2>AxHost</FONT><FONT size=2>为基类继承而来的类都可以置于</FONT><FONT face=Arial size=2>Windows</FONT><FONT size=2>的窗口上。</FONT><FONT face=Arial size=2>ActiveX</FONT><FONT size=2>控件在</FONT><FONT face=Arial size=2>.NET</FONT><FONT size=2>里的应用就是通过利用</FONT><FONT face=Arial size=2>AxHost</FONT><FONT size=2>类来实现的。</FONT><FONT face=Arial size=2>MapObjects 2.2</FONT><FONT size=2>中的</FONT><FONT face=Arial size=2>AxMap</FONT><FONT size=2>类就是从</FONT><FONT face=Arial size=2>AxHost</FONT><FONT size=2>类继承而来的,所以它能置于</FONT><FONT face=Arial size=2>Windows</FONT><FONT size=2>的窗口之上,当然它包含了对潜在的</FONT><FONT face=Arial size=2>ActiveX</FONT><FONT size=2>控件</FONT><FONT face=Arial size=2>Map</FONT><FONT size=2>的引用。可是,</FONT><FONT face=Arial size=2>AxHost</FONT><FONT size=2>也有一个名叫</FONT><FONT face=Arial size=2>Refresh</FONT><FONT size=2>的方法,这刚好与</FONT><FONT face=Arial size=2>MapObjects 2.2</FONT><FONT size=2>的</FONT><FONT face=Arial size=2>ActiveX</FONT><FONT size=2>控件</FONT><FONT face=Arial size=2>Map</FONT><FONT size=2>的一个方法同名。所以当在调用</FONT><FONT face=Arial size=2>AxMap.Refresh</FONT><FONT size=2>方法的时候,其实是在调用从</FONT><FONT face=Arial size=2>AxHost</FONT><FONT size=2>继承下来的方法。而</FONT><FONT face=Arial size=2>MapObjects</FONT><FONT size=2>自己的</FONT><FONT face=Arial size=2>Refresh</FONT><FONT size=2>方法已被改名为</FONT><FONT face=Arial size=2>CtlRefresh</FONT><FONT size=2>,为了实现刷新地图的功能,现在要改用</FONT><FONT face=Arial size=2>CtlRefresh</FONT><FONT size=2>,也就是</FONT><FONT face=Arial size=2>AxMap.CtlRefresh</FONT><FONT size=2>。事实上,像这样在</FONT><FONT face=Arial size=2>ActiveX</FONT><FONT size=2>控件的同名成员之前加上</FONT><FONT face=Arial size=2><FONT>“</FONT>Ctl<FONT>”</FONT></FONT><FONT size=2>的前缀是一种标准的协定。</FONT></P><B>
<P ><FONT face=Arial size=2>2.</FONT><FONT size=2>数据类型匹配</FONT></P></B>
<P ><FONT face=Arial size=2>C#</FONT><FONT size=2>语言本身对数据类型的检查就很严格,我们常常需要通过显式的类型转换来满足它的要求。尽管从语法来讲在</FONT><FONT face=Arial size=2>VB.NET</FONT><FONT size=2>环境里这方面的工作我们可以做得比较</FONT><FONT face=Arial size=2>“</FONT><FONT size=2>模糊</FONT><FONT face=Arial size=2>”</FONT><FONT size=2>,但事实上,如果在工程里做了相应的设置,</FONT><FONT face=Arial size=2>VB.NET</FONT><FONT size=2>对同样的问题也会变得很</FONT><FONT><FONT face=Arial size=2>“</FONT><FONT size=2>斤斤计较</FONT><FONT face=Arial size=2>”</FONT><FONT size=2>。所以为了程序在编译时和运行时更少地出现错误,必须规范这方面的工作。举个例子,应该是:</FONT></FONT></P>
<P ><FONT face=Arial size=2>[C#]</FONT></P>
<P ><FONT face=Arial size=2>ESRI.MapObjects2.Core.MapLayer lyr = (ESRI.MapObjects2.Core.MapLayer) axMap1.Layers.Item(0);</FONT></P>
<P ><FONT face=Arial size=2>[Visual</FONT><FONT size=2> </FONT><FONT face=Arial size=2>Basic]</FONT></P>
<P ><FONT face=Arial size=2>Dim lyr As ESRI.MapObjects2.Core.MapLayer = CType(AxMap1.Layers.Item(0), ESRI.MapObjects2.Core.MapLayer)</FONT></P>
<P ><FONT size=2>而不是:</FONT></P>
<P ><FONT face=Arial size=2>[C#]</FONT></P>
<P ><FONT face=Arial size=2>ESRI.MapObjects2.Core.MapLayer lyr = axMap1.Layers.Item(0);</FONT></P>
<P ><FONT face=Arial size=2>[VB.NET]</FONT></P>
<P ><FONT face=Arial size=2>Dim lyr As ESRI.MapObjects2.Core.MapLayer = AxMap1.Layers.Item(0)</FONT></P>
<P ><FONT size=2>关于类型匹配还有一个很典型的例子就是</FONT><FONT face=Arial size=2>MapObjects </FONT><FONT size=2>中</FONT><FONT face=Arial size=2>Color</FONT><FONT size=2>的使用。</FONT><FONT face=Arial size=2>MapObjects </FONT><FONT size=2>中的</FONT><FONT face=Arial size=2>Color</FONT><FONT size=2>是</FONT><FONT face=Arial size=2>OLE_COLOR</FONT><FONT size=2>类型的,应用在</FONT><FONT face=Arial size=2>.NET</FONT><FONT size=2>里它等同于无符号的</FONT><FONT face=Arial size=2>32</FONT><FONT size=2>位整数行(</FONT><FONT face=Arial size=2>UINT32</FONT><FONT size=2>),</FONT></P>
<P ><FONT size=2>所以要做必要的类型转换,尽管转换是非常方便的:</FONT></P>
<P ><FONT face=Arial size=2>[C#]</FONT></P>
<P ><FONT face=Arial size=2>ESRI.MapObjects2.Core.Symbol sym = new ESRI.MapObjects2.Core.SymbolClass();</FONT></P>
<P ><FONT face=Arial size=2>sym.Color = Convert.ToUInt32(ESRI.MapObjects2.Core.ColorConstants.moRed);</FONT></P>
<P ><FONT face=Arial size=2>[VB.NET]</FONT></P>
<P ><FONT face=Arial size=2>Dim sym As ESRI.MapObjects2.Core.Symbol = New ESRI.MapObjects2.Core.Symbol()</FONT></P>
<P ><FONT face=Arial size=2>sym.Color = Convert.ToUInt32(ESRI.MapObjects2.Core.ColorConstants.moRed)</FONT></P><B>
<P ><FONT face=Arial size=2>3. </FONT><FONT size=2>常数的使用</FONT></P></B>
<P ><FONT face=Arial size=2>.NET</FONT><FONT size=2>为</FONT><FONT face=Arial size=2>MapObjects 2.2</FONT><FONT size=2>的常数枚举类型都作了包装,它们都是从</FONT><FONT face=Arial size=2>System.Enum</FONT><FONT size=2>类继承下来的。在代码中使用这些常数时必须使用完整的枚举名称来限定所用的常数。</FONT></P>
<P ><FONT face=Arial size=2>[C#]</FONT></P>
<P ><FONT face=Arial size=2>ESRI.MapObjects2.Core.Symbol sym = new ESRI.MapObjects2.Core.SymbolClass();</FONT></P>
<P ><FONT face=Arial size=2>sym.SymbolType = ESRI.MapObjects2.Core.SymbolTypeConstants.moFillSymbol;</FONT></P>
<P ><FONT face=Arial size=2>[Visual</FONT><FONT size=2> </FONT><FONT face=Arial size=2>Basic]</FONT></P>
<P ><FONT face=Arial size=2>Dim sym As ESRI.MapObjects2.Core.Symbol = New ESRI.MapObjects2.Core.SymbolClass()</FONT></P>
<P ><FONT face=Arial size=2>sym.SymbolType = ESRI.MapObjects2.Core.SymbolTypeConstants.moFillSymbol</FONT></P></TD></TR></TABLE>
喜欢0 评分0
西门吹血,有了鼓风机,就不用吹啦!
chaimin1400
路人甲
路人甲
  • 注册日期2003-10-11
  • 发帖数315
  • QQ
  • 铜币533枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2004-09-22 20:37
顶<img src="images/post/smile/dvbbs/em01.gif" /><img src="images/post/smile/dvbbs/em02.gif" />
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
2楼#
发布于:2004-09-22 20:39
<img src="images/post/smile/dvbbs/em01.gif" />
举报 回复(0) 喜欢(0)     评分
candycanqq
路人甲
路人甲
  • 注册日期2006-03-05
  • 发帖数57
  • QQ
  • 铜币264枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2006-04-19 17:03
<img src="images/post/smile/dvbbs/em01.gif" /><img src="images/post/smile/dvbbs/em02.gif" /><img src="images/post/smile/dvbbs/em03.gif" />
举报 回复(0) 喜欢(0)     评分
cheie
路人甲
路人甲
  • 注册日期2003-09-15
  • 发帖数39
  • QQ
  • 铜币245枚
  • 威望0点
  • 贡献值0点
  • 银元0个
4楼#
发布于:2006-04-25 16:21
说得很好<img src="images/post/smile/dvbbs/em01.gif" />
举报 回复(0) 喜欢(0)     评分
rongyuhb
路人甲
路人甲
  • 注册日期2006-04-12
  • 发帖数12
  • QQ
  • 铜币132枚
  • 威望0点
  • 贡献值0点
  • 银元0个
5楼#
发布于:2006-05-16 10:12
好详细啊,多谢,^_^
举报 回复(0) 喜欢(0)     评分
太子☆哥
路人甲
路人甲
  • 注册日期2006-11-09
  • 发帖数9
  • QQ
  • 铜币131枚
  • 威望0点
  • 贡献值0点
  • 银元0个
6楼#
发布于:2006-11-20 22:51
<P>请问一下  mo控件在asp.net里运行时不能显示加载的图层是不是也是因为这个原因??</P>
举报 回复(0) 喜欢(0)     评分
bayygyofn
路人甲
路人甲
  • 注册日期2006-11-23
  • 发帖数12
  • QQ
  • 铜币127枚
  • 威望0点
  • 贡献值0点
  • 银元0个
7楼#
发布于:2006-11-29 20:33
<img src="images/post/smile/dvbbs/em01.gif" /><img src="images/post/smile/dvbbs/em01.gif" />,多谢楼主!
举报 回复(0) 喜欢(0)     评分
游客

返回顶部