AE:::部分AE功能实现代码

●·● 目录:

A1 …………实现:鼠标滑过显示要素 tip
A2 …………实现:通过鼠标选择要素并高亮显示(ISelectionEnvironment)
A3 …………实现:只显示筛选的要素(IFeatureLayerDefinition)
A4 …………实现:高亮显示筛选的要素(IFeatureSelection)
A5 …………实现:类似 ArcMap 中 Identify 工具的效果(IIdentify、IArray、IIdentifyObj)
A6 …………实现:在 MapControl 上绘制几何图形
       实现:在 MapControl 上绘制几何图形(IGraphicsContainer,几何:圆)

A7 …………实现:在 MapControl 自由旋转地图(IScreenDisplay [RotateMoveTo])
  实现:在 MapControl 中鼠标与地图反向移动(IScreenDisplay [PanMoveTo])

A8 …………实现:弹出颜色选择器(IColorPalette、IColorSelector、IColorBrowser)
       实现:获取控件的屏幕位置(两种方法)

A9 …………实现实现:Symbol 对象(ISimpleMarkerSymbol、Arrow、Character、Picture)

G1 …………实现:Symbol 对象
G2 …………实现:显示图层的属性窗口
G3 …………实现:PageLayoutControl 的样式设置(IBorder、IBackground、IShadow、IMapGrid)
G4 …………实现:删除shapefile文件中的重复数据
G5 …………实现:MapControl 与 PageLayoutControl 的交互
G6 …………实现:制作可以浮动的工具栏
G7 …………实现:ArcGIS Engine 实现鹰眼 & 分析(IGraphicsContainer、IFillShapeElement)
G8 …………实现:独立窗口的鹰眼显示(IHookHelper)
G9 …………实现:自定义工具窗口(ICustomizeDialog、ICustomizeDialogEvents)

U1 …………实现:Map 与 PageLayout 切换后工具不变
U2 …………实现:在窗体中显示渐变颜色 & 根据名称获取控件(IAlgorithmicColorRamp、IEnumColor)
U3 …………实现:获取地图是否处于编辑状态(IDataset、IWorkspaceEdit)
U4 …………实现:获取地图是否处于编辑状态
U5 …………实现:获取地图是否处于编辑状态

---------------------------------------------------------------------------------------------------------

U6 …………实现:自定义的图层控制器(涉及图层组,IGroupLayer,ICompositeLayer)

U7 …………实现:向图层中添加shapefile的几种方式

U8 …………实现:给图层添加参考系

U9…………实现:线与线的相交计算、线与多边形的相交计算、多边形是否包含其他集合类型的计算

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第A1个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:鼠标滑过显示要素 tip

对于这个有两个方法:

第一种:通过将 axmapcontrol 自带的 ShowMapTips 属性设置为 true 来实现

第二种:通过 .NET 自带的控件 ToolTip 来实现

第一种代码

