[AE] ArcGIS Engine - 地图整饰 - 添加图形元素(临时的Geometry)

图形元素:不在数据库中保存的地理实体,一个临时的元素

相关知识:http://blog.csdn.net/summer_dew/article/details/79187995

思路:

以添加点元素到地图控件中为例:

  1. 创建点符号

     ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass(); //创建类
     pSimpleMarkerSymbol.Color = GetRGB(0, 255, 0); //自定义得到颜色函数
     pSimpleMarkerSymbol.Size = 5; //设置大小
     pSimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSDiamond; //设置样式
    
  2. 创建点的位置

     //点位置
     IPoint pPoint = new PointClass();
     pPoint.PutCoords(e.mapX, e.mapY);
    
  3. 创建点元素

     //点
     IMarkerElement pMarkerElement = new MarkerElementClass();
     pMarkerElement.Symbol = pSimpleMarkerSymbol; //赋值点元素的符号
     IElement pElement = pMarkerElement as IElement; 
     pElement.Geometry = pPoint as IGeometry; //赋值点位置
    
  4. 加入容器

     IMap pMap = axMapControl1.Map;
     IGraphicsContainer pGraphicsContainer = pMap as IGraphicsContainer;
     pGraphicsContainer.AddElement(pElement, 0);
    
  5. 刷新

     IActiveView pActiveView = pMap as IActiveView;
     pActiveView.Refresh();
    

代码:

//添加点、线、面元素的点击事件 标记Flag变量
private int Flag = -1;
private void drawMarkerElementToolStripMenuItem_Click(object sender, EventArgs e)
{
    Flag = 11; //点
}

private void drawLineElementToolStripMenuItem_Click(object sender, EventArgs e)
{
    Flag = 12; //线
}

private void drawPolygonElementToolStripMenuItem_Click(object sender, EventArgs e)
{
    Flag = 13; //面
}
//MapControl点击事件
private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
{
    if (e.button == 1) {
        switch (Flag) {
            case 11: //点
                {
                    //点符号样式
                    ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass();
                    pSimpleMarkerSymbol.Color = GetRGB(0, 255, 0);
                    pSimpleMarkerSymbol.Size = 5;
                    pSimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSDiamond;
                    //点位置
                    IPoint pPoint = new PointClass();
                    pPoint.PutCoords(e.mapX, e.mapY);
                    //点
                    IMarkerElement pMarkerElement = new MarkerElementClass();
                    pMarkerElement.Symbol = pSimpleMarkerSymbol;
                    IElement pElement = pMarkerElement as IElement;
                    pElement.Geometry = pPoint as IGeometry;
                    //加入地图
                    IMap pMap = axMapControl1.Map;
                    IActiveView pActiveView = pMap as IActiveView;
                    IGraphicsContainer pGraphicsContainer = pMap as IGraphicsContainer;
                    pGraphicsContainer.AddElement(pElement, 0);
                    pActiveView.Refresh();
                    break;
                }
            case 12: //线
                {
                    //线符号
                    ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass();
                    pSimpleLineSymbol.Color = GetRGB(0, 255, 0);
                    pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSDash;
                    //线
                    ILineElement pLineElement = new LineElementClass();
                    pLineElement.Symbol = pSimpleLineSymbol;
                    //位置
                    IElement pElement = pLineElement as IElement;
                    pElement.Geometry = axMapControl1.TrackLine();
                    //加入地图并刷新
                    IMap pMap = axMapControl1.Map;
                    IActiveView pActiveView = pMap as IActiveView;
                    IGraphicsContainer pGraphicsContainer = pMap as IGraphicsContainer;
                    pGraphicsContainer.AddElement(pElement, 0);
                    pActiveView.Refresh();
                    break;
                }
            case 13: //面
                {
                    IMap pMap = axMapControl1.Map; //获取Map对象
                    IActiveView pActiveView = pMap as IActiveView; //获取与Map相关联的活动视图
                    IGraphicsContainer pGraphicsContainer = pMap as IGraphicsContainer; //获取与Map相关联的图形容器
                    IFillShapeElement pPolygonElement = new PolygonElementClass(); //创建新的图形元素,并设置符号
                    //设置符号
                    ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass();
                    pSimpleFillSymbol.Color = GetRGB(0, 255, 0);
                    pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSDiagonalCross;
                    pPolygonElement.Symbol = pSimpleFillSymbol;
                    IElement pElement = pPolygonElement as IElement;
                    pElement.Geometry = axMapControl1.TrackPolygon();
                    pGraphicsContainer.AddElement(pElement, 0);
                    pActiveView.Refresh();
                    break;
                }
        }
    }
    else if (e.button == 2)
    {
        contextMenuStrip3.Show(axTOCControl1, e.x, e.y);
    }
    
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

geodoer

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值