第二章 使用ArcGIS Engine控件编程
2016-05-23 16:56
363 查看
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.DataSourcesFile; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.Display; namespace EngineWindowsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } int flag = 0; private void Form1_Load(object sender, EventArgs e) { IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory(); IWorkspace pWorkSpace = pWorkspaceFactory.OpenFromFile(Application.StartupPath+"\\实验一数据",0); IFeatureWorkspace pFeatureWorkspace= pWorkSpace as IFeatureWorkspace; IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass("塔林林场"); IFeatureLayer pFeatureLayer=new FeatureLayerClass(); pFeatureLayer.FeatureClass = pFeatureClass; axMapControl1.AddLayer(pFeatureLayer as ILayer); axMapControl2.AddLayer(pFeatureLayer as ILayer); } private void extendToolStripMenuItem_Click(object sender, EventArgs e)//fangda { flag = 1; axMapControl1.MousePointer = esriControlsMousePointer.esriPointerZoomIn; } private void 缩小ToolStripMenuItem_Click(object sender, EventArgs e) { flag = 2; axMapControl1.MousePointer = esriControlsMousePointer.esriPointerZoomOut; } private void 移动ToolStripMenuItem_Click(object sender, EventArgs e) { flag = 3; axMapControl1.MousePointer = esriControlsMousePointer.esriPointerPan; } private void 全图ToolStripMenuItem_Click(object sender, EventArgs e) { axMapControl1.Extent = axMapControl1.FullExtent; } private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { if (flag == 1) axMapControl1.Extent = axMapControl1.TrackRectangle(); else if(flag==3) axMapControl1.Pan(); else if (flag == 2) { IEnvelope pEnvelope = axMapControl1.Extent; pEnvelope.Expand(2, 2, true); axMapControl1.Extent = pEnvelope; } } private void axMapControl1_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e) { IEnvelope envelope = (IEnvelope)e.newEnvelope; IGraphicsContainer graphicsContainer = axMapControl2.Map as IGraphicsContainer; IActiveView activeView = graphicsContainer as IActiveView; //在绘图前,清除axMapControl2中的任何图形元素 graphicsContainer.DeleteAllElements(); IElement element = new RectangleElementClass(); element.Geometry = envelope; //设置鹰眼图中的红线 //产生一个线符号对象 ILineSymbol outLineSymbol = new SimpleLineSymbolClass(); outLineSymbol.Width = 2; outLineSymbol.Color = GetColor(255, 0, 0, 255); //设置颜色属性 //设置填充符号的属性 IFillSymbol fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = GetColor(9, 0, 0, 0); fillSymbol.Outline = outLineSymbol; IFillShapeElement fillShapeElement = element as IFillShapeElement; fillShapeElement.Symbol = fillSymbol; graphicsContainer.AddElement((IElement)fillShapeElement, 0); activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } private IRgbColor GetColor(int r, int g, int b, int t) { IRgbColor rgbColor = new RgbColorClass(); rgbColor.Red = r; rgbColor.Green = g; rgbColor.Blue = b; rgbColor.Transparency = (byte)t; return rgbColor; } private void axMapControl2_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { IPoint point = new PointClass(); point.PutCoords(e.mapX, e.mapY); axMapControl1.CenterAt(point); } } }
相关文章推荐
- 如何查看 JAR 包的源代码
- Java面向对象编程 第一章 面向对象开发方法概述
- ASP.NET将文件写到另一服务器
- Java面向对象 第一章 面向对象开发方法概述
- C# 文件夹的常用操作
- Spring 框架的设计理念与设计模式分析
- matlab中文论坛视频谷普教程MATLAB压缩包介绍
- matlab中文论坛视频谷普教程MATLAB压缩包介绍
- java.lang.OutOfMemoryError处理错误
- ASP.NET MVC Form验证
- java 数据采集
- ftp ftpclient异常解决、远程命令已经错误代码
- Maven设置项目java默认编译版本
- C#实现发送邮件
- php 页面静态化
- java 字符串缓冲池 String缓冲池
- Java 协变数组和类型擦除(covariant array & type erasure)
- JAVA基础教程6:运行时类型识别(RTTI)
- python正则表达式
- 最近写代码的一些记录