/// <summary>
        /// Form Load event handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainForm_Load(object sender, EventArgs e)
        {
            m_globeControl = axGlobeControl1.Object as IGlobeControl;

            //cast the GlobeViewUtil from the GlobeCamera
            m_globeViewUtil = m_globeControl.GlobeCamera as IGlobeViewUtil;
        }
        /// <summary>
        /// Occurs when this command is created
        /// </summary>
        /// <param name="hook">Instance of the application</param>
        public override void OnCreate(object hook)
        {
            //Instantiate the hook helper
            if (null == m_globeHookHelper)
            {
                m_globeHookHelper = new GlobeHookHelperClass();
            }

            //set the hook
            m_globeHookHelper.Hook = hook;

            //get the relevant members
            IGlobe globe = m_globeHookHelper.Globe;

            m_scene         = globe as IScene;
            m_globeDsp      = m_globeHookHelper.GlobeDisplay;
            m_globeViewUtil = m_globeHookHelper.Camera as IGlobeViewUtil;

            //connect to the ZipCodes featureclass
            //get the ArcGIS path from the registry
            String      versionNumber = RuntimeManager.ActiveRuntime.Version;
            RegistryKey key           = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\ESRI\ArcObjectsSdk" + versionNumber);
            string      path          = Convert.ToString(key.GetValue("InstallDir"));

            path = System.IO.Path.Combine(path, @"Samples\data\USZipCodeData");

            IWorkspaceFactory wf = new ShapefileWorkspaceFactoryClass() as IWorkspaceFactory;
            IWorkspace        ws = wf.OpenFromFile(path, 0);
            IFeatureWorkspace fw = ws as IFeatureWorkspace;

            m_featureClass = fw.OpenFeatureClass("US_ZipCodes");
        }
        /// <summary>
        /// Occurs when this command is created
        /// </summary>
        /// <param name="hook">Instance of the application</param>
        public override void OnCreate(object hook)
        {
            //Instantiate the hook helper
            if (null == m_globeHookHelper)
            {
                m_globeHookHelper = new GlobeHookHelperClass();
            }

            //set the hook
            m_globeHookHelper.Hook = hook;

            //get the relevant members
            IGlobe globe = m_globeHookHelper.Globe;

            m_scene         = globe as IScene;
            m_globeDsp      = m_globeHookHelper.GlobeDisplay;
            m_globeViewUtil = m_globeHookHelper.Camera as IGlobeViewUtil;

            //connect to the ZipCodes featureclass
            string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            path = System.IO.Path.Combine(path, @"ArcGIS\data\USZipCodeData");
            if (!Directory.Exists(path))
            {
                throw new Exception(string.Format("Fix code to point to your sample data: {0} was not found", path));
            }

            IWorkspaceFactory wf = new ShapefileWorkspaceFactoryClass() as IWorkspaceFactory;
            IWorkspace        ws = wf.OpenFromFile(path, 0);
            IFeatureWorkspace fw = ws as IFeatureWorkspace;

            m_featureClass = fw.OpenFeatureClass("US_ZipCodes");
        }
Exemple #4
0
        private void globeControl_OnMouseMove(object sender, IGlobeControlEvents_OnMouseMoveEvent e)
        {
            //get scale range in Kilometers
            IGlobeViewUtil globeCamera  = globeControl.GlobeCamera as IGlobeViewUtil;
            double         distanceInKM = globeCamera.ScalingDistance / 1000;

            Coordinates.Text = string.Format("{0} {1} {2}", "Distance: ", distanceInKM.ToString("######.##"), globeControl.Globe.GlobeUnits.ToString().Substring(4));
        }
