转自IT-GIS终结者原文ArcEngine创建IElement简单例子

代码下载地址: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, , 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, );
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, );
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, pGeometry.Envelope);
return pElement;
}
else
{
return null;
}
}
catch (Exception ex)
{
return null;
}
}

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-font-kerning:1.0pt;}

最新文章

  1. html布局小练习(百度首页)
  2. Java InMemoryCache
  3. centos7引导项修复
  4. 创建URL为空的解决办法
  5. 网络模拟器WANem使用配置图文教程
  6. [CF738B]Spotlights(前缀和,模拟)
  7. FAQ unzip无法解压文件
  8. 关于asp.net MVC 中的TryUpdateModel方法
  9. Netty 的Downstream 和 Upstream
  10. 学习笔记之Linux内核编译过程
  11. OS之多线程
  12. Dom对象和JQuery对象的详细介绍及其区别
  13. SQL Server :理解DCM页
  14. .net后台代码临时表创建
  15. 转:Web 测试的创作与调试技术
  16. hive 动态分区数设置
  17. 详解ES6中的 let 和const
  18. JSP获取input(含正则表达式)
  19. YiShop_做一个b2c商城要多少钱
  20. zTree实现地市县三级级联报错(二)

热门文章

  1. go-web编程之处理xml
  2. Django项目之Web端电商网站的实战开发(二)
  3. Direct2D 图形计算
  4. 【2017 Multi-University Training Contest - Team 6】Classes
  5. PHP用socket连接SMTP服务器发送邮件
  6. Flume Sinks官网剖析(博主推荐)
  7. valueof(), intvalue(0 parseint() 这三个方法怎么用
  8. [Angular] Progress HTTP Events with 'HttpRequest'
  9. 字符串中的空格替换问题(Java版)
  10. VS2012载入DLL编译出现试图载入格式不对的程序; 以及执行出现Mixed mode assembly is built against version 'v2.0.50727' of the