代码里有,自己找
using SM.FM_PD.DataConversion;
using SuperMap.Data;
using SuperMap.UI;
using System;
using System.Drawing;
using SM.FM_PD.Database.ConfigManage;
namespace SM.FM_PD.PipeLine.DataQuery
{
public enum DrawType
{
CreatePoint = 106,
CreateLine = 107,
CreatePolyline = 108,
CreatePolygon = 109,
CreateRectangle = 110,
CreateCircle = 111
}
public class SceneDrawHelper
{
private SceneControl m_SceneControl;
private DrawType m_DrawType;
private PrjCoordSys m_DestPrjCoordSys;
private bool m_Once;
private GeoStyle3D m_GeoStyle3D;
public Geometry3D Geometry3D;
/// <summary>
/// 场景绘制帮助对象
/// </summary>
/// <param name="sceneControl">场景控件</param>
/// <param name="drawType">绘制对象类型</param>
/// <param name="once"></param>
public SceneDrawHelper(SceneControl sceneControl, DrawType drawType, PrjCoordSys destPrj, bool once = true)
{
m_SceneControl = sceneControl;
m_DrawType = drawType;
m_DestPrjCoordSys = destPrj;
m_Once = once;
m_GeoStyle3D = new GeoStyle3D()
{
AltitudeMode = AltitudeMode.Absolute,
FillMode = FillMode3D.LineAndFill,
FillForeColor = Color.LightGray,//灰色
LineColor = Color.FromArgb(255, 255, 255, 00),//黄色
LineWidth = 2.5,
MarkerColor = Color.Red,
MarkerSize = 5,
};
CORE_CF_STYLES model3D = BLLCommonHelper.GetOrCreateStyle("场景绘制对象风格", StyleType.GeoStyle3D, m_GeoStyle3D.ToXML());
if (model3D == null)
return;
m_GeoStyle3D.FromXML(model3D.STYLEXML);//加载成功就用库里的,加载失败就用系统默认的
loadEvent();
}
#region 默认绘制:绘制点、直线、折线、多边形、矩形、圆形
private void loadEvent()
{
if (m_DrawType == DrawType.CreateCircle)
m_SceneControl.Action = Action3D.CreateLine;
else
m_SceneControl.Action = (Action3D)Enum.Parse(typeof(Action3D), m_DrawType.ToString());
m_SceneControl.IsCursorCustomized = true;
m_SceneControl.Cursor = System.Windows.Forms.Cursors.Cross;
if (m_SceneControl.Action == Action3D.CreatePoint)
{
m_SceneControl.Tracking -= SceneControl_Tracking;
m_SceneControl.Tracking += SceneControl_Tracking;
}
else
{
m_SceneControl.Tracking -= SceneControl_Tracking;
m_SceneControl.Tracking += SceneControl_Tracking;
m_SceneControl.Tracked -= SceneControl_Tracked;
m_SceneControl.Tracked += SceneControl_Tracked;
}
}
private void SceneControl_Tracking(object sender, Tracking3DEventArgs e)
{
Geometry3D geo = e.Geometry;
if (geo == null)
return;
if (geo is GeoPoint3D)
{
Geometry3D = geo;
geo.Style3D = m_GeoStyle3D;
m_SceneControl.Scene.TrackingLayer.Add(geo, "111");
if (m_Once)
{
StopDrawing();
}
}
else if (geo is GeoLine3D && m_DrawType == DrawType.CreateCircle)
{
GeoLine3D geoLine3D = geo as GeoLine3D;
GeoLine geoLine = GeometryConvert.ConvertToGeoLine(geoLine3D);
geoLine = PrjCoordSysHelper.Convert(geoLine, new PrjCoordSys(PrjCoordSysType.EarthLongitudeLatitude), m_DestPrjCoordSys, new CoordSysTransParameter(), CoordSysTransMethod.CoordinateFrame);
if (geoLine.Length > 0)
{
GeoCircle3D geoCircle = new GeoCircle3D(geoLine3D[0][0], geoLine.Length);
if (geoCircle != null)
{
//GeoRegion3D region3D = GeometryConvert.ConvertCircle3DToRegion3D(geoCircle);
//region3D.Style3D = m_GeoStyle3D;
geoCircle.Style3D = m_GeoStyle3D;
SuperMapSceneHelper.RemoveTrackingLayerByTag(m_SceneControl, "circle");
m_SceneControl.Scene.TrackingLayer.Add(geoCircle, "circle");
}
}
}
}
private void SceneControl_Tracked(object sender, Tracked3DEventArgs e)
{
Geometry3D geo = e.Geometry;
if (geo == null)
return;
if (geo is GeoLine3D && m_DrawType == DrawType.CreateCircle)
{
GeoLine3D geoLine3D = geo as GeoLine3D;
GeoLine geoLine = GeometryConvert.ConvertToGeoLine(geoLine3D);
geoLine = PrjCoordSysHelper.Convert(geoLine, new PrjCoordSys(PrjCoordSysType.EarthLongitudeLatitude), m_DestPrjCoordSys, new CoordSysTransParameter(), CoordSysTransMethod.CoordinateFrame);
if (geoLine.Length > 0)
{
GeoCircle3D geoCircle = new GeoCircle3D(geoLine3D[0][0], geoLine.Length);
if (geoCircle != null)
{
//GeoRegion3D region3D = GeometryConvert.ConvertCircle3DToRegion3D(geoCircle);
//region3D.Style3D = m_GeoStyle3D;
geoCircle.Style3D = m_GeoStyle3D;
SuperMapSceneHelper.RemoveTrackingLayerByTag(m_SceneControl, "circle");
m_SceneControl.Scene.TrackingLayer.Add(geoCircle, "circle");
}
}
}
else if (geo.Type != GeometryType.GeoPoint3D)
{
Geometry3D = geo;
geo.Style3D = m_GeoStyle3D;
m_SceneControl.Scene.TrackingLayer.Add(geo, "111");
}
if (m_Once)
{
StopDrawing();
}
}
#endregion
public void StopDrawing()
{
m_SceneControl.Tracking -= SceneControl_Tracking;
m_SceneControl.Tracked -= SceneControl_Tracked;
m_SceneControl.IsCursorCustomized = false;
m_SceneControl.Action = Action3D.Pan;
}
}
}