Exemple #5
0
        /// <summary>
        /// 地理坐标转化为屏幕坐标
        /// </summary>
        /// <param name="lon">经度</param>
        /// <param name="lat">纬度</param>
        /// <param name="alt">高度</param>
        /// <returns></returns>
        public System.Drawing.Point GeographyToScenePoint(double lon, double lat, double alt = 0)
        {
            int            x, y;
            IGlobeViewUtil globeViewUtil = mapControl.GlobeCamera as IGlobeViewUtil;
            IGlobeDisplay  pGlobeDisplay = mapControl.GlobeDisplay;

            globeViewUtil.GeocentricToWindow(lon, lat, alt, out x, out y);
            System.Drawing.Point point = new System.Drawing.Point(x, y);
            return(point);
        }
Exemple #6
0
 public SunPositionTool()
 {
     //get the different members
     m_globe                 = ArcGlobe.Globe;
     m_globeDisplay          = m_globe.GlobeDisplay as IGlobeDisplay3;
     m_globeDisplayRendering = m_globeDisplay as IGlobeDisplayRendering;
     m_globeCamera           = m_globeDisplay.ActiveViewer.Camera as IGlobeCamera;
     m_globeViewUtil         = m_globeCamera as IGlobeViewUtil;
     m_sceneViewer           = m_globeDisplay.ActiveViewer;
 }
 public SunPositionTool()
 {
     //get the different members
     m_globe = ArcGlobe.Globe;
     m_globeDisplay = m_globe.GlobeDisplay as IGlobeDisplay3;
     m_globeDisplayRendering = m_globeDisplay as IGlobeDisplayRendering;
     m_globeCamera = m_globeDisplay.ActiveViewer.Camera as IGlobeCamera;
     m_globeViewUtil = m_globeCamera as IGlobeViewUtil;
     m_sceneViewer = m_globeDisplay.ActiveViewer;
 }
Exemple #8
0
        /// <summary>
        /// 屏幕坐标转地理坐标
        /// </summary>
        /// <param name="x">屏幕X</param>
        /// <param name="y">屏幕Y</param>
        /// <returns></returns>
        public MapLngLat SceneToGeographyPoint(int x, int y)
        {
            double         dLat, dLon, dAlt;
            IGlobeDisplay  pGlobeDisplay  = mapControl.GlobeDisplay;
            ISceneViewer   pViewer        = mapControl.GlobeDisplay.ActiveViewer;
            IGlobeViewUtil pGlobeViewUtil = mapControl.GlobeCamera as IGlobeViewUtil;

            pGlobeViewUtil.WindowToGeographic(pGlobeDisplay, pViewer, x, y, true, out dLon, out dLat, out dAlt);
            Core.Model.MapLngLat lnglat = new Core.Model.MapLngLat(dLon, dLat, dAlt);
            return(lnglat);
        }
Exemple #9
0
        private void GetGeographicCoordinates(IGlobe globe, int screenX, int screenY, ref double longitude, ref double latitude, ref double altitudeInKilometers)
        {
            IGlobeDisplay globeDisplay = globe.GlobeDisplay;

            ISceneViewer sceneViewer = globeDisplay.ActiveViewer;

            ICamera camera = globeDisplay.ActiveViewer.Camera;

            IGlobeViewUtil globeViewUtil = camera as IGlobeViewUtil;

            globeViewUtil.WindowToGeographic(globeDisplay, sceneViewer, screenX, screenY, true, out longitude, out latitude, out altitudeInKilometers);
        }
Exemple #10
0
        private void Form1_Load(object sender, EventArgs e)
        {
            m_Globe         = axGlobeControl1.Globe;
            m_GlobeDisplay  = m_Globe.GlobeDisplay;
            m_SceneView     = m_GlobeDisplay.ActiveViewer;
            m_GlobeViewUtil = axGlobeControl1.GlobeCamera as IGlobeViewUtil;

            IGlobeDisplayEvents_Event m_GlobeDisplayEvents = axGlobeControl1.Globe.GlobeDisplay as IGlobeDisplayEvents_Event;

            //将三维视图重绘事件委托给m_GlobeDisplayEvents_AfterDraw方法
            m_GlobeDisplayEvents.AfterDraw += new IGlobeDisplayEvents_AfterDrawEventHandler(m_GlobeDisplayEvents_AfterDraw);

            axMapControl1.Extent    = axMapControl1.FullExtent;
            comboBox1.SelectedIndex = 0;
        }
