ArcEngine创建IElement简单例子
转自IT-GIS终结者原文ArcEngine创建IElement简单例子
代码下载地址:https://files.cnblogs.com/ogis/MapControlApplication2.rar
以下几个函数功能主要是向地图中添加IElement,一共四个函数:
GetColor,CreateSimpleLineSymbol,CreateSimpleFillSymbol,AddCreateElement
功能函数:AddCreateElement
调用例子:
ISymbol pSymbol = AEUtil.CreateSimpleFillSymbol(Color.Red, 100, esriSimpleFillStyle.esriSFSCross);
AEUtil.AddCreateElement(pFeature.ShapeCopy, m_MapControl.ActiveView, pSymbol, fucosKey);
通过red green blue 三色创建IRgbColor
public static IRgbColor GetColor(int r, int g, int b) { RgbColor color = new RgbColor(); color.Red = r; color.Green = g; color.Blue = b; return color; }
创建简单线Symbol
输入参数 color-颜色,width-宽度,style-线型,有七种线型可选
esriSLSSolid
esriSLSDash
esriSLSDot
esriSLSDashDot
esriSLSDashDotDot
esriSLSNull
esriSLSInsideFrame
public static ISymbol CreateSimpleLineSymbol(Color color, int width, esriSimpleLineStyle style) { ISimpleLineSymbol pSimpleLineSymbol; pSimpleLineSymbol = new SimpleLineSymbol(); pSimpleLineSymbol.Width = width; pSimpleLineSymbol.Color = GetColor(color.R, color.G, color.B); pSimpleLineSymbol.Style = style; return (ISymbol)pSimpleLineSymbol; }
创建面填充ISymbol对象.
fillColor-颜色,oLineWidth-外廓线宽,fillStyle-填充类型,有以下可选
esriSFSSolid esriSFSNull esriSFSHollow esriSFSHorizontal esriSFSVertical esriSFSForwardDiagonal esriSFSBackwardDiagonal esriSFSCross esriSFSDiagonalCross public static ISymbol CreateSimpleFillSymbol(Color fillColor, int oLineWidth, esriSimpleFillStyle fillStyle) { ISimpleFillSymbol pSimpleFillSymbol; pSimpleFillSymbol = new SimpleFillSymbol(); pSimpleFillSymbol.Style = fillStyle; pSimpleFillSymbol.Color = GetColor(fillColor.R, fillColor.G, fillColor.B); pSimpleFillSymbol.Outline = (ILineSymbol)CreateSimpleLineSymbol(fillColor, 1, esriSimpleLineStyle.esriSLSDash); return (ISymbol)pSimpleFillSymbol; } // 函数实现向地图中添加元素,pGeometry-元素形状,pActiveView-地图视图,pSymbol-符号,key-元素属性 public static IElement AddCreateElement(IGeometry pGeometry, IActiveView pActiveView, ISymbol pSymbol, string key) { try { IGraphicsContainer pGraphicsContainer = pActiveView.GraphicsContainer; IElement pElement = null; ILineElement pLineElement = null; IFillShapeElement pFillShapeElement = null; IMarkerElement pMarkerElement = null; ICircleElement pCircleElement = null; IElementProperties pElmentProperties = null; switch (pGeometry.GeometryType) { case esriGeometryType.esriGeometryEnvelope: { pElement = new RectangleElement(); pElement.Geometry = pGeometry; pFillShapeElement = (IFillShapeElement)pElement; pFillShapeElement.Symbol = (IFillSymbol)pSymbol; break; } case esriGeometryType.esriGeometryPolyline: { pElement = new LineElement(); pElement.Geometry = pGeometry; pLineElement = (ILineElement)pElement; pLineElement.Symbol = (ILineSymbol)pSymbol; break; } case esriGeometryType.esriGeometryLine: { pElement = new LineElement(); pElement.Geometry = pGeometry; pLineElement = (ILineElement)pElement; pLineElement.Symbol = (ILineSymbol)pSymbol; break; } case esriGeometryType.esriGeometryPolygon: { pElement = new PolygonElement(); pElement.Geometry = pGeometry; pFillShapeElement = (IFillShapeElement)pElement; pFillShapeElement.Symbol = (IFillSymbol)pSymbol; break; } case esriGeometryType.esriGeometryMultipoint: case esriGeometryType.esriGeometryPoint: { pElement = new MarkerElement(); pElement.Geometry = pGeometry; pMarkerElement = (IMarkerElement)pElement; pMarkerElement.Symbol = (IMarkerSymbol)pSymbol; break; } case esriGeometryType.esriGeometryCircularArc: { pElement = new CircleElementClass(); pElement.Geometry = pGeometry; pCircleElement = (ICircleElement)pElement; break; } default: pElement = null; break; } if (pElement != null) { pElmentProperties = pElement as IElementProperties; pElmentProperties.Name = key; pGraphicsContainer.AddElement(pElement, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, pGeometry.Envelope); return pElement; } else { return null; } } catch (Exception ex) { return null; } }
esriSFSSolid
esriSFSNull
esriSFSHollow
esriSFSHorizontal
esriSFSVertical
esriSFSForwardDiagonal
esriSFSBackwardDiagonal
esriSFSCross
esriSFSDiagonalCross
public static ISymbol CreateSimpleFillSymbol(Color fillColor, int oLineWidth, esriSimpleFillStyle fillStyle)
{
ISimpleFillSymbol pSimpleFillSymbol;
pSimpleFillSymbol = new SimpleFillSymbol();
pSimpleFillSymbol.Style = fillStyle;
pSimpleFillSymbol.Color = GetColor(fillColor.R, fillColor.G, fillColor.B);
pSimpleFillSymbol.Outline = (ILineSymbol)CreateSimpleLineSymbol(fillColor, 1, esriSimpleLineStyle.esriSLSDash);
return (ISymbol)pSimpleFillSymbol;
}
函数实现向地图中添加元素,pGeometry-元素形状,pActiveView-地图视图,pSymbol-符号,key-元素属性
public static IRgbColor GetColor(int r, int g, int b) { RgbColor color = new RgbColor(); color.Red = r; color.Green = g; color.Blue = b; return color; } public static IElement AddCreateElement(IGeometry pGeometry, IActiveView pActiveView, ISymbol pSymbol, string key) { try { IGraphicsContainer pGraphicsContainer = pActiveView.GraphicsContainer; IElement pElement = null; ILineElement pLineElement = null; IFillShapeElement pFillShapeElement = null; IMarkerElement pMarkerElement = null; ICircleElement pCircleElement = null; IElementProperties pElmentProperties = null; switch (pGeometry.GeometryType) { case esriGeometryType.esriGeometryEnvelope: { pElement = new RectangleElement(); pElement.Geometry = pGeometry; pFillShapeElement = (IFillShapeElement)pElement; pFillShapeElement.Symbol = (IFillSymbol)pSymbol; break; } case esriGeometryType.esriGeometryPolyline: { pElement = new LineElement(); pElement.Geometry = pGeometry; pLineElement = (ILineElement)pElement; pLineElement.Symbol = (ILineSymbol)pSymbol; break; } case esriGeometryType.esriGeometryLine: { pElement = new LineElement(); pElement.Geometry = pGeometry; pLineElement = (ILineElement)pElement; pLineElement.Symbol = (ILineSymbol)pSymbol; break; } case esriGeometryType.esriGeometryPolygon: { pElement = new PolygonElement(); pElement.Geometry = pGeometry; pFillShapeElement = (IFillShapeElement)pElement; pFillShapeElement.Symbol = (IFillSymbol)pSymbol; break; } case esriGeometryType.esriGeometryMultipoint: case esriGeometryType.esriGeometryPoint: { pElement = new MarkerElement(); pElement.Geometry = pGeometry; pMarkerElement = (IMarkerElement)pElement; pMarkerElement.Symbol = (IMarkerSymbol)pSymbol; break; } case esriGeometryType.esriGeometryCircularArc: { pElement = new CircleElementClass(); pElement.Geometry = pGeometry; pCircleElement = (ICircleElement)pElement; break; } default: pElement = null; break; } if (pElement != null) { pElmentProperties = pElement as IElementProperties; pElmentProperties.Name = key; pGraphicsContainer.AddElement(pElement, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, pGeometry.Envelope); return pElement; } else { return null; } } catch (Exception ex) { return null; } }
相关文章
- Java 创建一个简单的验证码图片
- 利用angular4和nodejs-express构建一个简单的网站(一)——构建前后端开发环境
- Jxl 简单运用 Excel创建,插入数据,图片,更新数据,
- 设计模式(1)-使用简单工厂优化代码
- Python网络编程之TCP套接字简单用法示例
- 【JAVA SERVLET 开发系列之二】创建WEBAPP详细步骤,通过SERVLET实现HTTP简单交互
- IOS通过NSUserDefaults实现简单的应用间数据传递
- C# 创建线程的简单方式:异步委托 .
- CICD详解(九)——gitlab简单使用
- Oracle创建简单视图案例
- 如何创建最简单的 SAP Kyma Function
- 最简单的Docker镜像教程:从头基于空镜像scratch创建一个新的Docker镜像
- [转]Console命令详解,让调试js代码变得更简单
- SAP Business Application Studio 里创建一个基于 CAP 模型的最简单的 OData 服务试读版
- ZZNUOJ_C语言1002:简单多项式求值(完整代码)
- Linux(1)——在Linux下安装Nodejs(详细教程,包会),并成功创建一个简单的服务器
- 基于JAVA实现的WEB端UI自动化 - WebDriver基础篇 - 实现简单的浏览器操作
- ListView乱谈之ListView中View复用机制的简单解析
- C++之enum class简单使用
- ruby简单的基本 3
- 【spring教程之中的一个】创建一个最简单的spring样例
- SpringCloud Zuul网关的简单理解
- Okhttp之CallServerInterceptor简单分析
- 基于JAVA实现的WEB端UI自动化 - WebDriver基础篇 - 实现简单的浏览器操作