You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							392 lines
						
					
					
						
							15 KiB
						
					
					
				
			
		
		
	
	
							392 lines
						
					
					
						
							15 KiB
						
					
					
				using ESRI.ArcGIS.Carto; | 
						|
using ESRI.ArcGIS.Display; | 
						|
using ESRI.ArcGIS.Geometry; | 
						|
using System; | 
						|
using System.Collections.Generic; | 
						|
using System.Linq; | 
						|
using System.Runtime.InteropServices; | 
						|
using System.Text; | 
						|
using System.Threading.Tasks; | 
						|
 | 
						|
namespace Kingo.Plugin.MapView.Model | 
						|
{ | 
						|
    /// <summary> | 
						|
    /// 线模型 | 
						|
    /// </summary> | 
						|
    public class LineModel | 
						|
    { | 
						|
 | 
						|
        //ILineMovePointFeedback s = new LineMovePointFeedbackClass(); | 
						|
        //IMoveLineFeedback s1 = new MoveLineFeedbackClass(); | 
						|
        /// <summary> | 
						|
        /// 线对象 | 
						|
        /// </summary> | 
						|
        public IPointCollection Line { get; set; } | 
						|
        public List<IElement> PointElements = new List<IElement>(); | 
						|
        /// <summary> | 
						|
        /// 显示线元素 | 
						|
        /// </summary> | 
						|
        public IElement LineElement { get; set; } | 
						|
        /// <summary> | 
						|
        /// 跟随线对象 | 
						|
        /// </summary> | 
						|
        public ILineMovePointFeedback FollowLine { get; set; } | 
						|
        /// <summary> | 
						|
        /// 显示跟随线元素 | 
						|
        /// </summary> | 
						|
        public IElement FollowLineElement { get; set; } | 
						|
        /// <summary> | 
						|
        /// 计算线上点的坐标所用到的宽度比例 | 
						|
        /// </summary> | 
						|
        public double Scale { get; set; } | 
						|
        /// <summary> | 
						|
        /// 线样式 | 
						|
        /// </summary> | 
						|
        public ILineSymbol LineSymbol { get; private set; } | 
						|
 | 
						|
        public bool IsAutoTrackPoint { get; set; } | 
						|
        /// <summary> | 
						|
        /// 跟随线样式 | 
						|
        /// </summary> | 
						|
        public ILineSymbol FollowLineSymbol { get; private set; } | 
						|
        private IActiveView ActiveView { get; set; } | 
						|
        public LineModel(IActiveView pActiveView, esriSimpleLineStyle pLineStyle, double pScale = 1) | 
						|
        { | 
						|
            this.ActiveView = pActiveView; | 
						|
            //this.Line = new Polyline(); | 
						|
            //this.FollowLine = new Polyline(); | 
						|
            this.Scale = pScale; | 
						|
            // 获取IRGBColor接口 | 
						|
            IRgbColor color = new RgbColor(); | 
						|
            // 设置颜色属性 | 
						|
            color.Red = 0; | 
						|
            color.Green = 255; | 
						|
            color.Blue = 255; | 
						|
            // 获取ILine符号接口 | 
						|
            ILineSymbol outline = new SimpleLineSymbol(); | 
						|
            // 设置线符号属 | 
						|
            outline.Width = 1.5; | 
						|
            outline.Color = color; | 
						|
            (outline as SimpleLineSymbol).Style = pLineStyle; | 
						|
            this.LineSymbol = outline; | 
						|
            this.FollowLineSymbol = outline; | 
						|
        } | 
						|
        public LineModel(IActiveView pActiveView, esriSimpleLineStyle pLineStyle, esriSimpleLineStyle pFollowLineStyle, double pScale = 1) | 
						|
        { | 
						|
            this.ActiveView = pActiveView; | 
						|
            //this.Line = new Polyline(); | 
						|
            //this.FollowLine = new Polyline(); | 
						|
            this.Scale = pScale; | 
						|
            // 获取IRGBColor接口 | 
						|
            IRgbColor color = new RgbColor(); | 
						|
            // 设置颜色属性 | 
						|
            color.Red = 0; | 
						|
            color.Green = 255; | 
						|
            color.Blue = 255; | 
						|
            // 获取ILine符号接口 | 
						|
            ILineSymbol outline = new SimpleLineSymbol(); | 
						|
            // 设置线符号属 | 
						|
            outline.Width = 1.5; | 
						|
            outline.Color = color; | 
						|
            (outline as SimpleLineSymbol).Style = pLineStyle; | 
						|
            this.LineSymbol = outline; | 
						|
            this.FollowLineSymbol = outline; | 
						|
            (this.FollowLineSymbol as SimpleLineSymbol).Style = pFollowLineStyle; | 
						|
        } | 
						|
 | 
						|
        public void Init() | 
						|
        { | 
						|
            this.Line = new Polyline(); | 
						|
            //this.FollowLine = new LineMovePointFeedbackClass(); | 
						|
 | 
						|
            ActiveView.ScreenDisplay.SetSymbol(FollowLineSymbol as ISymbol); | 
						|
            this.FollowLine = new LineMovePointFeedbackClass() { Symbol = FollowLineSymbol as ESRI.ArcGIS.Display.ISymbol, Display = ActiveView.ScreenDisplay }; | 
						|
            this.FollowLine.Symbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen; | 
						|
        } | 
						|
        /// <summary> | 
						|
        /// 设置线的样式 | 
						|
        /// </summary> | 
						|
        /// <param name="pSymbol"></param> | 
						|
        public void SetLineSymbol(ILineSymbol pSymbol) | 
						|
        { | 
						|
            this.LineSymbol = pSymbol; | 
						|
        } | 
						|
        /// <summary> | 
						|
        /// 设置跟随线的样式 | 
						|
        /// </summary> | 
						|
        /// <param name="pSymbol"></param> | 
						|
        public void SetFollowLineSymbol(ILineSymbol pSymbol) | 
						|
        { | 
						|
            this.FollowLineSymbol = pSymbol; | 
						|
        } | 
						|
        /// <summary> | 
						|
        /// 绘制线对象 | 
						|
        /// </summary> | 
						|
        public void DrawLine(int pIndex = -1) | 
						|
        { | 
						|
            if (this.Line == null || this.Line.PointCount == 0) | 
						|
            { | 
						|
                ActiveView.GraphicsContainer.DeleteAllElements(); | 
						|
                ActiveView.Refresh(); | 
						|
                this.PointElements.Clear(); | 
						|
                this.LineElement = null; | 
						|
                this.FollowLineElement = null; | 
						|
            } | 
						|
            else | 
						|
            { | 
						|
                if (PointElements.Count > this.Line.PointCount) | 
						|
                { | 
						|
                    if (pIndex == -1) | 
						|
                    { | 
						|
                        pIndex = PointElements.Count - 1; | 
						|
                    } | 
						|
                    IPoint endPointForElement = (IPoint)PointElements[pIndex].Geometry; | 
						|
                    IPoint endPointForLine = (this.Line as IPolyline).ToPoint; | 
						|
                    if (endPointForElement.X != endPointForLine.X || endPointForElement.Y != endPointForLine.Y) | 
						|
                    { | 
						|
                        IElement e = PointElements[pIndex]; | 
						|
                        ActiveView.GraphicsContainer.DeleteElement(e); | 
						|
                        PointElements.Remove(e); | 
						|
                        e = null; | 
						|
                    } | 
						|
                } | 
						|
                else if (PointElements.Count < this.Line.PointCount) | 
						|
                { | 
						|
                    if (pIndex == -1) | 
						|
                    { | 
						|
                        pIndex = PointElements.Count; | 
						|
                    } | 
						|
                    IPoint endPointForLine = (this.Line as IPolyline).ToPoint; | 
						|
                    IMarkerElement e = new MarkerElementClass(); | 
						|
                    // 获取IRGBColor接口 | 
						|
                    IRgbColor color = new RgbColor(); | 
						|
                    if (IsAutoTrackPoint) | 
						|
                    { | 
						|
                        // 设置颜色属性 | 
						|
                        color.Red = 100; | 
						|
                        color.Green = 0; | 
						|
                        color.Blue = 255; | 
						|
                    } | 
						|
                    else | 
						|
                    { | 
						|
                        // 设置颜色属性 | 
						|
                        color.Red = 255; | 
						|
                        color.Green = 255; | 
						|
                        color.Blue = 0; | 
						|
                    } | 
						|
                    IMarkerSymbol symbol = new SimpleMarkerSymbolClass(); | 
						|
                    symbol.Color = color; | 
						|
                    symbol.Size = 5; | 
						|
                    e.Symbol = symbol; | 
						|
                    (e as IElement).Geometry = endPointForLine; | 
						|
                    ActiveView.GraphicsContainer.AddElement(e as IElement, 0); | 
						|
                    PointElements.Insert(pIndex, e as IElement); | 
						|
                } | 
						|
                else | 
						|
                { | 
						|
                    if (pIndex == -1) | 
						|
                    { | 
						|
                        pIndex = PointElements.Count - 1; | 
						|
                    } | 
						|
                    IPoint endPointForLine = (this.Line as IPolyline).ToPoint; | 
						|
                    IElement e = PointElements[pIndex]; | 
						|
                    e.Geometry = endPointForLine; | 
						|
                } | 
						|
                if (this.LineElement == null) | 
						|
                { | 
						|
                    if (this.Line.PointCount >= 2) | 
						|
                    { | 
						|
                        #region 构造新的元素 | 
						|
                        ILineElement pFillShapeElement = new LineElementClass(); | 
						|
                        pFillShapeElement.Symbol = this.LineSymbol; | 
						|
                        this.LineElement = pFillShapeElement as IElement; | 
						|
                        this.LineElement.Geometry = this.Line as IGeometry; | 
						|
                        ActiveView.GraphicsContainer.AddElement(this.LineElement, 0); | 
						|
                        #endregion | 
						|
                    } | 
						|
                } | 
						|
                else | 
						|
                { | 
						|
                    if (this.Line.PointCount < 2) | 
						|
                    { | 
						|
                        #region 当点集合小于2的时候,删除对应的元素 | 
						|
                        ActiveView.GraphicsContainer.DeleteElement(this.LineElement); | 
						|
                        this.LineElement = null; | 
						|
                        #endregion | 
						|
                    } | 
						|
                    else | 
						|
                    { | 
						|
                        #region 更新现有元素 | 
						|
                        this.LineElement.Geometry = this.Line as IGeometry; | 
						|
                        #endregion | 
						|
                    } | 
						|
                } | 
						|
                DrawFollowLine(); | 
						|
                IPointCollection newGeo = new Polyline(); | 
						|
                if (this.Line.PointCount > 1) | 
						|
                { | 
						|
                    newGeo.AddPoint(this.Line.get_Point(this.Line.PointCount - 2)); | 
						|
                } | 
						|
                newGeo.AddPoint(this.Line.get_Point(this.Line.PointCount - 1)); | 
						|
                //if (this.FollowLine != null && this.FollowLine.PointCount > 0) | 
						|
                //{ | 
						|
                //    newGeo.AddPoint(this.FollowLine.get_Point(this.FollowLine.PointCount - 1)); | 
						|
                //} | 
						|
                if (newGeo.PointCount > 1) | 
						|
                { | 
						|
                    if ((newGeo as IGeometry).IsEmpty) | 
						|
                        return; | 
						|
                    ITopologicalOperator topo = newGeo as ITopologicalOperator; | 
						|
                    if (topo != null) | 
						|
                    { | 
						|
                        topo.Simplify(); | 
						|
                        //注释注释缓冲代码,解决在GIS10.2环境中绘制线物面卡顿问题 | 
						|
                        //IGeometry geo = topo.Buffer(10); | 
						|
                        ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, (newGeo as IGeometry).Envelope); | 
						|
                    } | 
						|
                } | 
						|
            } | 
						|
        } | 
						|
        /// <summary> | 
						|
        /// 绘制鼠标跟随线 | 
						|
        /// </summary> | 
						|
        public void DrawFollowLine() | 
						|
        { | 
						|
            //if (this.FollowLine != null && this.FollowLine.PointCount != 0) | 
						|
            //{ | 
						|
            //    if (this.FollowLineElement == null) | 
						|
            //    { | 
						|
            //        #region 构造新的元素 | 
						|
            //        ILineElement pFillShapeElement = new LineElementClass(); | 
						|
            //        pFillShapeElement.Symbol = this.FollowLineSymbol; | 
						|
            //        this.FollowLineElement = pFillShapeElement as IElement; | 
						|
            //        this.FollowLineElement.Geometry = this.FollowLine as IGeometry; | 
						|
            //        ActiveView.GraphicsContainer.AddElement(this.FollowLineElement, 0); | 
						|
            //        #endregion | 
						|
            //    } | 
						|
            //    else | 
						|
            //    { | 
						|
            //        #region 更新现有元素 | 
						|
            //        this.FollowLineElement.Geometry = this.FollowLine as IGeometry; | 
						|
            //        #endregion | 
						|
            //        if (this.Line.PointCount == 0) | 
						|
            //        { | 
						|
            //            ActiveView.GraphicsContainer.DeleteElement(this.FollowLineElement); | 
						|
            //            this.FollowLineElement = null; | 
						|
            //        } | 
						|
            //    } | 
						|
            //} | 
						|
            //else | 
						|
            //{ | 
						|
            //} | 
						|
        } | 
						|
        /// <summary> | 
						|
        /// 刷新线上的指定索引处的点 | 
						|
        /// </summary> | 
						|
        public void RefreshPoint(int pPointIndex) | 
						|
        { | 
						|
            if (this.Line.PointCount > pPointIndex) | 
						|
            { | 
						|
                this.DrawLine(pPointIndex); | 
						|
                if (PointElements.Count > this.Line.PointCount) | 
						|
                { | 
						|
                    IPoint endPointForElement = (IPoint)PointElements[PointElements.Count - 1].Geometry; | 
						|
                    IPoint endPointForLine = (this.Line as IPolyline).ToPoint; | 
						|
                    if (endPointForElement.X != endPointForLine.X || endPointForElement.Y != endPointForLine.Y) | 
						|
                    { | 
						|
                        IElement e = PointElements[pPointIndex]; | 
						|
                        ActiveView.GraphicsContainer.DeleteElement(e); | 
						|
                        PointElements.Remove(e); | 
						|
                        e = null; | 
						|
                    } | 
						|
                } | 
						|
                else if (PointElements.Count < this.Line.PointCount) | 
						|
                { | 
						|
                    IPoint endPointForLine = (this.Line as IPolyline).ToPoint; | 
						|
                    IMarkerElement e = new MarkerElementClass(); | 
						|
                    // 获取IRGBColor接口 | 
						|
                    IRgbColor color = new RgbColor(); | 
						|
                    // 设置颜色属性 | 
						|
                    color.Red = 255; | 
						|
                    color.Green = 255; | 
						|
                    color.Blue = 0; | 
						|
                    IMarkerSymbol symbol = new SimpleMarkerSymbolClass(); | 
						|
                    symbol.Color = color; | 
						|
                    symbol.Size = 5; | 
						|
                    e.Symbol = symbol; | 
						|
                    (e as IElement).Geometry = endPointForLine; | 
						|
                    ActiveView.GraphicsContainer.AddElement(e as IElement, 0); | 
						|
                    PointElements.Insert(pPointIndex, e as IElement); | 
						|
                } | 
						|
                else if (pPointIndex > -1) | 
						|
                { | 
						|
                    IPoint endPointForLine = this.Line.get_Point(pPointIndex); | 
						|
                    IElement e = PointElements[pPointIndex]; | 
						|
                    e.Geometry = endPointForLine; | 
						|
                } | 
						|
 | 
						|
                IPointCollection newGeo = new Polyline(); | 
						|
                int i = pPointIndex - 1; | 
						|
                if (i >= 0) | 
						|
                { | 
						|
                    newGeo.AddPoint(this.Line.get_Point(i)); | 
						|
                } | 
						|
                i = pPointIndex; | 
						|
                if (i >= 0) | 
						|
                { | 
						|
                    newGeo.AddPoint(this.Line.get_Point(i)); | 
						|
                } | 
						|
                i = pPointIndex + 1; | 
						|
                if (i < this.Line.PointCount) | 
						|
                { | 
						|
                    newGeo.AddPoint(this.Line.get_Point(i)); | 
						|
                } | 
						|
                if (newGeo.PointCount > 1) | 
						|
                { | 
						|
                    ITopologicalOperator topo = newGeo as ITopologicalOperator; | 
						|
                    if (topo != null) | 
						|
                    { | 
						|
                        IGeometry geo = topo.Buffer(10); | 
						|
                        ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, geo.Envelope); | 
						|
                    } | 
						|
                } | 
						|
            } | 
						|
        } | 
						|
 | 
						|
        public void Dissvoe() | 
						|
        { | 
						|
            if (this.Line != null) | 
						|
            { | 
						|
                Marshal.FinalReleaseComObject(this.Line); | 
						|
                this.Line = null; | 
						|
            } | 
						|
            if (this.FollowLine != null) | 
						|
            { | 
						|
                Marshal.FinalReleaseComObject(this.FollowLine); | 
						|
                this.FollowLine = null; | 
						|
            } | 
						|
            //this.Line = new Polyline(); | 
						|
            //this.FollowLine = new Polyline(); | 
						|
            this.DrawLine(); | 
						|
            //if (LineElement != null) | 
						|
            //{ | 
						|
            //    ActiveView.GraphicsContainer.DeleteElement(this.LineElement); | 
						|
            //    LineElement = null; | 
						|
            //} | 
						|
            //if (FollowLineElement != null) | 
						|
            //{ | 
						|
            //    ActiveView.GraphicsContainer.DeleteElement(this.FollowLineElement); | 
						|
            //    FollowLineElement = null; | 
						|
            //} | 
						|
            ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, ActiveView.Extent); | 
						|
        } | 
						|
 | 
						|
        public void Reset() | 
						|
        { | 
						|
            this.Dissvoe(); | 
						|
            this.Init(); | 
						|
        } | 
						|
 | 
						|
    } | 
						|
 | 
						|
}
 | 
						|
 |