Exemple #11
0
        //获得三维视图的显示范围,并在二维地图上显示
        private void GlobeControl_DisplayEvents_AfterDraw(ISceneViewer pViewer)
        {
            IEnvelope      m_MapExtent     = new EnvelopeClass();
            IGlobeViewUtil m_GlobeViewUtil = axGlobeControl1.GlobeCamera as IGlobeViewUtil;

            m_GlobeViewUtil.QueryVisibleGeographicExtent(m_MapExtent);
            IGraphicsContainer pGra = axMapControl1.Map as IGraphicsContainer;
            IActiveView        pAv  = pGra as IActiveView;

            pGra.DeleteAllElements();

            IRectangleElement rec = new RectangleElementClass();
            IElement          ele = rec as IElement;

            ele.Geometry = m_MapExtent;

            IRgbColor pColor = new RgbColorClass();

            pColor.Red   = 255;
            pColor.Green = 0;
            pColor.Blue  = 0;

            ILineSymbol line = new SimpleLineSymbolClass();

            line.Color = pColor;
            line.Width = 2;

            pColor              = new RgbColorClass();
            pColor.Red          = 255;
            pColor.Green        = 0;
            pColor.Blue         = 0;
            pColor.Transparency = 0;

            IFillSymbol fill = new SimpleFillSymbolClass();

            fill.Outline = line;
            fill.Color   = pColor;

            IFillShapeElement pFillElement = ele as IFillShapeElement;

            pFillElement.Symbol = fill;

            pGra.AddElement((IElement)pFillElement, 0);
            pAv.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
		/// <summary>
		/// Occurs when this command is created
		/// </summary>
		/// <param name="hook">Instance of the application</param>
		public override void OnCreate(object hook)
		{
      //Instantiate the hook helper
      if (null == m_globeHookHelper)
        m_globeHookHelper = new GlobeHookHelperClass();
      
      //set the hook
      m_globeHookHelper.Hook = hook;

      //get the relevant members
      IGlobe globe = m_globeHookHelper.Globe;
      m_scene = globe as IScene;
      m_globeDsp = m_globeHookHelper.GlobeDisplay;
			m_globeViewUtil = m_globeHookHelper.Camera as IGlobeViewUtil;

			//connect to the ZipCodes featureclass
      //get the ArcGIS path from the registry
      String versionNumber = RuntimeManager.ActiveRuntime.Version;
      RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\ESRI\ArcObjectsSdk" + versionNumber);
      string path = Convert.ToString(key.GetValue("InstallDir"));
      path = System.IO.Path.Combine(path, @"Samples\data\USZipCodeData");

			IWorkspaceFactory wf = new ShapefileWorkspaceFactoryClass() as IWorkspaceFactory;
      IWorkspace ws = wf.OpenFromFile(path, 0);
			IFeatureWorkspace fw = ws as IFeatureWorkspace;
			m_featureClass = fw.OpenFeatureClass("US_ZipCodes");
		}
    /// <summary>
    /// This is where the actual drawing takes place.
    /// </summary>
    /// <param name="pGlobeViewer"></param>
    public override void DrawImmediate(IGlobeViewer pGlobeViewer)
    {
      //make sure that the layer is valid, visible and that the main table exists 
      if (!m_bVisible || !m_bValid | null == m_table)
        return;

      
      //get the OpenGL rendering mode
      uint mode;
      unsafe
      {
        int m;
        GL.glGetIntegerv(GL.GL_RENDER_MODE, &m);
        mode = (uint)m;
          //GL.glGetIntegerv(GL.GL_RENDER_MODE, out mode);
        
      }

      //get the OpenGL matrices (required for the viewport filtering and the billboard orientation)
      GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, m_modelViewMatrix);
      GL.glGetIntegerv(GL.GL_VIEWPORT, m_viewport);
      GL.glGetDoublev(GL.GL_PROJECTION_MATRIX, m_projMatrix);

      //populate the billboard matrix
      m_billboardMatrix[0] = m_modelViewMatrix[0];
      m_billboardMatrix[1] = m_modelViewMatrix[4];
      m_billboardMatrix[2] = m_modelViewMatrix[8];
      m_billboardMatrix[3] = 0;

      m_billboardMatrix[4] = m_modelViewMatrix[1];
      m_billboardMatrix[5] = m_modelViewMatrix[5];
      m_billboardMatrix[6] = m_modelViewMatrix[9];
      m_billboardMatrix[7] = 0;

      m_billboardMatrix[8] = m_modelViewMatrix[2];
      m_billboardMatrix[9] = m_modelViewMatrix[6];
      m_billboardMatrix[10] = m_modelViewMatrix[10];
      m_billboardMatrix[11] = 0;

      m_billboardMatrix[12] = 0;
      m_billboardMatrix[13] = 0;
      m_billboardMatrix[14] = 0;
      m_billboardMatrix[15] = 1;

      ISceneViewer sceneViewer = pGlobeViewer.GlobeDisplay.ActiveViewer;

      //only once, create display lists and do initializations
      if (!m_bDisplayListCreated)
      {
        CreateDisplayLists();
        m_globeDisplay = pGlobeViewer.GlobeDisplay;
      }

      //get the globeViewUtil which allow to convert between the different globe coordinate systems
      m_globeViewUtil = sceneViewer.Camera as IGlobeViewUtil;
      IGlobeViewUtil globeViewUtil = sceneViewer.Camera as IGlobeViewUtil;
      IGlobeAdvancedOptions advOpt = m_globeDisplay.AdvancedOptions;

      //the ClipNear value is required for the viewport filtering (since we don't
      //want to draw an item which is beyond the clipping planes).
      double clipNear = advOpt.ClipNear;

      double dblObsX, dblObsY, dblObsZ, dMagnitude;
      ICamera camera = pGlobeViewer.GlobeDisplay.ActiveViewer.Camera;
      
      //query the camera location in geocentric coordinate (OpenGL coord system)
      camera.Observer.QueryCoords(out dblObsX, out dblObsY);
      dblObsZ = camera.Observer.Z;

      double lat, lon, X = 0.0, Y = 0.0, Z = 0.0;

      //iterate through all the records of the layer, test whether the item is within the 
      //viewport are and draw it onto the globe.
      foreach (DataRow rec in m_table.Rows)
      {

        lat = Convert.ToDouble(rec[3]);
        lon = Convert.ToDouble(rec[4]);
        X = Convert.ToDouble(rec[5]);
        Y = Convert.ToDouble(rec[6]);
        Z = Convert.ToDouble(rec[7]);

        #region get the OGL geocentric coordinates X,Y,Z
        if (X == 0.0 && Y == 0.0 && Z == 0.0)
        {
          //calculate the geocentric coordinates
          globeViewUtil.GeographicToGeocentric(lon, lat, 1000.0, out X, out Y, out Z);

          //write the calculated geocentric coordinate to the table
          lock (m_table)
          {
            rec[5] = X;
            rec[6] = Y;
            rec[7] = Z;
            rec.AcceptChanges();
          }
        }
        #endregion

        //make sure that the item is inside the viewport, otherwise no need to draw it
        if (!InsideViewport(X, Y, Z, clipNear, mode))
          continue;

        //get the distance from the camera to the drawn item.
        //This distance will determine whether to draw the item as a dot or as
        //a full icon.
        m_vector3D.SetComponents(dblObsX - X, dblObsY - Y, dblObsZ - Z);
        dMagnitude = m_vector3D.Magnitude;

        //call the drawing method
        DrawItem(rec, dMagnitude);
      }
    }