Developing GIS Applications with Arc Objects using C
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET GIS 应 用 开 发 Developing GIS Applications with Arc. Objects using C#. NET 江西省研究生优质课程 主讲:兰小机 GIS博士、教授 Email : landcom 8835@163. com QQ : 305333315 课件: ftp: //218. 87. 136. 94/
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET Chap. 3 使用Arc. Objects控件编程(6学 时) l 为了能够快速建构一个具有GIS功能的独立应用程序, Arc. GIS Engine为开发者提供了多个可视化的组件即控 件,如 License. Control 、Map. Control、 Page. Layout. Control、TOCControl、Toolbar. Control和 Symbology. Control等。 l 在VS. NET中使用Arc. Objects,需要使用ESRI interop程 序集,这些程序集在托管的. NET代码和非托管的COM代 码之间起了桥梁作用。 l ESRI interop程序集为Arc. GIS控件提供了能够位于. NET 窗体上的控件(继承自Ax. Host类),这些控件名前缀为 “Ax”,如Ax. Map. Control、Ax. Page. Layout. Control、
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET ØUsing Arc. GIS Engine controls in Winforms ØUsing Arc. GIS Engine Controls in WPF
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 本章内容: 1. Map. Control控件 2. Page. Layout. Control控件 3. TOCControl控件 4. Toolbar. Control及相关对象 5. Control Commands (Symbology. Control in Chapter 6) 6. 在WPF程序中使用Arc. GIS Engine控 件
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 3. 1. 1 Map. Control的主要接口 l Map. Control实现的主要接口有: ØIMap. Control. Default ØIMap. Control 2 ØIMap. Control 3 ØIMap. Control 4( new in 9. 2 ) ØIMap. Control. Events 2事件接口 ØITOCBuddy ØIToolbar. Buddy
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l IMap. Control 2. Extent: 地�的可�范� ; l IMap. Control 2. Full. Extent: 地�中所有� �的覆盖范�.
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET IMap. Control 2
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l IMap. Control 3接口继承IMap. Control 2,并增加了以下8个 属性和一个方法: Ø Custom. Property --object:使用该属性关联有用信息 Ø Document. Filename --string):返回Map. Control装入 的地图文档的文件名 Ø Document. Map --string :返回Map. Control最后装入的 地图(Map)名称 Ø Key. Intercept --int :返回或设置Map. Control截取键盘 按键信息
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET Øpublic bool Auto. Mouse. Wheel {get; set; }: 确定鼠标滚轮是否用于缩放地图的显示;缺省 情况下该属性为true。
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 引用控件本身 l 当使用IMap. Control 2接口时: IMap. Control 2 p. Map. Control = ax. Map. Control 1. Object as IMap. Control 2; 或IMap. Control 2 p. Map. Control = ax. Map. Control 1. Get. Ocx() as IMap. Control 2; l 当使用IMap. Control 3接口时: IMap. Control 3 p. Map. Control = ax. Map. Control 1. Object as IMap. Control 3; 或IMap. Control 3 p. Map. Control = ax. Map. Control 1. Get. Ocx() as IMap. Control 3;
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l 当使用IMap. Control 4接口时: IMap. Control 4 p. Map. Control; p. Map. Control = ax. Map. Control 1. Object as IMap. Control 4; 或 p. Map. Control = ax. Map. Control 1. Get. Ocx() as IMap. Control 4;
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 使用箭��、鼠�����地��航 l 使用箭头键平移(Panning)地图 ax. Map. Control 1. Key. Intercept = (int) esri. Key. Intercept. Arrow. Keys; ax. Map. Control 1. Auto. Keyboard. Scrolling=true; l 使用鼠标滚轮缩放地图 ax. Map. Control 1. Auto. Mouse. Wheel = true;
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET ax. Map. Control 1. Key. Intercept = (int) esri. Key. Intercept. Arrow. Keys; Auto. Keyboard. Scrolling=true; Constant esri. Key. Intercept. None Value 0 esri. Key. Intercept. Arrow. Ke 1 ys esri. Key. Intercept. Alt 2 esri. Key. Intercept. Tab 4 esri. Key. Intercept. Enter 8 Description No keys are intercepted. Intercepts the arrow keys, normally handled by the container to change control focus. Intercepts the Alt key, normally handled by a container to change focus. Intercepts the Tab key, normally handled by the container to change control focus. Intercepts the Enter key,
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 3. 1. 1. 5 ITOCBuddy l 该接口定义了以下2个方法: ØGet. Active. View Returns the underlying object implementing basic map and Active. View. This is used to populate the TOC. ØGet. Scale Returns the scale of the supplied Basic. Map, this allows for objects that do not support IMap.
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 3. 1. 1. 6 IToolbar. Buddy l Objects that implement the IToolbar. Buddy interface can be passed to the IToolbar. Control. Set. Buddy. Control method. l The Current. Tool is the tool used to interact with the display area of the IToolbar. Control. Buddy.
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l Samples: 1. Map. And. Page. Layout. Synch. App 2. Map. Control. Map. Tips 3. Map. Control. Geo. Events 4. Map. Control. Draw. Text 5. Map. Control. CADViewer 6. Map. Control. Save. Layer. File
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 下面是一个载入文档的例子-- ax. Map. Control 1. Load. Mx. File private void Load. Map. Document() { System. Windows. Forms. Open. File. Dialog open. File. Dialog 2; open. File. Dialog 2 = new Open. File. Dialog(); open. File. Dialog 2. Title = "Open Map Document"; open. File. Dialog 2. Filter = "Map Documents (*. mxd)|*. mxd"; open. File. Dialog 2. Show. Dialog(); string s. File. Path = open. File. Dialog 2. File. Name; if (ax. Map. Control 1. Check. Mx. File(s. File. Path)) { ax. Map. Control 1. Load. Mx. File(s. File. Path, 0, Type. Missing); } else { Message. Box. Show(s. File. Path + " is not a valid Arc. Map document"); return; }
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET IMx. Document 与IMap. Document
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET IApplication的属性、方法
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l IMx. Document. Activated. View与 Active. View 属 性 Ø 在Arc. Map的布局视图(layout view)状态下,图形元素 可以添加到页面布局(Page. Layout)或焦点地图(focus Map)的图形元素容器(graphics container )中;这时, IMx. Document. Active. View 属性与 IMx. Document. Activated. View 属性不同, Active. View 属性引用Page. Layout 对象, Activated. View属性引用焦点地图对象(如果该地图对象 处于活动状态) 。 Ø 在Arc. Map的数据视图(data view)状态下, Active. View 与Activated. View属性都引用焦点地图对 象。
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET IMap. Document m_Map. Document = new Map. Document. Class(); private void Load. Map. Doc() { Open. File. Dialog open. File. Dialog 2 = new Open. File. Dialog(); open. File. Dialog 2. Title = "Open Map Document"; open. File. Dialog 2. Filter = "Map Documents (*. mxd)|*. mxd"; open. File. Dialog 2. Show. Dialog(); string s. File. Path = open. File. Dialog 2. File. Name; If(m_Map. Document. get_Is. Map. Document(s. File. Path)) public bool get_Is. Map. Document (string { s. Document); m_Map. Document. Open(s. File. Path, ""); ax. Map. Control 1. Map = m_Map. Document. get_Map(0); ax. Map. Control 1. Refresh(); } public void Open ( string s. Document, string bs. Password); }
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET private void Save. Document() { if (m_Map. Document. get_Is. Read. Only(m_Map. Docum ent. Document. Filename) == true) { Message. Box. Show("This map document is read only!"); return; } m_Map. Document. Save(m_Map. Document. Uses. Relative. Path s, true); Message. Box. Show("Changes saved successfully!"); public void Save ( bool b. Use. Relative. Paths, } b. Create. Thumnbail); bool
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 使用鼠标拖曳确定地图显示的范围(拉框放大) private void ax. Map. Control 1_On. Mouse. Down (object sender, ESRI. Arc. GIS. Map. Control. IMap. Control. Events 2_On Mouse. Down. Event e) { //改变地图控件显示范围为当前拖曳的区域 ax. Map. Control 1. Extent = ax. Map. Control 1. Track. Rectangle(); //刷新地图 ax. Map. Control 1. Refresh(esri. View. Draw. Phase. esri public void Refresh ( esri. View. Draw. Phase View. Geography, null); phase, object layer. Or. Element, object envelope ); }
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 移动、旋转地图 l 在 Map. Control中有一种更简单便利的方法 pan()来移动其中的地图。 l 下面的方法使用在Map. Control控件的 On. Mose. Down事件中: ax. Map. Control 1. pan(); ax. Map. Control 1. Rotation = 45;
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET private void ax. Map. Control 1_On. Mouse. Down (object sender, ESRI. Arc. GIS. Map. Control. IMap. Control. Events 2_On Mouse. Down. Event e) { //产生拖曳多边形,并绘制 IGeometry p. Geom = ax. Map. Control 1. Track. Polygon(); Draw. Map. Shape(p. Geom); //刷新地图 //ax. Map. Control 1. Refresh(esri. View. Draw. Phase. esri View. Geography, null);
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET private void Draw. Map. Shape (IGeometry p. Geom) { IRgb. Color p. Color; p. Color = new Rgb. Color. Class(); p. Color. Red = 220; p. Color. Green = 112; p. Color. Blue = 60; public void Draw. Shape ( IGeometry Shape, object symbol ); //新建一个绘制图形的填充符号 ISimple. Fill. Symbol p. Fillsyl; p. Fillsyl = new Simple. Fill. Symbol. Class(); p. Fillsyl. Color = p. Color; object o. Fillsyl = p. Fillsyl; ax. Map. Control 1. Draw. Shape(p. Geom, ref o. Fillsyl); } ref
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET private void ax. Map. Control 1_On. Mouse. Down(object sender, IMap. Control. Events 2_On. Mouse. Down. Event e) { //产生拖曳多边形 IGeometry p. Geom = ax. Map. Control 1. Track. Polygon(); ax. Map. Control 1. Map. Select. By. Shape(p. Geom, null, false); ax. Map. Control 1. Refresh(esri. View. Draw. Phase. esri. View. Geo. Selection, null);
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l 清除选择集的方法 ax. Map. Control 1. Map. Clearselection(); ax. Map. Control 1. Active. View. Refresh();
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 3. 1. 5 实现鹰眼功能
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 两个控件的数据共享 private void ax. Map. Control 1_On. Map. Replaced (object sender, IMap. Control. Events 2_On. Map. Replaced. Event e) { IMap p. Map; p. Map = ax. Map. Control 1. Map; int i ; for( i = 0; i<= p. Map. Layer. Count - 1; i++) { ax. Map. Control 2. Map. Add. Layer(p. Map. get_Layer(i)); }
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 绘制鹰眼控件中的显示方框 l 主窗体视图的范围发生变化后,会触发控件的 On. Extent. Updated事件,绘制方框的方法就在这 个事件中进行: Ø private void ax. Map. Control 1_On. Extent. Updated(object sender, IMap. Control. Events 2_On. Extent. Updated. Event e) { ……. }
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET �建数据���面
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l Page. Layout. Control控件同样实现了多个接口 Ø IPage. Layout. Control. Default Ø IPage. Layout. Control 2 Ø IPage. Layout. Control 3 (New in 9. 2) Ø IPage. Layout. Control. Events
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET IPage. Layout. Control 3
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l Samples: 1. Page. Layout. Control. Load. Map. Document 2. Page. Layout. Control. Copy. Focus. Map 3. Page. Layout. Control. Overview 4. Page. Layout. Control. Page. Appearance 5. Page. Layout. Control. Print. Preview 6. Page. Layout. Control. Printing
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 3. 2. 1 Page. Layout. Control操作 MXD文 件 l 在Ax. Page. Layout. Control控件对MXD文件 的操作,与Map. Control类似。 Ø public void Load. Mx. File ( string file. Name, object password );
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 下面是在Page. Layout控件中打开一个MXD文件的方法: private void Open. Map. Document() { IMap. Document m_Map. Document = new Map. Document. Class(); Open. File. Dialog open. File. Dialog 1; open. File. Dialog 1 = new Open. File. Dialog(); open. File. Dialog 1. Title = "Open Map Document"; open. File. Dialog 1. Filter = "Map Documents (*. mxd)|*. mxd"; open. File. Dialog 1. Show. Dialog(); string s. File. Path = open. File. Dialog 1. File. Name; m_Map. Document. Open(s. File. Path, ""); ax. Page. Layout. Control 1. Page. Layout = m_Map. Document. Page. Layout; ax. Page. Layout. Control 1. Refresh();
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET private void Save. Document() { //Check that the document is not read only. if (m_Map. Document. get_Is. Read. Only(m_Map. Document. Docume nt. Filename) == true) { Message. Box. Show("This map document is read only!"); return; } //Save with the current relative path setting. m_Map. Document. Save(m_Map. Document. Uses. Relative. Paths, true); Message. Box. Show("Changes saved successfully!"); }
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET private void cmd. Save. As_Click(object sender, System. Event. Args e) { //Open a file dialog for saving map documents. save. File. Dialog 1. Title = "Save Map Document As"; save. File. Dialog 1. Filter = "Map Documents (*. mxd)|*. mxd"; save. File. Dialog 1. Show. Dialog(); string s. File. Path = save. File. Dialog 1. File. Name; if (s. File. Path == “”) return; if (s. File. Path == m_Map. Document. Filename) { //Save changes to the current document. Save. Document(); } else { //Save. As a new document with relative paths. m_Map. Document. Save. As (s. File. Path, true); //Open the document. Open. Document((s. File. Path)); Message. Box. Show("Document saved successfully!"); }
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 3. 3 TOCControl控件 1. TOCControl控件概述 ① ITOCControl与ITOCControl 2 ② ITOCControl. Events 2. 应用开发实例
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l TOCControl的“伙伴控件”可以在设计时 通过TOCControl属性页设置或用 Set. Buddy. Control方法通过编程设置。 l TOCControl的主要接口有:ITOCControl 、 ITOCControl 2、ITOCControl. Events
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 3. 3. 1. 1 ITOCControl与ITOCControl 2 l ITOCControl接口是任何与TOCControl 有关的任务的出发点,如设置控件的外观, 设置伙伴控件,管理图层的可见性和标签 的编辑。
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET ITOCControl l Label. Edit 、 Layer. Visibility. Edit : Label 、Visibility editing state. Ø esri. TOCControl. Autom atic Ø esri. TOCControl. Manua
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l 在C#. NET环境中,当查询接口到ITOCControl 或 ITOCControl 2时,必须使用Object属性或者容器 指定代码。 ITOCControl p. TOCControl; p. TOCControl = ax. TOCControl 1. Object as ITOCControl; 或 p. TOCControl = ax. TOCControl 1. Get. Ocx() as ITOCControl;
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l public void Hit. Test (int X, int Y, ref esri. TOCControl. Item. Type, ref IBasic. Map, ref ILayer, ref object Unk, ref object Data ); 用于获取用户在TOCControl 中点击的信相关息。 Ø Item. Type:TOCControl中项的类型,如none、map、layer、 heading 或legend class. Ø Basic. Map:指定地图 对象。 Ø Layer:ILayer 对象。 Ø Unk :ILegend. Group(图例组,一个图层可以有多种符号化 方案)对象。 Ø Data:用户点击的图例组中某个图例的索引号(长整型);联合 使用图例组Unk和这个索引号,可以获得用户点击的图例 (legend class);如果这个索引号为-1,表明用户点击的是图 例中的标题头。
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET IBasic. Map map = new Map. Class(); ILayer layer = new Feature. Layer. Class(); object other = new object(); object index = new object(); esri. TOCControl. Item item = new esri. TOCControl. Item(); ax. TOCControl 1. Hit. Test(e. x, e. y, ref item, ref map, ref layer, ref other, ref index); if (e. button == 1) //判断用�是否按了鼠�左� { if (layer == null) return; IFeature. Layer feature. Layer = layer as IFeature. Layer; if (feature. Layer == null) return; IGeo. Feature. Layer geo. Feature. Layer = (IGeo. Feature. Layer) feature. Layer;
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET ILegend. Class legend. Class = new Legend. Class(); ISymbol symbol = null; if (other is ILegend. Group && (int)index != -1) { legend. Class = ((ILegend. Group)other). get_Class((int)index); symbol = legend. Class. Symbol; } if (symbol == null) return; symbol = Get. Symbol. By. Control(symbol); //�出符号����框 �用���新的符号 if (symbol == null) return; legend. Class. Symbol = symbol; this. Activate(); ax. Map. Control 1. Active. View. Contents. Changed(); ax. Map. Control 1. Refresh(esri. View. Draw. Phase. esri. View. Geograph y, null); ax. TOCControl 1. Update(); }
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l private ISymbol Get. Symbol. By. Control( ISymbol symbol. Type) { ISymbol symbol = null; IStyle. Gallery. Item style. Gallery. Item = null; esri. Symbology. Style. Class style. Class = esri. Symbology. Style. Class. esri. Style. Class. Marker. Symbols; if (symbol. Type is IMarker. Symbol) { style. Class = esri. Symbology. Style. Class. esri. Style. Class. Marker. Symbols; } if (symbol. Type is ILine. Symbol) { style. Class = esri. Symbology. Style. Class. esri. Style. Class. Line. Symbols; } if (symbol. Type is IFill. Symbol) { style. Class = esri. Symbology. Style. Class. esri. Style. Class. Fill. Symbols; } Get. Symbol. By. Control. Form symbol. Form = new Get. Symbol. By. Control. Form(style. Class); symbol. Form. Show. Dialog(); style. Gallery. Item = symbol. Form. m_style. Gallery. Item;
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET ITOCControl 2 (New in 9. 2) l 与ITOCControl相比,ITOCControl 2多了以下1个 属性和2个方法: Ø public bool Enable. Layer. Drag. Drop {get; set; } :指示 图层是否可以拖放,以改变图层的顺序。 Ø public void Get. Selected. Item (ref esri. TOCControl. Item. Type, ref IBasic. Map, ref ILayer, ref object Unk, ref object Data ):返回 TOCControl中被选择项。 Ø public void Select. Item (object Unk, object Data ): 用于设置TOCControl中的选择项,如:
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l //Selecting the focus map Ø ax. TOCControl 1. Select. Item( ax. TOCControl 1. Active. View. Focus. Map); l //Selecting a layer in the focus map Ø ax. TOCControl 1. Select. Item (ax. TOCControl 1. Active. View. Focus. Map. get_Layer(0)); l //To select an item within a Legend. Group Ø ILayer layer = ax. TOCControl 1. Active. View. Focus. Map. get_Layer(0); Ø ILegend. Info legend. Info = (ILegend. Info) layer; Ø ILegend. Group legend. Group = legend. Info. get_Legend. Group(0); Ø //Select a heading • ax. TOCControl 1. Select. Item (legend. Group); Ø //Select a legend class
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 3. 3. 1. 2 ITOCControl. Events l ITOCControl. Events是一个事件接口,它 定义了 TOCControl能够处理的全部事件, 如On. Mouse. Down、On. Mouse. Move、 On. Mouse. Up、On. Double. Click、 On. Begin. Label. Edit、On. End. Label. Edit、 On. Key. Down、On. Key. Up。
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l private void ax. TOCControl 1_On. Begin. Label. Edit (object sender, ITOCControl. Events_On. Begin. Label. Edit. Event e) { ………… m_TOCControl. Hit. Test(e. x, e. y, ref item, ref map, ref layer, ref other, ref index); //已在其它地方(如窗体 的Load事件中)声明为ITOCControl类型的变量,并 已实例化 if (item !=
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l private void ax. TOCControl 1_On. End. Label. Edit(object sender, ITOCControl. Events_On. End. Label. Edit. E vent e) { //Prevent empty labels if (e. new. Label. Trim() == "") { e. can. Edit = false; } }
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l Samples 1. TOCControl. Context. Menu 2. TOCControl. Layer. Drag. Drop 3. TOCControl. Metadata. Viewer
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l 当右�点�地�� , �出 l 当右�点���� , �出
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 首先要��好右�菜�上的命令 private void Main. Form_Load(object sender, Event. Args e) Ø定�地�右�菜�、��右�菜� private void ax. TOCControl 1_On. Mouse. Down(object sender, ITOCControl. Events_On. Mouse. Down. Event e)
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET IToolbar. Menu m_Toc. Layer. Menu = new Toolbar. Menu. Class(); IToolbar. Menu m_Toc. Map. Menu = new Toolbar. Menu. Class(); private void Main. Form_Load(object sender, Event. Args e) {…… //TOCControl��右�菜� m_Toc. Layer. Menu. Add. Item(new Open. Attribute. Table. Cmd(), 0, 0, false, esri. Command. Styles. esri. Command. Style. Icon. And. Text ); m_Toc. Layer. Menu. Add. Item(new Remove. Layer. Cmd(), 0, 1, false, esri. Command. Styles. esri. Command. Style. Icon. And. Text
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET m_Toc. Layer. Menu. Add. Item(new Scale. Thresholds(), 3, 4, false, esri. Command. Styles. esri. Command. Style. Text. Only); m_Toc. Layer. Menu. Add. Item(new Layer. Selectable(), 1, 5, true, esri. Command. Styles. esri. Command. Style. Text. Only); m_Toc. Layer. Menu. Add. Item(new Layer. Selectable(), 2, 6, false, esri. Command. Styles. esri. Command. Style. Text. Only); m_Toc. Layer. Menu. Add. Item(new Zoom. To. Layer. Cmd(), 0, 7, true, esri. Command. Styles. esri. Command. Style. Icon. And. Te xt); m_Toc. Layer. Menu. Add. Item(new
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l private void ax. TOCControl 1_On. Mouse. Down (object sender, ITOCControl. Events_On. Mouse. Down. Event e) { …… ax. TOCControl 1. Hit. Test(e. x, e. y, ref item, ref map, ref layer, ref other, ref index); if (e. button == 2) { if (item == esri. TOCControl. Item. Map) { m_map. Control. Custom. Property = map as IMap; m_Toc. Map. Menu. Popup. Menu (e. x, e. y, ax. TOCControl 1. h. Wnd); } else if (layer is IFeature. Layer) { m_map. Control. Custom. Property = layer; m_Toc. Layer. Menu. Popup. Menu (e. x, e. y, ax. TOCControl 1. h. Wnd); } }
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l public sealed class Open. Attribute. Table. Cmd : Base. Command {…… public override void On. Click() { IMap map = null; if (m_hook. Helper. Hook is IMap. Control 3) { m_mapcontrol = m_hook. Helper. Hook as IMap. Control 3; current. Layer = m_mapcontrol. Custom. Property as IFeature. Layer; if (current. Layer == null) return; map = m_mapcontrol. Map; } if (map == null) return; Layer. Attributes layer. Attribute. Table = new Layer. Attributes (map, current. Layer); layer. Attribute. Table. Show(m_hook. Helper as System. Windows. Forms. IWin 32 Window); } }
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l public partial class Layer. Attributes : Form {…… Data. Set m_layer. Data. Set = new Data. Set (m_data. Set. Name); private System. Windows. Forms. Data. Grid. View data. Grid. View 1; public Layer. Attributes (IMap map, IFeature. Layer feature. Layer) { Initialize. Component(); m_map = map; m_active. View = map as IActive. View;
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l private void Attributes. Form_Load(object sender, Event. Args e) { this. Text = current. Layer. Name + " 属性表"; int row. Count = Construct. Data. Set (current. Layer); data. Grid. View 1. Data. Source = m_layer. Data. Set; data. Grid. View 1. Data. Member = current. Layer. Name; tool. Strip. Status. Label 1. Text = "����数: "; tool. Strip. Status. Label 2. Text = "���数: " + current. Layer. Feature. Class. Feature. Count(null). To. S tring();
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l private int Construct. Data. Set( IFeature. Layer p. Feat. Lyr) { ILayer. Fields p. Featlyr. Fields = p. Feat. Lyr as ILayer. Fields; IFeature. Class p. Feat. Cls = p. Feat. Lyr. Feature. Class; int rows = 0; if (m_layer. Data. Set. Tables[p. Feat. Lyr. Name] == null) { Data. Table p. Table = new Data. Table(p. Feat. Lyr. Name); Data. Column p. Table. Col; for (int i = 0; i <= p. Featlyr. Fields. Field. Count - 1; i++) { p. Table. Col = new Data. Column(p. Featlyr. Fields. get_Field(i). Alias. Name); p. Table. Columns. Add(p. Table. Col);
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET IFeature. Cursor features = p. Feat. Lyr. Search(null, false); IFeature feature = features. Next. Feature(); while (feature != null) { Data. Row p. Table. Row = p. Table. New. Row(); for (int i = 0; i <= p. Featlyr. Fields. Field. Count - 1; i++) { if (p. Featlyr. Fields. Find. Field(p. Feat. Cls. Shape. Field. Name) == i) { p. Table. Row[i] = p. Feat. Cls. Shape. Type; } else { p. Table. Row[i] = feature. get_Value(i); } } p. Table. Rows. Add(p. Table. Row); feature = features. Next. Feature(); } rows = p. Table. Rows. Count; m_layer. Data. Set. Tables. Add(p. Table); } return rows; }
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 3. 4 Toolbar. Control及相关对象 1. Toolbar. Control控件 2. Toolbar. Control上的命令 3. Toolbar. Item 4. 更新命令 5. Toolbar. Menu 组件类 6. Toolbar. Palette 7. Command. Pool 8. 操作栈(Operation. Stack) 9. 定制
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l Toolbar. Control主要接口有: Ø Ø IToolbar. Control 2 (New in 9. 2) IToolbar. Control. Default IToolbar. Control. Events (default)
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 3. 4. 1. 1 IToolbar. Control与 IToolbar. Control 2 l IToolbar. Control 2接口是任何与Toolbar. Control有关的 任务的出发点,如设置控件的外观,设置伙伴控件,添加 或去除命令、 具、菜单,定制Toolbar. Control的内容。 l IToolbar. Control接口提供的主要属性 Ø Buddy、Command. Pool、Current. Tool、Customize、 Custom. Property、Enabled、Object、Operation. Stack 、 Tool. Tips、Text. Alignment、Update. Interval等。 l IToolbar. Control接口提供的主要方法 Ø Add. Item、Add. Menu. Item、Add. Toolbar. Def、Find、Get. Item、 Get. Item. Rect、Hit. Test、Move. Item、Remove. All、 Set. Buddy. Control、Update等。
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET IToolbar. Control 2 (New in 9. 2) l 与IToolbar. Control相比, IToolbar. Control 2增加了以下: 1. public bool Align. Left {get; set; } 2. public uint Back. Color {get; set; } 3. public uint Fade. Color {get; set; } 4. public esri. Toolbar. Fill. Direction {get; set; } 5. public int Icon. Size {get; set; } 6. public void Load. Items ( IStream p. Stream ); 7. public esri. Toolbar. Orientation {get; set; } 8. public void Save. Items ( IStream p. Stream ); 9. public bool Show. Hidden. Items {get; set; } 10. public bool Themed. Drawing {get; set; }:是否有后面的圆角 矩形。 11. public bool Transparent {get; set; }
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET Themed. Drawing为 true Themed. Drawing为false
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 3. 4. 1. 2 IToolbar. Control. Default l 在绝大多数开发环境中,在容器(窗体)中放置 Toolbar. Control控件,将产生一个名叫 ax. Toolbar. Control 1的对象,这个对象上直接可用的属 性和方法对应于IToolbar. Control. Default接口上的属性 和方法,加上容器特有的属性和方法。 l IToolbar. Control. Default接口的属性和方法,与 Toolbar. Control的最高编号主接口的属性、方法相同。 例如,目前版本中,IToolbar. Control. Default等同于 IToolbar. Control 2,但在未来的版本中,将变为 IToolbar. Control 3。在软件开发中,使用 IToolbar. Control. Default接口,能够保证总是访问最新 版本的Toolbar. Control。
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 3. 4. 1. 3 IToolbar. Control. Events l IToolbar. Control. Events是一个事件接口, 它定义了 Toolbar. Control能够处理的全 部事件,如On. Buddy. Changed、 On. Double. Click、On. Item. Click、 On. Key. Down、On. Key. Up、 On. Mouse. Down、On. Mouse. Move、 On. Mouse. Up。
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l设计时,可以通过Toolbar. Control 的属性对话框 将命令项添加到Toolbar. Control 上。 l也可以通过编程将命令项添加到Toolbar. Control 上,使用IToolbar. Control. Add. Item方法有三种方 式将命令项添加到Toolbar. Control上: Ø 使用UID对象(使用GUID) Ø 使用prog. ID Ø 给Add. Item方法提供某个现有命令的一个实例。 Constant Value Description esri. Command. Style. Text. Only public int Add. Item ( object 0 text only. item, int. Display Sub. Type, int esri. Command. Style. Icon. Only Display icon only. index, bool begin. Group, 1 int Group. Spacing , esri. Command. Styles Style ); Display icon and esri. Command. Style. Icon. And. Text 2 text. esri. Command. Style. Menu. Bar 4 Display bar main menu. as
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET //Adding a command by UID u. ID = new UIDClass(); u. ID. Value = "esri. Controls. Map. Full. Extent. Command"; ax. Toolbar. Control 1. Add. Item( u. ID, -1, false, 0, esri. Command. Styles. esri. Command. Style. Icon. Only); //Adding a command by Prog. ID string prog. ID = "esri. Controls. Map. Full. Extent. Command"; ax. Toolbar. Control 1. Add. Item( prog. ID, -1, false, 0, esri. Command. Styles. esri. Command. Style. Icon. Only); //Adding a command by ICommand command = new Controls. Map. Full. Extent. Command. Class(); ax. Toolbar. Control 1. Add. Item( command, -1, false, 0,
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l Arc. Objects中命令、 具等的CLSID、 Prog. ID ØDeveloping with Arc. GIS>>>Learning Arc. Objects>>>General Arc. Objects references>>>Names and IDs Ø自定义命令、 具等的CLSID、Prog. ID,命令 类、 具类中可以找到。
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l Note: the IToolbar. Item interface has been superseded by IToolbar. Item 2. lesri. Toolbar. Item. Unknown Type属性: esri. Toolbar. Item. Type esri. Toolbar. Item. Command esri. Toolbar. Item. Tool. Control esri. Toolbar. Item. Menu esri. Toolbar. Item. Palette esri. Toolbar. Item. Multi. Item
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l Toolbar. Menu的主要接口 有:IToolbar. Menu、 IToolbar. Menu 2 。
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l IToolbar. Menu 2
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l Toolbar. Menu的构建有两种方式: 1. 先实现IMenu. Def,创建菜单对象,假设为 Menu. Def. A;再实例化一个Toolbar. Menu对象,假 设为Toolbar. Menu. A;然后使用 IToolbar. Menu 2. Add. Item方法,将Menu. Def. A对 象添加到Toolbar. Menu. A对象;最后,使用 IToolbar. Control. Add. Item 或 IToolbar. Control. Add. Menu. Item方法将 Toolbar. Menu. A添加到 具条控件上。 2. 使用IToolbar. Menu 2接口中的属性、方法将已有的 命令添加到Toolbar. Menu对象上来构建菜单; Toolbar. Menu上的子菜单又可以使另一个
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 3. 4. 6 Toolbar. Palette l Toolbar. Palette( 具条面板) 提供了面板项的实现,其 上可以驻留命令和 具,但不能驻留Tool. Control、 Toolbar. Menu 以及Multi. Item对象。Toolbar. Palette可 以驻留在Toolbar. Control上或作为弹出面板出现。 l IToolbar. Palette是Toolbar. Palette的主要接口。该接口 定义的属性有:Active. Item、Align. Left、Caption、 Command. Pool、Count、Customize、Hook、 Icon. Size、Mouse. Icon、Mouse. Pointer、 Themed. Drawing、Tool. Tips;定义的方法有: Add. Item、Find、Get. Item、Move. Item、 Popup. Palette、Remove. All、Set. Hook.
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l Toolbar. Palette的构建有两种方式: 1. 先实现IPalette. Def,创建面板对象,假设为 Palette. Def. A;再实例化一个Toolbar. Palette对象, 假设为Toolbar. Palette. A;然后使用 IToolbar. Palette. Add. Item方法,将Palette. Def. A 对象添加到Toolbar. Palette. A对象;最后,使用 IToolbar. Control. Add. Item方法将 Toolbar. Palette. A添加到 具条控件上。 2. 使用IToolbar. Palette接口中的属性、方法将已有 的命令、 具添加到Toolbar. Palette对象上来构 建面板。
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET Ø //Create a Toolbar. Palette m_Toolbar. Palette = new Toolbar. Palette. Class(); Ø //Add new items to the Toolbar. Palette m_Toolbar. Palette. Add. Item("esri. Controls. Select. Tool", 0, 1); m_Toolbar. Palette. Add. Item("esri. Controls. New. Circle. Tool ", 0, -1); m_Toolbar. Palette. Add. Item("esri. Controls. New. Curve. Tool ", 0, -1); m_Toolbar. Palette. Add. Item("esri. Controls. New. Ellipse. Too l", 0, -1); m_Toolbar. Palette. Add. Item("esri. Controls. New. Line. Tool", 0, -1); m_Toolbar. Palette. Add. Item("esri. Controls. New. Polygon. To ol", 0, -1); m_Toolbar. Palette. Add. Item("esri. Controls. New. Rectangle
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET ICommand. Pool m_Command. Pool = new Command. Pool. Class(); ax. Toolbar. Control 1. Command. Pool = m_Command. Pool; ax. Toolbar. Control 2. Command. Pool = m_Command. Pool;
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET IOperation. Stack operation. Stack = new Controls. Operation. Stack. Class(); ax. Toolbar. Control 1. Operation. Stack = operation. Stack ; ax. Toolbar. Control 2. Operation. Stack = operation. Stack ;
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET Customize. Dialog l Customize. Dialog包含一个无模态对话 框,允许程序运行时将 commands, toolbar definitions (toolsets) 和 menu definitions 等添加到 Toolbar. Control 上,当 IToolbar. Control. Customize 设置为 true时。
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l Customize. Dialog的主要接口为:ICustomize. Dialog 和事件接口ICustomize. Dialog. Events。 l ICustomize. Dialog接口的属性 Ø Dialog. Title、Is. Dialog. Active、 Double. Click. Destination、Commands. Category、 Menus. Category、Toolbars. Category、 Show. Add. From. File。 l ICustomize. Dialog接口的方法 Ø Start. Dialog 、Close. Dialog、 Set. Double. Click. Destination。 l ICustomize. Dialog. Events 接口成员:On. Start. Dialog 、 On. Close. Dialog.
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET ICustomize. Dialog 2(继承自 ICustomize. Dialog) Description Palettes. Category The GUID of the component category used for palette definitions. Set. Window. Positions the customize dialog at the given screen co-ordinates.
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 开发实例 l 首先声明一个ICustomize. Dialog类型的全局变量 m_Customize. Dialog,并实例化,代码如下: private ICustomize. Dialog m_Customize. Dialog = new Customize. Dialog. Class(); l 接着,声明如下两个事件变量: private ICustomize. Dialog. Events_On. Start. Dialog. Event. Han dler start. Dialog. E; private ICustomize. Dialog. Events_On. Close. Dialog. Event. Ha
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l COM事件转换为. NET 事件: Ø为每个事件产生一个代理( delegate ) • 命名:事件接口+_+事件名+ Event. Handler • 例如: IActive. View. Events_Selection. Changed. Event. Han dler Ø创建一个. NET事件接口 • 命名:事件接口+ _ + Event • 例如: IActive. View. Events_Event
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l 创建一个名为Create. Customize. Dialog的方法,在该方法中 添加代码,对两个事件变量和定制对话框进行有关设置: private void Create. Customize. Dialog() { ICustomize. Dialog. Events_Event p. Customize. Dialog. Event = m_Customize. Dialog as ICustomize. Dialog. Events_Event; start. Dialog. E = new ICustomize. Dialog. Events_On. Start. Dialog. Event. Handler( On. Start. Dialog. Handler ); p. Customize. Dialog. Event. On. Start. Dialog += start. Dialog. E; close. Dialog. E = new ICustomize. Dialog. Events_On. Close. Dialog. Event. Handler( On. Close. Dialog. Handler ); p. Customize. Dialog. Event. On. Close. Dialog += close. Dialog. E; m_Customize. Dialog. Title = "Customize Toolbar. Control Items"; m_Customize. Dialog. Set. Double. Click. Destination( ax. Toolbar. Control 1);
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l 在窗体Form 1的Load调用 Create. Customize. Dialog方法: l private void Form 1_Load(object sender, System. Event. Args e) { //…………… Create. Customize. Dialog(); //…………… }
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l 向窗体Form 1中添加一个复选框并将其命名为 chk. Customize,标题为“Customize”。 l 在复选框chk. Customize的Checked. Changed事 件处理方法中添加如下代码: l private void chk. Customize_Checked. Changed(object sender, System. Event. Args e) { // Show or hide the Customize dialog box. if (chk. Customize. Checked == false) m_Customize. Dialog. Close. Dialog(); else m_Customize. Dialog. Start. Dialog(ax. Toolbar. Contro l 1. h. Wnd);
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l 添加下面的On. Start. Dialog和On. Close. Dialog事件处理器, 在打开或关闭定制对话框时会触发这两个方法。 l private void On. Start. Dialog. Handler () { ax. Toolbar. Control 1. Customize = true; ………… } l private void On. Close. Dialog. Handler () { ax. Toolbar. Control 1. Customize = false; ………… chk. Customize. Checked = false; } Ø 按以上步骤就能实现Toolbar. Control的定制。
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l Names and IDs ØArc. Catalog commands ØArc. Globe commands ØArc. Map commands ØArc. Scene commands ØArc. GIS Engine commands ØExtensions
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 3. 5. 2 与 Toolbar. Control一起使用 l 通过Toolbar. Control控件使用Control Commands有三条途径: Ø 在程序设计阶段,通过Toolbar. Control控件的属性页添 加 Ø 在程序代码中,使用Add. Item, Add. Menu. Item或 Add. Toolbar. Def方法将要用到的Control Commands 的实例对象添加到Toolbar. Control控件中, 使用 Add. Item 或 Add. Sub. Menu方法添加到 Toolbar. Menu 上; Ø 最终用户可以通过Customize对话框进行设置(当 Toolbar. Control控件的Customize设置为true时有效)。
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l 例如: ICommand cmd = new Symbology. Unique. Value. Renderer(); cmd. On. Create(ax. Map. Control 1. Object); if (cmd. Enabled) cmd. On. Click(); ICommand p. Command = new Controls. Select. Features. Tool. Class(); p. Command. On. Create(ax. Map. Control 1. Object); ax. Map. Control 1. Current. Tool = p. Command as ITool; Base. Tool tool = new Select. Adjacent. Features(); tool. On. Create(ax. Map. Control 1. Object); ax. Map. Control 1. Current. Tool = tool;
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 3. 6 在WPF程序中使用Arc. GIS Engine 控件 1. WPF简介 2. 如何在WPF中使用Arc. GIS Engine 控件 3. 在WPF里使用Arc. GIS Engine控件的局限性
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 3. 6. 1 WPF�介 l Windows Presentation Foundation (WPF) 是. NET Framework 3. 0提供的新的图形显示系统,为用户界面、 2 D/3 D 图形、文档和媒体提供了统一的描述和操作方法。 l 基于Direct. X 9/10技术的WPF不仅带来了前所未有的3 D界 面,而且其图形向量渲染引擎也大大改进了传统的2 D界面, 比如Vista中的半透明效果的窗体等都得益于WPF。 l. NET Framework 3. 0同时新增了四个大组件:Windows Presentation Foundation (WPF),Windows Workflow Foundation (WWF)、Windows Communication Foundation (WCF)和Windows Card. Space,而这些恰 是NET Framework 3. 0最具价值的部分。
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 3. 6. 2 如何在WPF中使用Arc. GIS Engine 控件
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 3. 6. 2. 1 WPF和Windows Forms集成 l 将WPF与Windows Forms集成可以有在同一窗 体和在不同窗体两种方式。要把Arc. GIS Engine 的Windows Forms控件集成到WPF环境里去, 有两个选项可供选择: Ø在WPF应用程序中添加一个Windows Form, 然后在此Form上添加使用Arc. GIS Engine控件。 Ø将Arc. GIS Engine控件“直接”加到WPF窗体 中。
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 3. 6. 2. 2 在WPF窗体中添加Arc. GIS Engine控件 l Windows. Forms. Host控件提供了一个容器,可以 容纳Windows Forms 控件,由此就可以达到在 WPF窗体中添加Windows Forms控件的目的。 这样一来,WPF元素和Arc. GIS Engine控件就可 以方便地互相访问、互相操作。
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 示例:在WPF中添加一个Map. Control。 l 步骤一:启动Visual Studio l 步骤二:新建项目里选WPF应用程序,命名为 Map. Hosted. In. WPF l 步骤三:添加引用ESRI. Arc. GIS. Ax. Controls、 ESRI. Arc. GIS. System、ESRI. Arc. GIS. Version,其中 ESRI. Arc. GIS. Version为Arc. GIS新增的程序集,它提供了绑定运行时的 API,它的Runtime. Manager类可用以列举目前所安装的Arc. GIS产品以 及其安装目录。 l 步骤四:将Windows. Forms. Host控件拖入窗体 l 步骤五:将窗体的标题改为“Map. Control Hosted in WPF”,将Windows. Forms. Host控件的Name属性设为 “map. Host”,添加一个Windows Load事件,取其默认
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET <Window x: Class="Wpf. Application 1. Main. Window" xmlns="http: //schemas. microsoft. com/winfx/2006/xaml/present ation" xmlns: x="http: //schemas. microsoft. com/winfx/2006/xaml" Title="Map. Control hosted in WPF" Loaded="Window_Loaded" Height="350" Width="525"> <Grid> <Windows. Forms. Host Height="278" Horizontal. Alignment="Left" Name="map. Host" Vertical. Alignment="Top" Width="300" Margin="203, 33, 0, 0" /> <Windows. Forms. Host Height="278" Horizontal. Alignment="Left" Margin="0, 33, 0, 0" Name="toc. Control. Host" Vertical. Alignment="Top" Width="200" /> <Windows. Forms. Host Height="36" Horizontal. Alignment="Left" Name="toolbar. Control. Host" Vertical. Alignment="Top" Width="503" /> </Grid>
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l 步骤六:绑定产品及初始化license public partial class App : Application { protected override void On. Startup(Startup. Event. Args e) { base. On. Startup(e); ESRI. Arc. GIS. Runtime. Manager. Bind(ESRI. Arc. GIS. Product. Code. Engine); Initialize. Engine. License(); } private void Initialize. Engine. License() { Ao. Initialize aoi = new Ao. Initialize. Class(); esri. License. Product. Code product. Code = esri. License. Product. Code. Engine; if (aoi. Is. Product. Code. Available(product. Code) == esri. License. Status. esri. License. Available) { aoi. Initialize(product. Code); } } }
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l 步骤七:定义Map Control public partial class Window 1: Window { Ax. Map. Control map. Control; public Window 1() { Initialize. Component(); Create. Map. Control(); } private void Create. Map. Control() { map. Control = new Ax. Map. Control(); map. Host. Child = map. Control; } } }
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l 步骤八:为Map Control添加属性事件 private void Wire. Map. Events() { map. Control. On. Mouse. Move += new IMap. Control. Events 2_Ax_On. Mouse. Move. Event. Handler(map. Cont rol_On. Mouse. Move); map. Control. On. Mouse. Down+=new IMap. Control. Events 2_Ax_On. Mouse. Down. Event. Handler(map. Cont rol_On. Mouse. Down); } private void map. Control_On. Mouse. Down(object sender, IMap. Control. Events 2_On. Mouse. Down. Event e) { map. Control. Extent = map. Control. Track. Rectangle(); map. Control. Refresh(); } private void map. Control_On. Mouse. Move(object sender, IMap. Control. Events 2_On. Mouse. Move. Event e) { System. Console. Write. Line(e. map. X. To. String()); }
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET l 步骤九:编写窗体加载事件代码 private void Window_Loaded(object sender, Routed. Event. Args e) { Wire. Map. Events(); // Specify your. mxd file here. map. Control. Load. Mx. File( "C: \Program Files\Arc. GIS\Developer. Kit 10. 0\Samples\data\Gulf. Of. St. Lawren ce\Gulf_of_St. _Lawrence. mxd"); } 步骤十:运行程序 Sample: WPFMap. Viewer
江西理 大学 – Developing GIS Applications with Arc. Objects using C#. NET 5. 简要说明Command. Pool、 Operation. Stack的 作用。在GIS应用开发中如何使用它们? 6. 编程实现Toolbar. Control的定制。 7. ESRI. Arc. GIS. Controls类库中提供了大量的命令、 具,在开放过程中,不通过Toolbar. Control控 件如何使用这些内置的命令、 具?
- Slides: 159