ArcEngine 创建IElement简单例子 C#代码
2010-10-19 16:21
435 查看
代码下载地址:http://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;
}
}
相关文章推荐
- ArcEngine创建IElement简单例子
- ArcEngine创建IElement简单例子
- 收了100元辛苦费,写了一个最简单的C#ASP.NET的3层架构例子代码,源码是通过代码生成器生成的【写程序的效率神奇的高】
- C#创建文本文件代码(超级简单)
- 用C#创建XML[简单代码]
- c#匿名类型最简单的例子 自动帮助我们创建类
- .NET C# 创建WebService服务简单的例子
- Singleton模式(Singleton创建类型)c#简单的例子
- .NET C# 创建WebService服务简单的例子
- 用C#创建XML[简单代码]
- 收了100元辛苦费,写了一个最简单的C#ASP.NET的3层架构例子代码
- .NET C# 创建WebService服务简单的例子
- C# WebService创建、发布、调用的简单例子
- C#设计模式——抽象工厂 非洲美洲食物链简单例子代码
- C#创建文本文件代码(超级简单)
- sql 存储过程 几个 简单例子,及在asp.net(C#)中调用存储过程的代码
- 转贴:一个简单的C#多线程间同步的例子
- 用storyboard与代码创建一个简单的求和计算器
- delphi中用api创建多线程的简单例子
- C#+ArcEngine:shp矢量点转Tin(VS2010窗体+代码)