Arcglobe中平行于opengl的方法

来源:互联网 发布:软件后端开发是什么 编辑:程序博客网 时间:2024/04/29 10:36

以下方法,不能在线程中调用。否则无效。。

例程:

create3Dlayer("addlayer");

createPoint( dLon,   dLat,  dAlt)


 

//创建简单的3D模型
      public ISimpleMarker3DSymbol Create3Dmarker()
      {
          IMarkerSymbol markerSymbol = new SimpleMarker3DSymbolClass();

          //Set the marker symbol's style and resolution.
          ((ISimpleMarker3DSymbol)markerSymbol).Style = esriSimple3DMarkerStyle.esriS3DMSSphere;
          ((ISimpleMarker3DSymbol)markerSymbol).ResolutionQuality = 1.0;

          //Set the symbol's size and color.
          markerSymbol.Size = 700;
          return (ISimpleMarker3DSymbol)markerSymbol;
      }

一、创建新图层

//创建3D显示层
public void create3Dlayer(string layername)
{
    m_globeGraphicsLayer = new GlobeGraphicsLayerClass();
    ((ILayer)m_globeGraphicsLayer).Name = layername;

    IScene scene = (IScene)m_globeDisplay.Globe;

    //Add the new graphic layer to the globe.
    scene.AddLayer((ILayer)m_globeGraphicsLayer, false);

    //Activate the graphic layer.
    scene.ActiveGraphicsLayer = (ILayer)m_globeGraphicsLayer;

}

二、创建简单模型

/// <summary>
   /// 创建一个简单点
   /// </summary>
   /// <param name="dLon"></param>
   /// <param name="dLat"></param>
   /// <param name="dAlt"></param>
   private void createPoint(double dLon, double dLat, double dAlt)
   {
       IPoint point = new PointClass();
       IZAware zAware = point as IZAware;
       zAware.ZAware = true;
       point.PutCoords(dLon, dLat);
       point.Z = dAlt;

       //Create the element’s color (red).
       IRgbColor color = new RgbColorClass();
       color.Red = 255;
       color.Green = 0;
       color.Blue = 0;

       //Create the element’s symbol.
       IMarkerSymbol markerSymbol =(IMarkerSymbol) Create3Dmarker();
       markerSymbol.Color = color as IColor;

       //Create the new marker symbol’s element.
       IElement trackElement = new MarkerElementClass();

       //Set the element's symbol and geometry (location and shape).
       ((IMarkerElement)trackElement).Symbol = markerSymbol;
       trackElement.Geometry = point as IPoint;

       //Add the element to the graphic layer.
       ((IGraphicsContainer)m_globeGraphicsLayer).AddElement(trackElement, 0);

   }

三、增加三维模型

/// <summary>
///  增加3D模型
/// </summary>
/// <param name="dLon">经度</param>
/// <param name="dLat">维度</param>
/// <param name="dAlt">高程</param>
/// <param name="path">3D路径</param>
/// <returns></returns>
public int AddTrackElement(double dLon, double dLat, double dAlt, string path)
{
     if (null == m_globeGraphicsLayer)
         return -1;

     //create a new point at the given position
     IPoint point = new PointClass();
     ((IZAware)point).ZAware = true;
     point.X = dLon;
     point.Y = dLat;
     point.Z = dAlt;

     //set the color for the element (red)
     IRgbColor color = new RgbColorClass();
     color.Red = 255;
     color.Green = 0;
     color.Blue = 0;

     //create a new 3D marker symbol
     IMarkerSymbol markerSymbol = new SimpleMarker3DSymbolClass();

     //Define a new Marker3DSymbol
     IMarker3DSymbol pMarkerSym;
     pMarkerSym = new Marker3DSymbolClass();
     pMarkerSym.CreateFromFile(path);

     pMarkerSym.UseMaterialDraping = true;
     IMarkerPlacement pMarker3DPlace;
     pMarker3DPlace = pMarkerSym as IMarkerPlacement;
     //set the marker symbol's style and resolution
     IMarkerSymbol pMarkerSymbol = pMarkerSym as IMarkerSymbol;
     pMarkerSymbol.Size = 70;
     // pMarkerSymbol.Color = color as IColor;
     pMarkerSymbol.Angle = 90;

     ((ISimpleMarker3DSymbol)markerSymbol).Style = esriSimple3DMarkerStyle.esriS3DMSSphere;
     ((ISimpleMarker3DSymbol)markerSymbol).ResolutionQuality = 1.0;

     //set the symbol's size and color
     markerSymbol.Size = 700;
     // markerSymbol.Color = color as IColor;

     //crate the graphic element
     IElement trackElement = new MarkerElementClass();

     //set the elemet's symbol and geometry (location and shape)
     ((IMarkerElement)trackElement).Symbol = pMarkerSym as IMarkerSymbol;
     trackElement.Geometry = point as IPoint;

     //add the element to the graphics layer
     int elemIndex = 0;
     ((IGraphicsContainer)m_globeGraphicsLayer).AddElement(trackElement, 0);

     //get the elemet's index
     m_globeGraphicsLayer.FindElementIndex(trackElement, out elemIndex);
     return elemIndex;
}

 

四、更新元素

//更新3D层中某个图元
  public void updateLayer(int m_trackObjectIndex,double dx,double dy,double dz)
  {
      //Get the element by its index.

     // ILayer layer = null;
     // layer.
      IElement elem = ((IGraphicsContainer3D)m_globeGraphicsLayer).get_Element(m_trackObjectIndex);

      //Get the geometry of the element.
      IPoint point = elem.Geometry as IPoint;

      double surfaceElevation;
      m_globeDisplay.GetSurfaceElevation(point.X, point.Y, true, out surfaceElevation);

      //Update the element's position.
      point.PutCoords(point.X + dx, point.Y+dy);
      point.Z = surfaceElevation;//point.Z+dz;
      elem.Geometry = (IGeometry)point;
      //Update the element in the graphic layer.
      m_globeGraphicsLayer.UpdateElementByIndex(m_trackObjectIndex);
  }

原创粉丝点击