ArcGlobe开发中常用代码
ArcGlobe的强大与魅力深深地吸引着许多3DGIS初学者和开发者,现总结部分常用代码,贴出来以备大家参考,不妥之处请各位指正,
1.向ArcGlobe控件中通过类型来添加图层
public void
AddGlobeLayerByType(ESRI.ArcGIS.GlobeCore.IGlobe
globe,
ESRI.ArcGIS.GlobeCore.esriGlobeLayerType globeLayerType,
ESRI.ArcGIS.Carto.ILayer layer)
{
if (globe == null)
return;
if (globeLayerType
==
ESRI.ArcGIS.GlobeCore.esriGlobeLayerType.esriGlobeLayerTypeElevation)
{
if (layer is ESRI.ArcGIS.Carto.IRasterLayer
||
layer is ESRI.ArcGIS.Carto.ITinLayer ||
layer is ESRI.ArcGIS.Carto.ITerrainLayer)
{
globe.AddLayerType(layer, globeLayerType, true);
}
return;
}
// else if
GlobeLayerType is esriGlobeLayerTypeDraped
or
esriGlobeLayerTypeFloating
globe.AddLayerType(layer,
globeLayerType, true);
}
2.向ArcGlobe中添加Graphics
Layer
public void AddNewGraphicsLayer(ESRI.ArcGIS.GlobeCore.IGlobe globe,
System.String
graphicsLayerName)
{
//
创建graphics layer 并添加到 ArcGlobe
ESRI.ArcGIS.Carto.IGraphicsContainer globeGraphicsLayer =
new
ESRI.ArcGIS.GlobeCore.GlobeGraphicsLayerClass();
ESRI.ArcGIS.Carto.ILayer layer = (ESRI.ArcGIS.Carto.ILayer)globeGraphicsLayer;
layer.Name = graphicsLayerName;
ESRI.ArcGIS.Analyst3D.IScene scene = globe as ESRI.ArcGIS.Analyst3D.IScene;
scene.AddLayer(layer, true);
// 向graphics layer添加点元素
ESRI.ArcGIS.Carto.IElement
markerElement = new
ESRI.ArcGIS.Carto.MarkerElementClass();
ESRI.ArcGIS.Analyst3D.ISimpleMarker3DSymbol simpleMarker3DSymbol =
new
ESRI.ArcGIS.Analyst3D.SimpleMarker3DSymbolClass();
simpleMarker3DSymbol.Style
=
ESRI.ArcGIS.Analyst3D.esriSimple3DMarkerStyle.esriS3DMSCone;
// 设置相关属性
simpleMarker3DSymbol.ResolutionQuality =
1;
ESRI.ArcGIS.Display.IColor rgbColor = new
ESRI.ArcGIS.Display.RgbColorClass();
rgbColor.RGB = 255;
ESRI.ArcGIS.Display.IMarkerSymbol markerSymbol
=
(ESRI.ArcGIS.Display.IMarkerSymbol)simpleMarker3DSymbol;
markerSymbol.Color =
rgbColor;
markerSymbol.Size =
100000;
ESRI.ArcGIS.Geometry.IPoint point =
new ESRI.ArcGIS.Geometry.PointClass();
point.PutCoords(-47,
44);
markerElement.Geometry = point;
// 添加到
graphics layer
ESRI.ArcGIS.Carto.IMarkerElement markerElement_2
=
(ESRI.ArcGIS.Carto.IMarkerElement)markerElement;
markerElement_2.Symbol = markerSymbol;
globeGraphicsLayer.AddElement(markerElement, 1);
//
向graphics layer添加线元素
ESRI.ArcGIS.Carto.IElement lineElement =
new
ESRI.ArcGIS.Carto.LineElementClass();
ESRI.ArcGIS.Analyst3D.ISimpleLine3DSymbol simpleLineSymbol3D =
new
ESRI.ArcGIS.Analyst3D.SimpleLine3DSymbolClass();
simpleLineSymbol3D.Style
=
ESRI.ArcGIS.Analyst3D.esriSimple3DLineStyle.esriS3DLSStrip;
//设置颜色和大小
simpleLineSymbol3D.ResolutionQuality = 1;
rgbColor.RGB = 255000;
ESRI.ArcGIS.Display.ILineSymbol lineSymbol =
(ESRI.ArcGIS.Display.ILineSymbol)
simpleLineSymbol3D;
lineSymbol.Color = rgbColor;
lineSymbol.Width = 2;
// 设置geometry
ESRI.ArcGIS.Geometry.IPolyline polyline =
new
ESRI.ArcGIS.Geometry.PolylineClass();
ESRI.ArcGIS.Geometry.IPoint fromPoint = new
ESRI.ArcGIS.Geometry.PointClass();
fromPoint.PutCoords(-30,
44);
polyline.FromPoint = fromPoint;
ESRI.ArcGIS.Geometry.IPoint toPoint = new
ESRI.ArcGIS.Geometry.PointClass();
toPoint.PutCoords(-60,
44);
polyline.ToPoint = toPoint;
lineElement.Geometry = polyline;
// 添加到 graphics layer
ESRI.ArcGIS.Carto.ILineElement lineElement_2
=
(ESRI.ArcGIS.Carto.ILineElement)lineElement;
lineElement_2.Symbol = lineSymbol;
globeGraphicsLayer.AddElement(lineElement, 1);
}
3.向ArcGlobe添加 KML 数据
public void AddKMLData(System.String theKmlFile,
ESRI.ArcGIS.GlobeCore.IGlobe globe,
System.String kmlLayerName)
{
Type kmlType =
Type.GetTypeFromProgID("esriGlobeCore.KmlLayer");
ESRI.ArcGIS.GlobeCore.IKmlLayer kmlLayer =
(ESRI.ArcGIS.GlobeCore.IKmlLayer)
System.Activator.CreateInstance(kmlType);
kmlLayer.DataPath = theKmlFile;
kmlLayer.Name =
kmlLayerName;
ESRI.ArcGIS.Analyst3D.IScene scene = globe as
ESRI.ArcGIS.Analyst3D.IScene;
scene.AddLayer(kmlLayer as
ESRI.ArcGIS.Carto.ILayer, true);
}
4.向ArcGlobe中添加矢量数据
public void AddVectorData(ESRI.ArcGIS.GlobeCore.IGlobe
globe,
ESRI.ArcGIS.GlobeCore.esriGlobeLayerType globeLayerType,
ESRI.ArcGIS.Carto.ILayer layer)
{
if (globe == null ||
layer == null ||
globeLayerType
==
ESRI.ArcGIS.GlobeCore.esriGlobeLayerType.esriGlobeLayerTypeElevation
||
globeLayerType
==
ESRI.ArcGIS.GlobeCore.esriGlobeLayerType.esriGlobeLayerTypeUnknown)
{
return;
}
ESRI.ArcGIS.GlobeCore.IGlobeDisplay globeDisplay = globe.GlobeDisplay;
ESRI.ArcGIS.GlobeCore.IGlobeDisplay2 globeDisplay2 = globeDisplay
as
ESRI.ArcGIS.GlobeCore.IGlobeDisplay2;
globeDisplay2.PauseCaching = true;
globe.AddLayerType(layer,
globeLayerType, true);
ESRI.ArcGIS.GlobeCore.IGlobeDisplayLayers
globeDisplayLayers = globeDisplay
as
ESRI.ArcGIS.GlobeCore.IGlobeDisplayLayers;
ESRI.ArcGIS.GlobeCore.IGlobeLayerProperties globeLayerProperties
=
globeDisplayLayers.FindGlobeProperties(layer);
globeLayerProperties.IsDynamicallyRasterized = false;
globeDisplay2.PauseCaching = false;
}
经过几天的忙碌,又除去了网站程序中的一些Bug
,现在总结出ArcEngine三维开发控件ArcGlobe的一些常用代码,张贴出来以飨大家,其中疏漏之处,恳请指正!
1.按照适当的顺序绘制ArcGlobe图层
public
void GetSetGlobeDrawingOrder(ESRI.ArcGIS.GlobeCore.IGlobe globe)
{
ESRI.ArcGIS.GlobeCore.IGlobeDisplay globeDisplay =
globe.GlobeDisplay;
ESRI.ArcGIS.GlobeCore.IGlobeDrawingOrder
globeDrawingOrder =
(ESRI.ArcGIS.GlobeCore.IGlobeDrawingOrder)globe;
ESRI.ArcGIS.Carto.IEnumLayer
enumLayer = globeDrawingOrder.OrderedLayers;
ESRI.ArcGIS.Carto.IEnumLayer
baseLayers = globe.get_GlobeLayers(null, true, true,
true);
ESRI.ArcGIS.Carto.IEnumLayer floatingLayers =
globe.get_GlobeLayers(null, false, false,
true);
ESRI.ArcGIS.GlobeCore.IGlobeLayerProperties
globeLayerProperties;
ESRI.ArcGIS.GlobeCore.IGlobeDisplayLayers
globeDisplayLayers =
(ESRI.ArcGIS.GlobeCore.IGlobeDisplayLayers)globeDisplay;
System.Collections.ArrayList
DrapedLayers = new
System.Collections.ArrayList();
System.Collections.ArrayList ElevationLayers
= new System.Collections.ArrayList();
ESRI.ArcGIS.Carto.ILayer layer =
baseLayers.Next();
while (layer != null)
{
globeLayerProperties = globeDisplayLayers.FindGlobeProperties(layer);
if (globeLayerProperties.Type !=
ESRI.ArcGIS.GlobeCore.esriGlobeDataType.esriGlobeDataElevation)
{
DrapedLayers.Add(layer);
}
else if (globeLayerProperties.Type ==
ESRI.ArcGIS.GlobeCore.esriGlobeDataType.esriGlobeDataElevation)
{
ElevationLayers.Add(layer);
}
//获得下一层
layer = baseLayers.Next();
}
ESRI.ArcGIS.Carto.ILayer theDrapedLayer =
(ESRI.ArcGIS.Carto.ILayer)DrapedLayers[0];
globeDrawingOrder.MoveBackward(theDrapedLayer);
globeDisplay.RefreshViewers();
//获得浮动图层
ESRI.ArcGIS.Carto.ILayer theFloatingLayer = floatingLayers.Next();
while (theFloatingLayer != null)
{
theFloatingLayer = floatingLayers.Next();
}
}
2.获得BasicMap
public ESRI.ArcGIS.Carto.IBasicMap
GetBasicMapFromGlobe(ESRI.ArcGIS.GlobeCore.IGlobe globe)
{
ESRI.ArcGIS.Carto.IBasicMap basicMap = globe as
ESRI.ArcGIS.Carto.IBasicMap;
return basicMap;
}
3.获得Geographic 坐标
public ESRI.ArcGIS.Geometry.IPoint
GetGeographicCoordinates(System.Int32 xView, System.Int32 yView,
ESRI.ArcGIS.GlobeCore.IGlobeDisplay globeDisplay)
{
ESRI.ArcGIS.Geometry.IPoint point;
object ppOwner;
object ppObject;
globeDisplay.Locate(globeDisplay.ActiveViewer,
xView, yView, false, true, out point, out ppOwner, out ppObject);
return point;
}
4.设置Globe Layer 属性
public void
SetGlobeLayerProperties1(ESRI.ArcGIS.GlobeCore.IGlobeDisplay globeDisplay,
ESRI.ArcGIS.Carto.ILayer layer)
{
ESRI.ArcGIS.GlobeCore.IGlobeDisplayLayers globeDisplayLayers = globeDisplay as
ESRI.ArcGIS.GlobeCore.IGlobeDisplayLayers;
ESRI.ArcGIS.GlobeCore.IGlobeLayerProperties globeLayerProps =
globeDisplayLayers.FindGlobeProperties(layer);
globeLayerProps.Use16ColorBits = true;
globeDisplayLayers.RefreshLayer(layer);
}