private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e) { axMapControl1.ShowMapTips = true; IFeatureLayer pFeatureLayer = axMapControl1.Map.get_Layer(0as IFeatureLayer; pFeatureLayer.DisplayField = "Name"; pFeatureLayer.ShowTips = true; }

第二种代码

AE:::部分AE功能实现代码
private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e) { IFeatureLayer pFeatureLayer = axMapControl1.Map.get_Layer(0as IFeatureLayer; pFeatureLayer.DisplayField = "Name"; pFeatureLayer.ShowTips = truestring pTip; pTip = pFeatureLayer.get_TipText(e.mapX, e.mapY, axMapControl1.ActiveView.FullExtent.Width / 10000); if (pTip != null) { toolTip1.SetToolTip(axMapControl1, "名称:" + pTip); } else //当 ToolTip 空间显示的内容为 null 的时候,就不会显示了!相当于隐藏了! { toolTip1.SetToolTip(axMapControl1, ""); } }
AE:::部分AE功能实现代码

以上两种方法都可以实现显示标注,但是第二种效果更好一点~!

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第A2个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:通过鼠标选择要素并高亮显示

---------------------------------------------------------------------------------------------------------

●·●ISelectionEnvironment 接口

---------------------------------------------------------------------------------------------------------

通过 IMap 接口的 SelectByShape 方法来实现!同时可以修改高亮显示的颜色!

AE:::部分AE功能实现代码
private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault; IMap pMap = axMapControl1.Map; IGeometry pGeometry = axMapControl1.TrackRectangle(); //获取框选几何 ISelectionEnvironment pSelectionEnv = new SelectionEnvironment(); //新建选择环境 IRgbColor pColor = newRgbColor(); pColor.Red = 255; pSelectionEnv.DefaultColor = pColor; //设置高亮显示的颜色! pMap.SelectByShape(pGeometry, pSelectionEnvfalse); //选择图形! axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, nullnull); }
AE:::部分AE功能实现代码

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第A3个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:只显示筛选的要素

---------------------------------------------------------------------------------------------------------

●·●IFeatureLayerDefinition 接口

---------------------------------------------------------------------------------------------------------

1. 通过 IFeatureLayerDefinition 接口的 DefinitionExpression 属性可以实现

IFeatureLayer pFeatureLayer = axMapControl1.Map.get_Layer(0as IFeatureLayer; IFeatureLayerDefinition pFeatLyrDef = pFeatureLayer as IFeatureLayerDefinition; //新建 IFeatureLayerDefinition 接口实例 pFeatLyrDef.DefinitionExpression = "Area > 20";  //定义筛选条件 axMapControl1.ActiveView.Refresh();  //刷新

这样便只显示符合要求的部分了!即面积大于20的要素!

2. 通过 IFeatureLayerDefinition 接口的 CreatSelectionLayer 方法可以通过筛选建立新图层!

AE:::部分AE功能实现代码
IFeatureLayer pFeatureLayer = axMapControl1.Map.get_Layer(0as IFeatureLayer; IFeatureLayerDefinition pFeatLyrDef = pFeatureLayer as IFeatureLayerDefinition; pFeatLyrDef.DefinitionExpression = "Area > 20"; axMapControl1.ActiveView.Refresh(); //重新定义的图层 IQueryFilter pQueryFilter = new QueryFilter(); pQueryFilter.WhereClause ="POP > 10"; IFeatureSelection pFeatSel = pFeatureLayer as IFeatureSelection; pFeatSel.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew,false); axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null,null);  //在新定义图层的基础上进行的查询 IFeatureLayer pNewFeat = pFeatLyrDef.CreateSelectionLayer("New Layer"truenullnull);  //新建的图层包括上面两者的交集部分! pFeatSel.Clear(); axMapControl1.Map.AddLayer(pNewFeat); MessageBox.Show(axMapControl1.Map.LayerCount.ToString());
AE:::部分AE功能实现代码

首先是建立一个虚拟的新图层,然后在此新图层的基础上进行筛选,然后从而生成新的图层!

参考:http://blog.csdn.net/qinyilang/article/details/6575539
---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第A4个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:高亮显示筛选的要素

---------------------------------------------------------------------------------------------------------

●·●IFeatureSelection 接口

---------------------------------------------------------------------------------------------------------

通过 IFeatureSelection 接口的 SelectFeatures 方法可以实现

IFeatureLayer pFeatureLayer = axMapControl1.Map.get_Layer(0as IFeatureLayer;
IQueryFilter pQueryFilter = new QueryFilter();  //建立查询 pQueryFilter.WhereClause ="POP > 10"; IFeatureSelection pFeatSel = pFeatureLayer as IFeatureSelection;  //新建 IFeatureSelection 接口实例 pFeatSel.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, false);  //实现方法,选择筛选的部分! axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, nullnull);

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第A5个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:类似 ArcMap 中 Identify 工具的效果

---------------------------------------------------------------------------------------------------------

●·●IIdentify 接口

---------------------------------------------------------------------------------------------------------

●·●IIdentifyObj 接口

---------------------------------------------------------------------------------------------------------

●·●IArray 接口

---------------------------------------------------------------------------------------------------------

主要实现点击查询并闪烁显示,并把查询要素的信息通过DataGridView显示出来,主要用到的接口:IIdentity、IArray、IIdentifyObj

AE:::部分AE功能实现代码
IIdentify pIdentify = axMapControl1.Map.get_Layer(0as IIdentify; //通过图层获取 IIdentify 实例 IPoint pPoint = new ESRI.ArcGIS.Geometry.Point(); //新建点来选择 IArray pIDArray; IIdentifyObj pIdObj; pPoint.PutCoords(e.mapX, e.mapY); //定义点 pIDArray = pIdentify.Identify(pPoint); //通过点获取数组,用点一般只能选择一个元素 if (pIDArray !=null) { pIdObj = pIDArray.get_Element(0as IIdentifyObj; //取得要素 pIdObj.Flash(axMapControl1.ActiveView.ScreenDisplay); //闪烁效果 MessageBox.Show("Layer: " + pIdObj.Layer.Name + "\n" + "Feature: " + pIdObj.Name); //输出信息 } else { MessageBox.Show("Nothing!"); }
AE:::部分AE功能实现代码

效果:

AE:::部分AE功能实现代码

框选实现如下所示:

AE:::部分AE功能实现代码
IIdentify pIdentify = axMapControl1.Map.get_Layer(0as IIdentify; IGeometry pGeo = axMapControl1.TrackRectangle() as IGeometry; IArray pIDArray; IIdentifyObj pIdObj; pIDArray = pIdentify.Identify(pGeo); if (pIDArray != null) { string str = "\n"stringlyrName = ""for (int i = 0; i < pIDArray.Count;i++ ) { pIdObj = pIDArray.get_Element(i) as IIdentifyObj; pIdObj.Flash(axMapControl1.ActiveView.ScreenDisplay); str += pIdObj.Name + "\n"; lyrName = pIdObj.Layer.Name; } MessageBox.Show("Layer: " + lyrName + "\n" + "Feature:" + str); } else { MessageBox.Show("Nothing!"); }
AE:::部分AE功能实现代码

效果如下:

AE:::部分AE功能实现代码

参考:http://blog.csdn.net/mjhwy/article/details/7337426

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第A6个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:在 MapControl 上绘制几何图形

可以直接使用 axMapControl1.DrawShape 方法来实现~!

AE:::部分AE功能实现代码
ISimpleLineSymbol pLineSym = new SimpleLineSymbol(); IRgbColor pColor = new RgbColor(); pColor.Red = 11; pColor.Green = 120; pColor.Blue = 233; pLineSym.Color = pColor; pLineSym.Style = esriSimpleLineStyle.esriSLSSolid; pLineSym.Width = 2; IPolyline pLine = axMapControl1.TrackLine() as IPolyline; object symbol = pLineSym as object; axMapControl1.DrawShape(pLine, ref symbol);
AE:::部分AE功能实现代码

也可以通过 IScreenDisplay 接口的方法来实现!~

AE:::部分AE功能实现代码
ISimpleLineSymbol pLineSym = new SimpleLineSymbol(); IRgbColor pColor = new RgbColor(); pColor.Red = 11; pColor.Green = 120; pColor.Blue = 233; pLineSym.Color = pColor; pLineSym.Style = esriSimpleLineStyle.esriSLSSolid; pLineSym.Width = 2; IPolyline pLine = axMapControl1.TrackLine() as IPolyline; IScreenDisplay pScreenDisplay = axMapControl1.ActiveView.ScreenDisplay; pScreenDisplay.StartDrawing(pScreenDisplay.hDC, 1); pScreenDisplay.SetSymbol(pLineSymas ISymbol); pScreenDisplay.DrawPolyline(pLine); pScreenDisplay.FinishDrawing();
AE:::部分AE功能实现代码

通过比较,只是后面实现的部分不同,前面都是相同的!

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第A6A个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:在 MapControl 上绘制几何图形(IGraphicsContainer,几何:圆)

  普通的图形,可以直接向下面一样实现

AE:::部分AE功能实现代码
m_ActiveView = m_hookHelper.ActiveView; m_Map = m_hookHelper.FocusMap; IScreenDisplay pScreenDisplay = m_ActiveView.ScreenDisplay; IRubberBand pRubberPolygon newRubberPolygonClass(); ISimpleFillSymbol pFillSymbol new SimpleFillSymbolClass(); pFillSymbol.Color = getRGB(2552550); IPolygon pPolygon = pRubberPolygon.TrackNew(pScreenDisplay, (ISymbol)pFillSymbol) as IPolygon; pFillSymbol.Style = esriSimpleFillStyle.esriSFSDiagonalCross; pFillSymbol.Color = getRGB(0255255); IFillShapeElement pPolygonEle new PolygonElementClass(); pPolygonEle.Symbol = pFillSymbol; IElement pEle = pPolygonEle as IElement; pEle.Geometry = pPolygon; IGraphicsContainer pGraphicsContainer = m_Map asIGraphicsContainer; pGraphicsContainer.AddElement(pEle, 0); m_ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, nullnull);
AE:::部分AE功能实现代码

  画圆比较特殊,因为没有圆这个现成的几何体,因此要转换,如下所示:

AE:::部分AE功能实现代码
m_ActiveView = m_hookHelper.ActiveView; m_Map = m_hookHelper.FocusMap; IScreenDisplay pScreenDisplay = m_ActiveView.ScreenDisplay; IRubberBand pRubberCircle newRubberCircleClass(); ISimpleFillSymbol pFillSymbol new SimpleFillSymbolClass(); pFillSymbol.Color = getRGB(2552550); IGeometry pCircle = pRubberCircle.TrackNew(pScreenDisplay, (ISymbol)pFillSymbol) as IGeometry; IPolygon pPolygon = new PolygonClass();    //空的多边形 ISegmentCollection pSegmentCollection= pPolygon as ISegmentCollection;  //段集合 ISegment pSegment = pCircle asISegment;  //将圆赋值给段 object missing = Type.Missing;  //显示默认值 pSegmentCollection.AddSegment(pSegment, ref missing, ref missing);  //给空多边形加入圆 pFillSymbol.Style = esriSimpleFillStyle.esriSFSDiagonalCross; pFillSymbol.Color = getRGB(0255255); IFillShapeElement pPolygonEle new PolygonElementClass(); pPolygonEle.Symbol = pFillSymbol; IElement pEle = pPolygonEle as IElement; pEle.Geometry = pPolygon; IGraphicsContainer pGraphicsContainer = m_Map asIGraphicsContainer; pGraphicsContainer.AddElement(pEle, 0); m_ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, nullnull);
AE:::部分AE功能实现代码

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第A7个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:在 MapControl 自由旋转地图

---------------------------------------------------------------------------------------------------------

●·●IScreenDisplay 接口

---------------------------------------------------------------------------------------------------------

通过 IScreenDisplay 接口来实现

AE:::部分AE功能实现代码
//鼠标按下! private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { IPoint pPoint = new PointClass(); pPoint.PutCoords(e.mapX, e.mapY); IPoint pCentrePoint = new PointClass(); pCentrePoint.PutCoords(axMapControl1.Extent.XMin + axMapControl1.ActiveView.Extent.Width / 2, axMapControl1.Extent.YMax - axMapControl1.ActiveView.Extent.Height / 2); //获取图像的中心位置axMapControl1.ActiveView.ScreenDisplay.RotateStart(pPoint, pCentrePoint); //开始旋转 }
//鼠标移动! private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e) { IPoint pPoint = new PointClass(); pPoint.PutCoords(e.mapX, e.mapY); axMapControl1.ActiveView.ScreenDisplay.RotateMoveTo(pPoint); //旋转到鼠标的位置axMapControl1.ActiveView.ScreenDisplay.RotateTimer(); //可以忽略 }
//鼠标抬起! private void axMapControl1_OnMouseUp(object sender, IMapControlEvents2_OnMouseUpEvent e) { double dRotationAngle = axMapControl1.ActiveView.ScreenDisplay.RotateStop(); //获取旋转的角度axMapControl1.Rotation = dRotationAngle; //赋值给 axMapControl1.Rotation,这下真的旋转了!axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, nullnull); //刷新! }
AE:::部分AE功能实现代码

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第A7A个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:在 MapControl 中鼠标与地图反向移动

AE:::部分AE功能实现代码
double startMapX = 0double startMapY = 0; IScreenDisplay pScreenDisplay; privatevoid Form1_Load(object sender, EventArgs e)  //窗体加载信息 { pScreenDisplay =axMapControl1.ActiveView.ScreenDisplay; } private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)  //鼠标按下的时候触发 { IPoint pPoint new PointClass(); pPoint.PutCoords(e.mapX, e.mapY); pScreenDisplay.PanStart(pPoint); startMapY = e.mapY; startMapX = e.mapX; } privatevoid axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)  //鼠标移动的时候触发 { IPoint pPoint new PointClass(); pPoint.PutCoords(startMapX2 - e.mapX, startMapY * 2 - e.mapY); //获取当前点关于起始点的对称点 pScreenDisplay.PanMoveTo(pPoint); } private void axMapControl1_OnMouseUp(objectsender, IMapControlEvents2_OnMouseUpEvent e)    //鼠标松开的时候触发 { pScreenDisplay.PanStop(); }
AE:::部分AE功能实现代码

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第A8个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:弹出颜色选择器

---------------------------------------------------------------------------------------------------------

●·●IColorPalette 接口

---------------------------------------------------------------------------------------------------------

1. ColorPalette:

AE:::部分AE功能实现代码
private void button1_Click(object sender, EventArgs e) { IColor pColor newRgbColor(); pColor.RGB 255; tagRECT pTag new tagRECT(); pTag.left this.Left + button1.Left + button1.Width; pTag.bottom this.Top + button1.Top + button1.Height; IColorPalette pColorPalette new ColorPalette(); pColorPalette.TrackPopupMenu(refpTag, pColor, false0); pColor = pColorPalette.Color; }
AE:::部分AE功能实现代码

效果:

AE:::部分AE功能实现代码

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第A8A个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:获取控件的屏幕位置(两种方法)

第一种:将控件坐标转换为屏幕坐标!

pTag.left = button1.PointToScreen(System.Drawing.Point.Empty).X; pTag.bottom = button1.PointToScreen(System.Drawing.Point.Empty).Y + button1.Height;

第二种:通过空间之间属性的间接计算!注:button1 在 groupBox2 中!

pTag.left = SystemInformation.FrameBorderSize.Width + this.Left + groupBox2.Left +button1.Left; pTag.bottom = (this.Height - this.ClientRectangle.Height - SystemInformation.FrameBorderSize.Height) + this.Top + groupBox2.Top + button1.Top + button1.Height;

---------------------------------------------------------------------------------------------------------

●·●IColorSelector 接口

---------------------------------------------------------------------------------------------------------

2. ColorSelector:

AE:::部分AE功能实现代码
IColor pColor = new RgbColor(); pColor.RGB 255; IColorSelector pSelector newColorSelectorClass(); pSelector.Color = pColor; if (pSelector.DoModal(0)) { pColor =pSelector.Color; }
AE:::部分AE功能实现代码

效果:

AE:::部分AE功能实现代码

---------------------------------------------------------------------------------------------------------

●·●IColorBrowser 接口

---------------------------------------------------------------------------------------------------------

3. ColorBrowser:

AE:::部分AE功能实现代码
IColor pColor = new RgbColor(); pColor.RGB 255; IColorBrowser pColorBrowser newColorBrowser(); pColorBrowser.Color = pColor; if (pColorBrowser.DoModal(0)) { pColor =pColorBrowser.Color; }
AE:::部分AE功能实现代码

效果:

AE:::部分AE功能实现代码

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第A9个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:颜色台(Color Ramp)

---------------------------------------------------------------------------------------------------------

●·●IAlgorithmicColorRamp 接口

---------------------------------------------------------------------------------------------------------

1. AlgorithmicColorRamp:

定义函数:

AE:::部分AE功能实现代码
private IEnumColors CreateColorRamp(IColor fromColor,IColor toColor,int count) { IAlgorithmicColorRamp pRampColor new AlgorithmicColorRamp(); pRampColor.FromColor =fromColor; pRampColor.ToColor = toColor; pRampColor.Size = count; bool ok = false; pRampColor.CreateRamp(out ok); if (ok) { return pRampColor.Colors; } else returnnull; } }
AE:::部分AE功能实现代码

调用函数:颜色在 red 和 violet 之间变化!

AE:::部分AE功能实现代码
private void timer1_Tick(object sender, EventArgs e) { IRgbColor fromColor newRgbColor(); fromColor.Red 255; IRgbColor toColor new RgbColor(); toColor.Red =128; toColor.Blue 255; IEnumColors pEnumColors = CreateColorRamp(fromColor, toColor,50); IColor pColor nullfor (int i = 0; i < count;i++ ) { pColor =pEnumColors.Next(); } if (count == 50) { count 0; timer1.Enabled false; timer2.Enabled true; } count++; axPageLayoutControl1.PageLayout.Page.BackgroundColor= pColor; } private void timer2_Tick(object sender, EventArgs e) { IRgbColor fromColornew RgbColor(); fromColor.Red 128; fromColor.Blue 255; IRgbColor toColor newRgbColor(); toColor.Red 255; IEnumColors pEnumColors = CreateColorRamp(fromColor, toColor, 20); IColor pColor nullfor (int i = 0; i < count; i++) { pColor =pEnumColors.Next(); } if (count == 20) { count 0; timer2.Enabled false; timer1.Enabled true; } count++; axPageLayoutControl1.PageLayout.Page.BackgroundColor= pColor; }
AE:::部分AE功能实现代码

---------------------------------------------------------------------------------------------------------

●·●IRandomColorRamp 接口

---------------------------------------------------------------------------------------------------------

2. RandomColorRamp:

定义函数:

AE:::部分AE功能实现代码
private IColor CreateRandomColorRamp() { IRandomColorRamp pRandomColor newRandomColorRamp(); pRandomColor.StartHue 140; pRandomColor.EndHue 220; pRandomColor.MinValue 35; pRandomColor.MaxValue 100; pRandomColor.MinSaturation =32; pRandomColor.MaxSaturation 100; pRandomColor.Size 12; pRandomColor.Seed 7;bool ok = true; pRandomColor.CreateRamp(out ok); IEnumColors pEnumColors =pRandomColor.Colors; IColor pColor = pEnumColors.Next(); return pColor; }
AE:::部分AE功能实现代码

调用函数

private void button5_Click(object sender, EventArgs e) { IColor pColor =CreateRandomColorRamp(); axPageLayoutControl2.PageLayout.Page.BackgroundColor =pColor; }

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第G1个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:Symbol 对象

---------------------------------------------------------------------------------------------------------

●·●ISimpleMarkerSymbol 接口

---------------------------------------------------------------------------------------------------------

1. SimpleMarkerSymbol:

新建工具!

AE:::部分AE功能实现代码
using System; using System.Drawing; using System.Runtime.InteropServices; usingESRI.ArcGIS.ADF.BaseClasses; using ESRI.ArcGIS.ADF.CATIDs; using ESRI.ArcGIS.Controls;using System.Windows.Forms; using ESRI.ArcGIS.Display; using ESRI.ArcGIS.Geometry;namespace Symbol { /// /// Summary description for Tool1. /// [Guid("63835a8e-ae77-4817-b4e4-3b120b5232f9")] [ClassInterface(ClassInterfaceType.None)] [ProgId("Symbol.Tool1")] public sealed class Tool1 : BaseTool { #region COM Registration Function(s) [ComRegisterFunction()] [ComVisible(false)] static voidRegisterFunction(Type registerType) { // Required for ArcGIS Component Category Registrar support ArcGISCategoryRegistration(registerType); // // TODO: Add any COM registration code here // } [ComUnregisterFunction()] [ComVisible(false)] static voidUnregisterFunction(Type registerType) { // Required for ArcGIS Component Category Registrar support ArcGISCategoryUnregistration(registerType); // // TODO: Add any COM unregistration code here // #region ArcGIS Component Category Registrar generated code /// /// Required method for ArcGIS Component Category registration - /// Do not modify the contents of this method with the code editor. /// private static voidArcGISCategoryRegistration(Type registerType) { string regKey =string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID); ControlsCommands.Register(regKey); } /// /// Required method for ArcGIS Component Category unregistration - /// Do not modify the contents of this method with the code editor. /// private static void ArcGISCategoryUnregistration(Type registerType) {string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID); ControlsCommands.Unregister(regKey); } #endregion #endregion //---------------------------------------------------------------------------------------------------------private IHookHelper m_hookHelper = nullprivate IMapControl4 pMapControl; //--------------------------------------------------------------------------------------------------------- public Tool1() { // // TODO: Define values for the public properties //base.m_category = "Marker"//localizable text base.m_caption = "Marker";//localizable text base.m_message = "Marker"//localizable text base.m_toolTip ="Marker"//localizable text base.m_name = "Marker"//unique id, non-localizable (e.g. "MyCategory_MyTool") try // // TODO: change resource name if necessary //string bitmapResourceName = GetType().Name + ".bmp"base.m_bitmap = newBitmap(GetType(), bitmapResourceName); base.m_cursor = newSystem.Windows.Forms.Cursor(GetType(), GetType().Name + ".cur"); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap"); } } #regionOverriden Class Methods /// /// Occurs when this tool is created /// /// Instance of the application public override void OnCreate(object hook) { if (m_hookHelper == null) m_hookHelper new HookHelperClass(); m_hookHelper.Hook = hook; //---------------------------------------------------------------------------------------------------------if (hook is IMapControl4) { pMapControl = hook as IMapControl4; } //--------------------------------------------------------------------------------------------------------- // TODO: Add Tool1.OnCreate implementation /// /// Occurs when this tool is clicked /// public override void OnClick() { // TODO: Add Tool1.OnClick implementationpublic override void OnMouseDown(int Button, int Shift, int X, int Y) { // TODO: Add Tool1.OnMouseDown implementation //--------------------------------------------------------------------------------------------------------- ISimpleMarkerSymbol pMarkerSymbol = new SimpleMarkerSymbol(); pMarkerSymbol.Style =esriSimpleMarkerStyle.esriSMSCross; pMarkerSymbol.Color = GetColor(25500); pMarkerSymbol.Size 16; pMarkerSymbol.Outline true; pMarkerSymbol.OutlineSize 4; pMarkerSymbol.OutlineColor = GetColor(02550); IPoint pPoint =pMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); objectoMarkerSymbol = pMarkerSymbol; pMapControl.DrawShape(pPoint, ref oMarkerSymbol); //--------------------------------------------------------------------------------------------------------- } //--------------------------------------------------------------------------------------------------------- private IRgbColor GetColor(int r,int g,int b) { IRgbColor pColor new RgbColor(); pColor.Red = r; pColor.Green = g; pColor.Blue =b; return pColor; } //--------------------------------------------------------------------------------------------------------- public override void OnMouseMove(int Button,int Shift, int X, int Y) { // TODO: Add Tool1.OnMouseMove implementation publicoverride void OnMouseUp(int Button, int Shift, int X, int Y) { // TODO: Add Tool1.OnMouseUp implementation #endregion } }
AE:::部分AE功能实现代码

调用:

private void button1_Click(object sender, EventArgs e) { ICommand command newSymbol.Tool1(); command.OnCreate(axMapControl1.Object); axMapControl1.CurrentTool = command as ESRI.ArcGIS.SystemUI.ITool; }

---------------------------------------------------------------------------------------------------------

●·●IArrowMarkerSymbol 接口

---------------------------------------------------------------------------------------------------------

2. ArrowMarkerSymbol:

AE:::部分AE功能实现代码
public override void OnMouseDown(int Button, int Shift, int X, int Y) { // TODO: Add AddArrow.OnMouseDown implementation IArrowMarkerSymbol pArrowMarkerSymbol = newArrowMarkerSymbol(); pArrowMarkerSymbol.Style = esriArrowMarkerStyle.esriAMSPlain; pArrowMarkerSymbol.Color = GetColor(55111255); pArrowMarkerSymbol.Length 20; pArrowMarkerSymbol.Angle 90; pArrowMarkerSymbol.Width 10; IPoint pPoint =pMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); objectsymbol = pArrowMarkerSymbol; pMapControl.DrawShape(pPoint, ref symbol); }
AE:::部分AE功能实现代码

---------------------------------------------------------------------------------------------------------

●·●ICharacterMarkerSymbol 接口

---------------------------------------------------------------------------------------------------------

●·●stdole.StdFont

---------------------------------------------------------------------------------------------------------

3. CharacterMarkerSymbol:

AE:::部分AE功能实现代码
public override void OnMouseDown(int Button, int Shift, int X, int Y) { // TODO: Add Character.OnMouseDown implementation stdole.StdFont pFont = new stdole.StdFont(); //新建字体! pFont.Name "ESRI Default Marker"; pFont.Size 37; pFont.Italic true; ICharacterMarkerSymbol pCharacterSymbol new CharacterMarkerSymbol(); pCharacterSymbol.CharacterIndex 60; pCharacterSymbol.Color = GetColor(00255); pCharacterSymbol.Size 25; IPoint pPoint =pMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); objectoCharMarkerSymbol = pCharacterSymbol; pMapControl.DrawShape(pPoint, refoCharMarkerSymbol); }
AE:::部分AE功能实现代码

AE:::部分AE功能实现代码

---------------------------------------------------------------------------------------------------------

●·●IPictureMarkerSymbol 接口

---------------------------------------------------------------------------------------------------------

4. PictureMarkerSymbol:

AE:::部分AE功能实现代码
public override void OnMouseDown(int Button, int Shift, int X, int Y) {    // TODO: Add Character.OnMouseDown implementation    IPictureMarkerSymbol pPictureSymbol =new PictureMarkerSymbol(); pPictureSymbol.CreateMarkerSymbolFromFile(esriIPictureType.esriIPictureBitmap, @"F:\Desktop\1.bmp"); pPictureSymbol.Size =80; pPictureSymbol.BitmapTransparencyColor = GetColor(255255255); IPoint pPoint =pMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);object oMarkerSymbol = pPictureSymbol; pMapControl1.DrawShape(pPoint, refoMarkerSymbol); }
AE:::部分AE功能实现代码

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第G2个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:显示图层的属性窗口

首先新建 Command,下面是实现代码的重要部分!

AE:::部分AE功能实现代码
private bool SetupFeaturePropertySheet(ILayer layer) { if (layer == nullreturnfalse; ESRI.ArcGIS.Framework.IComPropertySheet pComPropSheet; pComPropSheet newESRI.ArcGIS.Framework.ComPropertySheet(); pComPropSheet.Title = layer.Name + " - 属性"; ESRI.ArcGIS.esriSystem.UID pPPUID new ESRI.ArcGIS.esriSystem.UIDClass(); pComPropSheet.AddCategoryID(pPPUID); // General....ESRI.ArcGIS.Framework.IPropertyPage pGenPage = newESRI.ArcGIS.CartoUI.GeneralLayerPropPageClass(); pComPropSheet.AddPage(pGenPage); //Source ESRI.ArcGIS.Framework.IPropertyPage pSrcPage = newESRI.ArcGIS.CartoUI.FeatureLayerSourcePropertyPageClass(); pComPropSheet.AddPage(pSrcPage); // Selection... ESRI.ArcGIS.Framework.IPropertyPage pSelectPage = new ESRI.ArcGIS.CartoUI.FeatureLayerSelectionPropertyPageClass(); pComPropSheet.AddPage(pSelectPage); // Display.... ESRI.ArcGIS.Framework.IPropertyPage pDispPage = new ESRI.ArcGIS.CartoUI.FeatureLayerDisplayPropertyPageClass(); pComPropSheet.AddPage(pDispPage); // Symbology.... ESRI.ArcGIS.Framework.IPropertyPage pDrawPage = new ESRI.ArcGIS.CartoUI.LayerDrawingPropertyPageClass(); pComPropSheet.AddPage(pDrawPage); // Fields... ESRI.ArcGIS.Framework.IPropertyPage pFieldsPage = new ESRI.ArcGIS.CartoUI.LayerFieldsPropertyPageClass(); pComPropSheet.AddPage(pFieldsPage); // Definition Query...ESRI.ArcGIS.Framework.IPropertyPage pQueryPage = newESRI.ArcGIS.CartoUI.LayerDefinitionQueryPropertyPageClass(); pComPropSheet.AddPage(pQueryPage); // Labels.... ESRI.ArcGIS.Framework.IPropertyPage pSelPage = new ESRI.ArcGIS.CartoUI.LayerLabelsPropertyPageClass(); pComPropSheet.AddPage(pSelPage); // Joins & Relates....ESRI.ArcGIS.Framework.IPropertyPage pJoinPage = newESRI.ArcGIS.ArcMapUI.JoinRelatePageClass(); pComPropSheet.AddPage(pJoinPage); // Setup layer link ESRI.ArcGIS.esriSystem.ISet pMySet = new ESRI.ArcGIS.esriSystem.SetClass(); pMySet.Add(layer); pMySet.Reset(); // make the symbology tab activepComPropSheet.ActivePage = 4// show the property sheet bool bOK = pComPropSheet.EditProperties(pMySet, 0); m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, m_activeView.Extent); return (bOK); }
AE:::部分AE功能实现代码

完整实现的 Command 代码如下:

AE:::部分AE功能实现代码 View Code

效果如下所示:

AE:::部分AE功能实现代码

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第G3个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:PageLayoutControl 的样式设置

Border:

AE:::部分AE功能实现代码
IActiveView pActiveView = axPageLayoutControl1.PageLayout as IActiveView; IMap pMap =pActiveView.FocusMap; IGraphicsContainer pGraphicsContainer = pActiveView asIGraphicsContainer; IMapFrame pMapFrame = pGraphicsContainer.FindFrame(pMap) asIMapFrame; IStyleSelector pStyleSelector new BorderSelector(); if(pStyleSelector.DoModal(axPageLayoutControl1.hWnd)) { IBorder PBorder = pStyleSelector.GetStyle(0as IBorder; pMapFrame.Border = PBorder; } axPageLayoutControl1.Refresh(esriViewDrawPhase.esriViewBackground, nullnull);
AE:::部分AE功能实现代码

Background:

AE:::部分AE功能实现代码
IActiveView pActiveView = axPageLayoutControl1.PageLayout as IActiveView; IMap pMap =pActiveView.FocusMap; IGraphicsContainer pGraphicsContainer = pActiveView asIGraphicsContainer; IMapFrame pMapFrame = pGraphicsContainer.FindFrame(pMap) asIMapFrame; IStyleSelector pStyleSelector new BackgroundSelector(); if(pStyleSelector.DoModal(axPageLayoutControl1.hWnd)) { IBackground pBackground = pStyleSelector.GetStyle(0as IBackground; pMapFrame.Background = pBackground; } pActiveView.Refresh();
AE:::部分AE功能实现代码

Shadow:

AE:::部分AE功能实现代码
IActiveView pActiveView = axPageLayoutControl1.PageLayout as IActiveView; IMap pMap =pActiveView.FocusMap; IGraphicsContainer pGraphicsContainer = pActiveView asIGraphicsContainer; IMapFrame pMapFrame = pGraphicsContainer.FindFrame(pMap) asIMapFrame; IStyleSelector pStyleSelector new ShadowSelector(); if(pStyleSelector.DoModal(axPageLayoutControl1.hWnd)) { IShadow pShadow = pStyleSelector.GetStyle(0as IShadow; IFrameProperties pFrameProperties = pMapFrameas IFrameProperties; pFrameProperties.Shadow = pShadow; } pActiveView.Refresh();
AE:::部分AE功能实现代码

MapGrid:

AE:::部分AE功能实现代码
IActiveView pActiveView = axPageLayoutControl1.PageLayout as IActiveView; IMap pMap =pActiveView.FocusMap; IGraphicsContainer pGraphicsContainer = pActiveView asIGraphicsContainer; IMapFrame pMapFrame = pGraphicsContainer.FindFrame(pMap) asIMapFrame; IStyleSelector pStyleSelector new MapGridSelector(); if(pStyleSelector.DoModal(axPageLayoutControl1.hWnd)) { IMapGrid pMapGrid = pStyleSelector.GetStyle(0as IMapGrid; IMapGrids pMapGrids = pMapFrame as IMapGrids;if (pMapGrid == null) { return; } pMapGrids.AddMapGrid(pMapGrid); } pActiveView.Refresh();
AE:::部分AE功能实现代码

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第G4个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:删除shapefile文件中的重复数据

第一种情况,只是出现重复数据,那么可以通过判断某一个字段值是否一样来进行删除重复的部分,实现如下:

AE:::部分AE功能实现代码
IFeatureLayer pFeatureLayer = axMapControl1.get_Layer(0as IFeatureLayer; IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; IFeatureCursor pFeatureCursor = pFeatureClass.Search(nullfalse); IFeature pFeature = pFeatureCursor.NextFeature();int count = 1while (pFeature != null) { string name = pFeature.get_Value(pFeatureClass.FindField("Name")).ToString(); //首先获取Name字段的名称属性 while (pFeature != null//外层遍历 { pFeature = pFeatureCursor.NextFeature(); //开始检查下一个要素与目标要素的关系 if (pFeature == null//若已经没有了,则终止 break; //跳出 stringfindName = pFeature.get_Value(pFeatureClass.FindField("Name")).ToString(); if(findName == name) //若名称相同,则删除此要素 pFeature.Delete(); } pFeatureCursor = pFeatureClass.Search(nullfalse); //重新从头开始 for (int i = 0; i <= count;i++ ) //为了获取比上一个目标要素下一个的目标,通过count来遍历 pFeature = pFeatureCursor.NextFeature(); count++;//每执行一次操作,增加一次count }
AE:::部分AE功能实现代码

AE:::部分AE功能实现代码

第二种情况,不仅出现某些属性,例如Name相同,但是几何体不是相同的,其中的一部分是残缺的,这个时候就要动用Area了,因为只有最大的那个Area才是完整的,因此要删除掉其他小的部分,可以按照如下实现

AE:::部分AE功能实现代码
IFeatureLayer pFeatureLayer = axMapControl1.get_Layer(0as IFeatureLayer; IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; IFeatureCursor pFeatureCursor = pFeatureClass.Search(nullfalse); IFeature pFeature = pFeatureCursor.NextFeature();int count = 1while (pFeature != null) { string name = pFeature.get_Value(pFeatureClass.FindField("Name")).ToString(); //首先获取Name字段的名称属性 double area = Convert.ToDouble(pFeature.get_Value(pFeatureClass.FindField("Area"))); //获取Area的大小while (pFeature != null//外层遍历 { pFeature = pFeatureCursor.NextFeature(); //开始检查下一个要素与目标要素的关系 if (pFeature == null//若已经没有了,则在从头开始 { pFeatureCursor = pFeatureClass.Search(nullfalse); //重新从头开始 pFeature = pFeatureCursor.NextFeature(); }string findName = pFeature.get_Value(pFeatureClass.FindField("Name")).ToString();double findArea = Convert.ToDouble(pFeature.get_Value(pFeatureClass.FindField("Area"))); if (findName == name && findArea < area) //若名称相同,且面积小的时候才删除,大的话就pass pFeature.Delete();else if (findName == name && findArea == area) //要是相同,则说明又碰到自己了,证明已经一圈过去了 break; } pFeatureCursor = pFeatureClass.Search(nullfalse); //重新从头开始 for(int i = 0; i <= count;i++ ) //为了获取比上一个目标要素下一个的目标,通过count来遍历 pFeature = pFeatureCursor.NextFeature(); count++; //每执行一次操作,增加一次count }
AE:::部分AE功能实现代码

实现代码可能不是最好的,是自己写的,要是数据很乱,就连最大的也是重复的,那就比较乱了,可以先试着下面的,将小的尽量删光,然后在用上面的将重复的删光!

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第G5个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:MapControl 与 PageLayoutControl 的交互

在 MapControl 和 PageLayoutControl 中进行关联!

首先要认清一点,虽然 MapControl 和 PageLayoutControl 中都有 ActiveView 属性,但是同样的属性在两者中表示的含义不同,在 MapControl 中,ActiveView 与 FocusMap 基本是同样的含义,是针对当前地图的;而 PageLayoutControl 中,ActiveView 指的是当前的布局图,并非 FocusMap,所以对于 MapControl 与 PageLayoutControl 之间的关联要用到 PageLayoutControl 中的 FocusMap,而非 ActiveView,对于 MapControl 则无所谓。它们之间的不同,可以通过显示其 Width 属性来实现,如下所示:

AE:::部分AE功能实现代码
private void button2_Click(object sender, EventArgs e) { label1.Text = axPageLayoutControl1.ActiveView.Extent.Width.ToString(); IActiveView pActiveView = axPageLayoutControl1.ActiveView.FocusMap as IActiveView; label2.Text = pActiveView.Extent.Width.ToString(); } private void button3_Click(object sender, EventArgs e) { label3.Text = axMapControl1.ActiveView.Extent.Width.ToString(); label4.Text = (axMapControl1.ActiveView.FocusMap as IActiveView).Extent.Width.ToString(); }
AE:::部分AE功能实现代码

显示如下:

AE:::部分AE功能实现代码

由此可见,PageLayoutControl 的 ActiveView 是独树一帜的!

AE:::部分AE功能实现代码
//当地图替换的时候触发 private void axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e) { IObjectCopy pObjectCopy = new ObjectCopy();object copyMap = axMapControl1.Map; object overWriteMap = axPageLayoutControl1.ActiveView.FocusMap; pObjectCopy.Overwrite(copyMap, refoverWriteMap); } //当布局的地图发生变化的时候触发,将 axPageLayoutControl 中地图的范围传递给 axMapControl private void axPageLayoutControl1_OnAfterScreenDraw(object sender, IPageLayoutControlEvents_OnAfterScreenDrawEvent e) { IActiveView activeView = axPageLayoutControl1.ActiveView.FocusMap as IActiveView; IDisplayTransformation displayTransformation = activeView.ScreenDisplay.DisplayTransformation; axMapControl1.Extent = displayTransformation.VisibleBounds; axMapControl1.ActiveView.Refresh(); } //当地图控件的范围发生变化时,将 axMapControl 中地图的范围传递给axPageLayoutControl private void axMapControl1_OnAfterDraw(object sender, IMapControlEvents2_OnAfterDrawEvent e) { IActiveView activeView = axPageLayoutControl1.ActiveView.FocusMap as IActiveView; IDisplayTransformation displayTransformation = activeView.ScreenDisplay.DisplayTransformation; displayTransformation.VisibleBounds = axMapControl1.Extent; axPageLayoutControl1.ActiveView.Refresh(); }
AE:::部分AE功能实现代码

另外,在 PageLayoutControl 中要想操作地图,还是要用到地图中的放大、缩小等工具,而要操作 PageLayoutControl 的框架时,则要用 PageLayout 的放大、缩小等工具!

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第G6个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:制作可以浮动的工具栏

第一步:导入一个类文件包,如下所示:

AE:::部分AE功能实现代码

文件包下载>>>点击下载<<<</P>

  • 在 项目 上右键选择 新建项》文件夹,命名为“rpaulo”,貌似是作者的名字!
  • 再在 此文件夹 下添加另外一个文件夹,命名为“toolbar”。
  • 然后 通过 添加》现有项,导航到文件夹中的 *.cs 和 *.resx 文件,将其全部倒入。

第二步:可以写代码了:

AE:::部分AE功能实现代码
using rpaulo.toolbar; //添加引用 ToolBarManager _toolBarManager; _toolBarManager newToolBarManager(thisthis); //新建工具管理 // The control Text property is used to draw the bar name while floating // and on view/hide menu. _toolBar1.Text = "Bar #1"; _toolBar2.Text "Bar #2"; _toolBar3.Text "Bar #3"; _toolBar4.Text "Bar #4"//Add toolbar (default position) _toolBarManager.AddControl(_toolBar1); // Add toolbar (floating) _toolBarManager.AddControl(_toolBar2, DockStyle.None); // Add toolbar (left) _toolBarManager.AddControl(_toolBar3, DockStyle.Left); // Add toolbar (left, on the left of _toolBar3) _toolBarManager.AddControl(_toolBar4, DockStyle.Left, _toolBar3, DockStyle.Left); // Add control ToolBarDockHolder holder =_toolBarManager.AddControl(_dateTimePicker, DockStyle.Bottom); // Added by mavholder.ToolbarTitle = "Appointment"; holder.AllowedBorders = AllowedBorders.Top|AllowedBorders.Bottom; _toolBarManager.AddControl(toolBar1, DockStyle.Right);
AE:::部分AE功能实现代码
  • 可以将所有的控件都加进去,都可以实现浮动的效果,但是 toolbar 可以根据“左右上下”进行调整,移动到左右的时候自动变成垂直工具条!
  • 可能默认的情况没有 ToolBar 控件,可以在 工具箱 上点击右键,选择 选择项,找到后,选中即可使用了!

效果图:

AE:::部分AE功能实现代码

最重要的是那些代码了,调用其实很容易的!

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第G7个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:ArcGIS Engine 实现鹰眼 & 分析

主要用到两个 MapControl 的事件:

  1> OnExtentUpdated:实现地图范围变化时触发。

  2> OnMouseDown:鼠标单击的时候触发。

第一步:实现 TrackRectangle 方法,通过拖拽矩形来放大地图。

private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { IEnvelope pEnv = axMapControl1.TrackRectangle(); axMapControl1.Extent = pEnv; }

第二步:实现信息从 MapControl1 传递到 MapControl2 中。

AE:::部分AE功能实现代码
private void axMapControl1_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e) {     //实现鹰眼的方框的 symbol 部分 ILineSymbol outLineSymbol = new SimpleLineSymbol();  //设置鹰眼图中的红线!outLineSymbol.Width = 2; outLineSymbol.Color = GetColor(25500255); IFillSymbol fillSymbol = new SimpleFillSymbol();  //设置填充符号的属性! fillSymbol.Color = GetColor(255000);   //设置完全透明色 fillSymbol.Outline = outLineSymbol;     //实现信息传递 IEnvelope envlope2 = e.newEnvelope as IEnvelope;  //定义新的信封范围,赋值为拖拽的矩形,或是extent IElement element2 = new RectangleElement();  //定义一个要素,用在后面放在容器中显示应眼框 element2.Geometry = envlope2;  //给矩形要素赋值上面的信封范围 IFillShapeElement fillShapeElement2 = element2 as IFillShapeElement;  //具有 symbol 属性! fillShapeElement2.Symbol = fillSymbol;  //赋值上面定义的 symbol IGraphicsContainer graphicsContainer2 = axMapControl2.Map as IGraphicsContainer;  //定义存储图形的容器 graphicsContainer2.DeleteAllElements();            //首先删除当前的全部图形,也就是上一次的鹰眼框 pElement = fillShapeElement2 as IElement;  //将 fillShapeElement2 在转为 IElement,以为后面方法只能用这个类型! graphicsContainer2.AddElement(pElement, 0);  //增加新的鹰眼框 axMapControl2.Refresh(esriViewDrawPhase.esriViewGeography, nullnull);  //刷新 MapControl2 } private IRgbColor GetColor(int r, int g, int b, int t)  //定义获取颜色的函数 { IRgbColor rgbColor = new RgbColor(); rgbColor.Red = r; rgbColor.Green = g; rgbColor.Blue = b; rgbColor.Transparency = (byte)t;  //透明度 return rgbColor; }
AE:::部分AE功能实现代码

第三步:实现点击 MapControl2 响应鹰眼框的移动。

private void axMapControl2_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { IPoint point = newESRI.ArcGIS.Geometry.Point();  //定义地理点 point.PutCoords(e.mapX, e.mapY);    //获取点击的地理点 axMapControl1.CenterAt(point);   }

效果显示:

AE:::部分AE功能实现代码

-------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第G8个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:独立窗口的鹰眼显示

№1:建立独立显示的窗体 Overview,在窗体中加入一个 MapControl 控件!

注意:将 axMapControl1 的 modifier 设置为 public,这样在主窗体中才可以调用!

AE:::部分AE功能实现代码
public partial class Overview : Form { IMapControl4 m_mapControl;  //建立用于显示主窗体 MapControl 的实例! IMap m_map; public Overview(IHookHelper hook)  //添加参数,用于与主窗体中 MapControl 相关联! { InitializeComponent(); m_mapControl = hook.Hook asIMapControl4;  //从 hook 中获取主窗体的 MapControl! m_map = m_mapControl.Map; }private void Overview_Load(object sender, EventArgs e) { for (int i = m_map.LayerCount - 1; i >= 0;i-- ) { axMapControl1.AddLayer(m_mapControl.get_Layer(i)); } axMapControl1.Extent = m_mapControl.FullExtent; } private voidaxMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { IPoint centerPoint new ESRI.ArcGIS.Geometry.Point(); centerPoint.PutCoords(e.mapX, e.mapY); m_mapControl.CenterAt(centerPoint); } }
AE:::部分AE功能实现代码

№2:在主窗体中写入交互内容!

AE:::部分AE功能实现代码
private Overview pOverview2;  //实例化一个鹰眼窗口 private void button2_Click(objectsender, EventArgs e) { HookHelper hookHelper new HookHelper();  //新建 HookHelper 的实例! hookHelper.Hook = axMapControl2.Object;  //将主窗体的 axMapControl1 赋值给其属性 Hook,实现关联! pOverview2 new Overview(hookHelper);  //实例化一个鹰眼窗体,并将 hookHelper 传递过去! pOverview2.Show();  //窗体显示! } private voidaxMapControl2_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e) { IEnvelope pEnv = e.newEnvelope as IEnvelope;  //获取矩形 IGraphicsContainer pGraphicsContainer = pOverview2.axMapControl1.Map as IGraphicsContainer;  //在鹰眼窗体上建立容器 IActiveView pActiveView = pGraphicsContainer as IActiveView;  //用于刷新的 pGraphicsContainer.DeleteAllElements();  //删除所有图形 ISimpleLineSymbol pSimpleLineSymbol new SimpleLineSymbol();  //新建线状样式 IRgbColor pColor newRgbColor(); pColor.Red 255; pSimpleLineSymbol.Width 1; pSimpleLineSymbol.Color =pColor; ISimpleFillSymbol pSimpleFillSymbol new SimpleFillSymbol();  //新建填充样式 IRgbColor pColor2 new RgbColor(); pColor2.Transparency 0; pSimpleFillSymbol.Color= pColor2; pSimpleFillSymbol.Outline = pSimpleLineSymbol; IElement pElement newRectangleElement();  //新建元素,用于后面添加到地图上面的 pElement.Geometry = pEnv;  //给元素赋予几何(矩形)属性,因为不具有 Symbol 属性,所以还要 QI 一下 IFillShapeElement pFillShapeElement = pElement as IFillShapeElement;  //用于赋予 symbol 的内容 pFillShapeElement.Symbol = pSimpleFillSymbol; pElement = pFillShapeElement asIElement;  //后面方法中只能用 IElement,所以在转回来! pGraphicsContainer.AddElement(pElement,0);  //添加元素,实现鹰眼效果 pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, nullnull);  //刷新,这是刷新的鹰眼窗体! }
AE:::部分AE功能实现代码

效果如下图所示:

AE:::部分AE功能实现代码

-------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第G9个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:自定义工具窗口

---------------------------------------------------------------------------------------------------------

●·●ICustomizeDialog 接口

  Members
Description
 
AE:::部分AE功能实现代码 CloseDialog Closes the customize dialog.
AE:::部分AE功能实现代码 CommandsCategory The GUID of the component category used for commands.
AE:::部分AE功能实现代码 DialogTitle The title of the customize dialog.
AE:::部分AE功能实现代码 DoubleClickDestination The ToolbarControl commands are added to when double clicked.
AE:::部分AE功能实现代码 IsDialogActive Indicates if the customize dialog is active on the screen.
AE:::部分AE功能实现代码 MenusCategory The GUID of the component category used for menu definitions.
AE:::部分AE功能实现代码 SetDoubleClickDestination Sets the ToolbarControl commands are added to when double clicked.
AE:::部分AE功能实现代码 ShowAddFromFile Indicates if the 'Add From File' button is available on the customize dialog.
AE:::部分AE功能实现代码 StartDialog Starts the modeless customize dialog.
AE:::部分AE功能实现代码 ToolbarsCategory The GUID of the component category used for toolbar definitions.

---------------------------------------------------------------------------------------------------------

●·●ICustomizeDialogEvents 接口

  Members
Description
 
AE:::部分AE功能实现代码 OnCloseDialog Fires when customize dialog is closed or exited.
AE:::部分AE功能实现代码 OnStartDialog Fires when customize dialog is displayed on screen.

---------------------------------------------------------------------------------------------------------

首先:定义窗口实例和委托实例!对于 ArcObjects 来说属性方法放在一个接口中,事件放在另外一个接口中!

ICustomizeDialog m_CustomizeDialog = new CustomizeDialogClass(); //自定义对话框实例 ICustomizeDialogEvents_OnStartDialogEventHandler startDialogE; //开始对话框委托,通过事件可以找到需要事件的委托类型! ICustomizeDialogEvents_OnCloseDialogEventHandler closeDialogE;   //关闭对话框委托

其次:定义函数!

AE:::部分AE功能实现代码
private void OnStartDialogHandler() { basicToolbarControl.Customize true; //工具条控件允许自定义工具 } private void OnCloseDialogHandler() { basicToolbarControl.Customize =false;   //工具条控件不允许自定义工具 chkCustomize.Checked false;      //将复选框的√去掉 }
AE:::部分AE功能实现代码

最后:实现事件!在 Form_Load 中写的!

AE:::部分AE功能实现代码
// Set the customize dialog box events. ICustomizeDialogEvents_Event pCustomizeDialogEvent = m_CustomizeDialog asICustomizeDialogEvents_Event;  //ICustomizeDialog 不具有事件,所以要查询到有事件的接口startDialogE = new ICustomizeDialogEvents_OnStartDialogEventHandler(OnStartDialogHandler);  //实例化开始委托 pCustomizeDialogEvent.OnStartDialog += startDialogE;  //用开始委托实现开始事件 closeDialogE = newICustomizeDialogEvents_OnCloseDialogEventHandler(OnCloseDialogHandler);  //实例化关闭委托 pCustomizeDialogEvent.OnCloseDialog += closeDialogE;  //用关闭委托实现关闭事件 //Set the title. m_CustomizeDialog.DialogTitle = "定制工具条";  //标题! // Set the ToolbarControl that new items will be added to. m_CustomizeDialog.SetDoubleClickDestination(basicToolbarControl);  //双击工具加到工具条控件中!
AE:::部分AE功能实现代码

另外是与复选框的交互!

AE:::部分AE功能实现代码
private void chkCustomize_CheckedChanged(object sender, EventArgs e) { if(chkCustomize.Checked == false) { m_CustomizeDialog.CloseDialog();  //关闭自定义对话框 } else { m_CustomizeDialog.StartDialog(basicToolbarControl.hWnd);  //弹出自定义对话框 } }
AE:::部分AE功能实现代码

-------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第U1个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:Map 与 PageLayout 切换后工具不变

实现在切换前后,对于Map的工具恢复到之前的工具,而PageLayoutControl也是一样的!

AE:::部分AE功能实现代码
ITool pMapTool = null;  //定义存储map的工具 ITool pPageLayoutTool null;  //定义存储pagelayout的工具 private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { if (tabControl1.SelectedIndex == 0) { if (axPageLayoutControl1.CurrentTool !=null)  //如果有工具则赋值,在没有转换buddy之前 pPageLayoutTool =axPageLayoutControl1.CurrentTool; axToolbarControl1.SetBuddyControl(axMapControl1); if(axMapControl1.CurrentTool == null)  //理论上讲默认都是null,然后给其赋值刚才的工具! axMapControl1.CurrentTool = pMapTool; } else if (axMapControl1.CurrentTool != null) pMapTool = axMapControl1.CurrentTool; axToolbarControl1.SetBuddyControl(axPageLayoutControl1); if(axPageLayoutControl1.CurrentTool == null) axPageLayoutControl1.CurrentTool =pPageLayoutTool; } }
AE:::部分AE功能实现代码

-------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第U2个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:在窗体中显示渐变颜色 & 通过名称找控件

实现效果:

AE:::部分AE功能实现代码

实现代码如下:

AE:::部分AE功能实现代码
private void button1_Click(object sender, EventArgs e) { IAlgorithmicColorRamp algColorRamp new AlgorithmicColorRampClass(); IRgbColor startColor new RgbColor(); startColor.Red 255; IRgbColor endColor new RgbColor(); endColor.Green 255; algColorRamp.FromColor = startColor; algColorRamp.ToColor = endColor; algColorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm; algColorRamp.Size32bool bture = true; algColorRamp.CreateRamp(out bture); IEnumColors pEnumColors =algColorRamp.Colors; for (int i = 1; i <= 32;i++ ) { object o; PictureBox pb;
o=this.GetType().GetField("pictureBox" + i.ToString(), BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this);  //通过控件名称来找控件的方法
if (o != null) { pb = (PictureBox)o; pb.BackColor =ColorTranslator.FromOle(pEnumColors.Next().RGB); } } }
AE:::部分AE功能实现代码

自己定义 pictureBox,实现如下:

AE:::部分AE功能实现代码
for (int i = 1; i <= 50;i++ ) { PictureBox pb new PictureBox(); pb.Height 10; pb.Width 500; pb.Location new System.Drawing.Point(10, i * 12); panel1.Controls.Add(pb); pb.BackColor =ColorTranslator.FromOle(pEnumColors.Next().RGB); }
AE:::部分AE功能实现代码

-------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第U3个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:获取地图是否处于编辑状态

引言:在操作地图的时候,可能某人设置了,左键可以实现拉框放大,中键和右键怎可以实现漫游,但是若是这样设置,当图层处于编辑状态的时候就糟糕了!因为操作会重叠,这个时候就需要判断图层是否处于编辑状态,只有处于非编辑状态的时候才要执行上面的方法!

AE:::部分AE功能实现代码
IFeatureLayer pFeatureLayer = axMapControl1.Map.get_Layer(0as IFeatureLayer;  //获取 IFeatureLayer IDataset pDataset =(IDataset) pFeatureLayer.FeatureClass;          //获取 IDataset IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit) pDataset.Workspace;  //获取 IWorkspaceEdit if(pWorkspaceEdit.IsBeingEdited()) {   //可以编辑状态 }
AE:::部分AE功能实现代码

●·●IDataset 接口

●·●IWorkspaceEdit 接口

-------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第U4个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:获取地图是否处于编辑状态

引言:在操作地图的时候,可能某人设置了,左键可以实现拉框

-------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第U5个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:获取地图是否处于编辑状态

引言:在操作地图的时候,可能某人设置了,左键可以实现拉框

-------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第U6个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:实现自定义的图层控制器

引言:通过TreeView,TreeNode实现自定义的图层控制器

实现:自定义的图层控制器(涉及图层组,IGroupLayer,ICompositeLayer)

treeView1.Nodes.Clear();
            TreeNode node = new TreeNode();
            node.Text = "图层数据";
            // 添加主地图控件中的所有图层到鹰眼控件中
            for (int i = 0; i
            {
                TreeNode newnode = new TreeNode();
                ILayer pLayer = axMapControl1.get_Layer(i) as ILayer;
                if (pLayer is IGroupLayer)
                {
                    ICompositeLayer pCL = pLayer as ICompositeLayer;
                    for (int j = 0; j < pCL.Count; j++) {
                        TreeNode node_son = new TreeNode();
                        node_son.Text = pCL.get_Layer(j).Name;
                        newnode.Nodes.Add(node_son);
                        node_son.Checked = true;
                    }
                }
                this.axMapControl2.AddLayer(pLayer);
                newnode.Text = pLayer.Name.ToString();
                newnode.Checked = true;
                newnode.ExpandAll();
                node.Nodes.Add(newnode);
            }
            node.ExpandAll();
            node.Checked = true;
            treeView1.Nodes.Add(node);
            // 设置 MapControl 显示范围至数据的全局范围
            this.axMapControl2.Extent = this.axMapControl1.FullExtent;
            // 刷新鹰眼控件地图
            this.axMapControl2.Refresh();

 效果图如下:

AE:::部分AE功能实现代码

-------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第U7个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:添加shp图层的几种方式

引言:通过IFeatureWorkspace,ShapefileWorkspaceFactory实现自定义的图层控制器

实现:从文件中直接添加shp到地图控件,从文件生成ILayer对象,然后加载到地图控件

 if (selectedLayer is IGroupLayer) {
                        IFeatureLayer pFeatureLayer;
                        IGroupLayer groupLayer = selectedLayer as IGroupLayer;

                        //第一种方式===========================
                        ShapefileWorkspaceFactory shape_factory = new ShapefileWorkspaceFactory();
                        IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)

                                                                             shape_factory.OpenFromFile(Pathname, 0);
                        pFeatureLayer = new FeatureLayerClass();
                        pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(strFilename);
                        pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
                        groupLayer.Add(pFeatureLayer);
                      
                    }else{

                    //第二种方式===================================
                        axMapControl1.AddShapeFile(Pathname, strFilename);//第二种方式
                    }

-------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第U8个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:给图层添加参考系

                     ILayer layer = axMapControl1.get_Layer(axMapControl1.LayerCount - i);
                    IFeatureLayer mFeatureLayer = layer as IFeatureLayer;
                    ISpatialReferenceFactory mSpatialRefFactory = new SpatialReferenceEnvironment();
                    IGeographicCoordinateSystem mGeoCoordinSystem = 

                                             mSpatialRefFactory.CreateGeographicCoordinateSystem(4214);

-------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣第U9个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●实现:线与线的相交计算、

               线与多边形的相交计算、

              多边形是否包含其他集合类型的计算

               求线与多边形(线)的交点:

                ISpatialFilter pspf = new SpatialFilterClass();
                pspf.Geometry = ppolyline_draw;//在地图上画的线,其余多边形相交
                pspf.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                ptp = pfea.Shape as ITopologicalOperator;//多边形或者是线对象
                IGeometry pgeo = ptp.Intersect(ppolyline_draw,

                                               esriGeometryDimension.esriGeometry0Dimension);

               多边形包含:

                IRelationalOperator mRelationalOperator=pfea.Shape as IRelationalOperator ;

                 mRelationalOperator.Contains(pc_draw.Point[k])

 

  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 是什么? I'm sorry, but I don't have any information on the code for the AE4108 chip. Can you provide me with some more context or details about what you're looking for? ### 回答2: AE4108芯片的代码是指用于控制和管理AE4108芯片功能的一系列指令和程序。AE4108芯片是一种高集成度的集成电路芯片,广泛应用于嵌入式系统和物联网应用。它具有低功耗、小尺寸、高性能的特点,能够实现多种功能,如数据处理、通信、传感和控制等。 AE4108芯片的代码主要是由软件工程师编写的,使用一种特定的编程语言,如C语言或汇编语言。代码可以分为多个模块,每个模块负责实现不同的功能,例如输入输出控制、数据处理算法、通信协议等。编写代码的过程需要根据具体的应用需求进行设计和开发。 在编写AE4108芯片的代码时,通常需要考虑以下几个方面: 1. 功能实现:根据产品需求,编写代码实现所需的功能,如数据采集、数据处理、通信等。代码需要根据芯片的特性合理地调用相关的寄存器和功能模块。 2. 代码优化:为了提高代码的效率和性能,需要进行代码优化。包括使用高效的算法、减少代码冗余、合理运用芯片的特殊功能等。 3. 错误处理:代码应该具备良好的错误处理机制,能够及时有效地处理各种异常情况,保证系统的稳定性和可靠性。 4. 硬件适配:代码需要适配AE4108芯片的硬件平台,包括与外围设备的接口、外部断、时钟等的协调与控制。 编写AE4108芯片的代码需要充分了解芯片的硬件特性和功能,并且掌握相应的编程技术。代码的质量和设计的合理性对于芯片的功能和性能具有重要影响,因此在编写代码的过程需要进行充分的测试和调试,确保代码的正确性和稳定性。 ### 回答3: AE4108芯片是一款针对嵌入式系统设计的微控制器芯片。其代码主要用于控制芯片的功能实现应用程序。 AE4108芯片的代码包括两部分:底层固件和应用层程序。 底层固件是指芯片内置的底层驱动程序和操作系统,用于控制芯片的硬件资源,如串口、GPIO、ADC等。底层固件负责与芯片的硬件进行交互,将硬件操作抽象为易于理解的接口函数供应用层程序调用。底层固件的代码由芯片厂商提供,并一般不对外公开。 应用层程序是指开发者根据具体需求编写的代码,用于实现具体的功能和应用。开发者可以使用C或汇编语言等编程语言编写应用层程序。应用层程序通过调用底层固件提供的接口函数,实现对芯片硬件资源的控制和访问。开发者可以根据自己的需要,编写各种应用程序,如传感器数据采集、通信接口控制等。 AE4108芯片的代码开发需要具备嵌入式系统开发的相关知识和开发工具。开发者需要了解嵌入式系统的硬件结构和资源分配,熟悉C或汇编语言的编程技术,并熟悉芯片厂商提供的开发工具链。开发者可以使用集成开发环境(IDE)来编写和调试代码,例如Keil MDK或IAR Embedded Workbench等。 总之,AE4108芯片的代码是由底层固件和应用层程序组成的,底层固件控制芯片硬件资源,应用层程序实现具体的功能和应用。开发者需要根据具体需求和芯片规格,编写相应的应用层程序,并借助开发工具链进行代码的编写和调试。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值