1. 程式人生 > >ArcGIS Engine 線段繪制研究

ArcGIS Engine 線段繪制研究

map sco tar div img esri private sym 形狀

轉自原文 ArcGIS Engine 線段繪制研究

基本步驟

構建形狀

1. 創建 IPoint
IPoint m_Point = new PointClass();
m_Point.PutCoords(x, y);

2. 創建 IPointCollection
IPointCollection m_PointCollection = new PolylineClass();
m_PointCollection.AddPoint(m_Point, ref Type.Missing, ref Type.Missing);

3. 創建 IPolyline
IPolyline m_Polyline = new PolylineClass();

m_Polyline = m_PointCollection as IPolyline;

4. 創建 IElement
// Element 不能實例化,需要用其派生類實例化
IElement m_Element = m_SimpleLineSymbol as IElement;
m_Element.Geometry = m_Polyline;

設置形狀樣式
1. 創建 ISimpleLineSymbol
ISimpleLineSymbol m_SimpleLineSymbol = new SimpleLineSymbolClass();

2. 創建 ILineElement
ILineElement m_LineElement = new LineElementClass();
m_LineElement.Symbol = m_SimpleLineSymbol;

加載到地圖
IMap m_Map = axMapControl1.Map;
IActiveView m_ActiveView = m_Map as IActiveView;
IGraphicsContainer m_Container = m_Map as IGraphicsContainer;

m_Container.AddElement(m_Element, 0);

m_Active.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

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

其他方法

技術分享圖片
private void DrawLine()  
{  
    ILineElement pLineElement;  
    IElement pLElement;  
      
    IPolyline pLine;  
      
    RgbColor pColor = new RgbColor();  
    pColor.Red = 0;  
    pColor.Green = 0;  
    pColor.Blue = 255;  
      
    ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass();  
    pSimpleLineSymbol.Color = pColor;  
    pSimpleLineSymbol.Width = 5;  
      
    pLineElement = new LineElementClass();  
    pLineElement.Symbol = pSimpleLineSymbol;  
      
    pLElement = pLineElement as IElement;  
      
    IRubberBand pRubberBand;  
    pRubberBand = new RubberLineClass();  
    pLine = pRubberBand.TrackNew(axMapControl1.ActiveView.ScreenDisplay, null) as IPolyline;  
      
    pLElement.Geometry = pLine;  
      
    IGraphicsContainer pGraphicsContainer;  
    pGraphicsContainer = axMapControl1.ActiveView as IGraphicsContainer; //把地圖的當前view作為圖片的容器  
      
    pGraphicsContainer.AddElement(pLElement, 0);//把剛剛的element轉到容器上  
    axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);  
}  
View Code

ArcGIS Engine 線段繪制研究