画线
List<ESRI.ArcGIS.Geometry.IPoint> linePoints = new List<ESRI.ArcGIS.Geometry.IPoint>();
for (int i = 0; i < rayList.Count; i++)
{
// GeometryUtilities定义见下文
p = GeometryUtilities.ConstructPoint3D(list[i].X, list[i].Y, list[i].Z); // list里存自己定义的类
linePoints.Add(p);
}
// GISMapApplication定义见下文
IGraphicsLayer pGraphicsLayer = (GISMapApplication.Instance.Scene as IBasicMap).BasicGraphicsLayer;
// DrawUtilities定义见下文
DrawUtilities.DrawLine(pGraphicsLayer as IGraphicsContainer3D, linePoints);
GeometryUtilities部分代码
public static class GeometryUtilities
{
private static object _missing = Type.Missing;
public static void MakeZAware(IGeometry geometry)
{
IZAware zAware = geometry as IZAware;
zAware.ZAware = true;
}
public static IPoint ConstructPoint3D(double x, double y, double z)
{
IPoint point = ConstructPoint2D(x, y);
point.Z = z;
MakeZAware(point as IGeometry);
return point;
}
public static IPoint ConstructPoint2D(double x, double y)
{
IPoint point = new PointClass();
point.X = x;
point.Y = y;
return point;
}
}
GISMapApplication部分代码
public class GISMapApplication
{
#region 私有字段
private static GISMapApplication instance = null; //当前对象的实例
private AxSceneControl m_axSceneControl = null;
public AxSceneControl AxSceneControl
{
get { return m_axSceneControl; }
set { m_axSceneControl = value; }
}
private ISceneControl m_sceneControl = null;
private ISceneGraph m_SceneGraph = null;
private static System.Object m_syncObject = new System.Object(); // 同步对象
#endregion 私有字段
/// <summary>
/// 地图控件的引用
/// </summary>
public ISceneControl SceneControl
{
get { return m_sceneControl; }
set { m_sceneControl = value; }
}
/// <summary>
/// 图形接口
/// </summary>
public ISceneGraph SceneGraph
{
get { return m_SceneGraph; }
}
private IScene m_Scene = null;
/// <summary>
/// 场景
/// </summary>
public IScene Scene
{
get { return m_Scene; }
set { m_Scene = value; }
}
/// <summary>
/// 当前实例对象(单例模式)
/// </summary>
public static GISMapApplication Instance
{
get
{
if (instance == null)
{
lock (m_syncObject)
{
if (instance == null)
{
instance = new GISMapApplication();
}
}
}
return instance;
}
}
/// <summary>
/// 初始化的一些方法
/// </summary>
public void Init(AxSceneControl axSceneControl)
{
if (axSceneControl != null)
{
this.m_axSceneControl = axSceneControl;
m_sceneControl = axSceneControl.Object as ISceneControl;
m_SceneGraph = m_sceneControl.SceneGraph;
m_Scene = m_sceneControl.Scene;
}
}
}
DrawUtilities部分代码
public static class DrawUtilities
{
private static object _missing = Type.Missing;
public static void DrawLine(IGraphicsContainer3D lineGraphicsContainer3D, List<IPoint> listPoints)
{
IPointCollection linePointColl = new PolylineClass();
foreach (var point in listPoints)
{
linePointColl.AddPoint(point, ref _missing, ref _missing);
}
DrawUtilities.DrawLine(lineGraphicsContainer3D, linePointColl);
}
public static void DrawLine(IGraphicsContainer3D lineGraphicsContainer3D, IPointCollection linePointCollection)
{
const esriSimple3DLineStyle lineStyle = esriSimple3DLineStyle.esriS3DLSTube;
const double lineWidth = 1;
IColor lineColor = ColorUtilities.GetColor(255, 0, 0);
GeometryUtilities.MakeZAware(linePointCollection as IGeometry);
// GraphicsLayer3DUtilities定义见下文
GraphicsLayer3DUtilities.AddLineToGraphicsLayer3D(lineGraphicsContainer3D, linePointCollection as IGeometry, lineColor, lineStyle, lineWidth);
}
}
GraphicsLayer3DUtilities部分代码
public static class GraphicsLayer3DUtilities
{
public static void AddLineToGraphicsLayer3D(IGraphicsContainer3D graphicsContainer3D, IGeometry geometry, IColor color, esriSimple3DLineStyle style, double width)
{
//ElementUtilities定义见下文
graphicsContainer3D.AddElement(ElementUtilities.ConstructPolylineElement(geometry, color, style, width));
}
}
ElementUtilities部分代码
public static class ElementUtilities
{
private const double HighResolution = 1;
private const esriUnits Units = esriUnits.esriUnknownUnits;
public static IElement ConstructPolylineElement(IGeometry geometry, IColor color, esriSimple3DLineStyle style, double width)
{
ISimpleLine3DSymbol simpleLine3DSymbol = new SimpleLine3DSymbolClass();
simpleLine3DSymbol.Style = style;
simpleLine3DSymbol.ResolutionQuality = HighResolution;
ILineSymbol lineSymbol = simpleLine3DSymbol as ILineSymbol;
lineSymbol.Color = color;
lineSymbol.Width = width;
ILine3DPlacement line3DPlacement = lineSymbol as ILine3DPlacement;
line3DPlacement.Units = Units;
ILineElement lineElement = new LineElementClass();
lineElement.Symbol = lineSymbol;
IElement element = lineElement as IElement;
element.Geometry = geometry;
return element;
}
}