小秋的家

home

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  1 Posts :: 91 Stories :: 17 Comments :: 0 Trackbacks
/*
 Copyright 1995-2004 ESRI

 All rights reserved under the copyright laws of the United States.

 You may freely redistribute and use this sample code, with or without modification.

 Disclaimer: THE SAMPLE CODE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
 WARRANTIES, INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ESRI OR
 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
 OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 INTERRUPTION) SUSTAINED BY YOU OR A THIRD PARTY, HOWEVER CAUSED AND ON ANY
 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ARISING IN ANY
 WAY OUT OF THE USE OF THIS SAMPLE CODE, EVEN IF ADVISED OF THE POSSIBILITY OF
 SUCH DAMAGE.

 For additional information contact: Environmental Systems Research Institute, Inc.

 Attn: Contracts Dept.

 380 New York Street

 Redlands, California, U.S.A. 92373

 Email: contracts@esri.com
*/
using System;
using System.Windows.Forms;
using ESRI.ArcGIS.Analyst3D;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.GlobeCore;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.SystemUI;

namespace GlobeNavigation
{
 /// <summary>
 /// Summary description for Form1.
 /// </summary>
 public class Form1 : System.Windows.Forms.Form
 {
  private ESRI.ArcGIS.GlobeControl.AxGlobeControl axGlobeControl1;
  internal System.Windows.Forms.TrackBar TrackBar1;
  public System.Windows.Forms.CheckBox chkSpin;
  public System.Windows.Forms.RadioButton optTools1;
  public System.Windows.Forms.RadioButton optTools0;
  public System.Windows.Forms.Button cmdLoadDocument;
  public System.Windows.Forms.Button cmdZoomOut;
  public System.Windows.Forms.Button cmdZoomIn;
  public System.Windows.Forms.Button cmdFullExtent;
  public System.Windows.Forms.Label Label1;
  public System.Windows.Forms.Label lblNavigate;
  public System.Windows.Forms.Label lblZoom;
  public System.Windows.Forms.Label lblLoad;
  private System.Windows.Forms.OpenFileDialog openFileDialog1;
  
  private IAoInitialize m_AoInitialize = new AoInitializeClass();
  private ISceneViewer m_ActiveView;
  private ICamera m_Camera;
  private IPoint m_pMousePos = new PointClass();
  private bool m_bMouseDown;
  private bool m_bZooming = false;
  private double m_dSpinSpeed = 0;
  private double m_dZoom;
  
  const double cMinZoom = 1.00002;
  const double cMaxZoom = 1.1;
  const double cDistanceZoomLimit = 200.0;

  /// <summary>
  /// Required designer variable.
  /// </summary>
  private System.ComponentModel.Container components = null;

  public Form1()
  {
   //
   // Required for Windows Form Designer support
   //
   InitializeComponent();

   //
   // TODO: Add any constructor code after InitializeComponent call
   //
  }

  /// <summary>
  /// Clean up any resources being used.
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

  #region Windows Form Designer generated code
  /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>
  private void InitializeComponent()
  {
   System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
   this.axGlobeControl1 = new ESRI.ArcGIS.GlobeControl.AxGlobeControl();
   this.TrackBar1 = new System.Windows.Forms.TrackBar();
   this.chkSpin = new System.Windows.Forms.CheckBox();
   this.optTools1 = new System.Windows.Forms.RadioButton();
   this.optTools0 = new System.Windows.Forms.RadioButton();
   this.cmdLoadDocument = new System.Windows.Forms.Button();
   this.cmdZoomOut = new System.Windows.Forms.Button();
   this.cmdZoomIn = new System.Windows.Forms.Button();
   this.cmdFullExtent = new System.Windows.Forms.Button();
   this.Label1 = new System.Windows.Forms.Label();
   this.lblNavigate = new System.Windows.Forms.Label();
   this.lblZoom = new System.Windows.Forms.Label();
   this.lblLoad = new System.Windows.Forms.Label();
   this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
   ((System.ComponentModel.ISupportInitialize)(this.axGlobeControl1)).BeginInit();
   ((System.ComponentModel.ISupportInitialize)(this.TrackBar1)).BeginInit();
   this.SuspendLayout();
   //
   // axGlobeControl1
   //
   this.axGlobeControl1.Location = new System.Drawing.Point(10, 9);
   this.axGlobeControl1.Name = "axGlobeControl1";
   this.axGlobeControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axGlobeControl1.OcxState")));
   this.axGlobeControl1.Size = new System.Drawing.Size(508, 499);
   this.axGlobeControl1.TabIndex = 0;
   this.axGlobeControl1.OnMouseDown += new ESRI.ArcGIS.GlobeControl.IGlobeControlEvents_OnMouseDownEventHandler(this.axGlobeControl1_OnMouseDown);
   this.axGlobeControl1.OnMouseMove += new ESRI.ArcGIS.GlobeControl.IGlobeControlEvents_OnMouseMoveEventHandler(this.axGlobeControl1_OnMouseMove);
   this.axGlobeControl1.OnMouseUp += new ESRI.ArcGIS.GlobeControl.IGlobeControlEvents_OnMouseUpEventHandler(this.axGlobeControl1_OnMouseUp);
   //
   // TrackBar1
   //
   this.TrackBar1.Location = new System.Drawing.Point(528, 465);
   this.TrackBar1.Name = "TrackBar1";
   this.TrackBar1.Size = new System.Drawing.Size(125, 45);
   this.TrackBar1.TabIndex = 26;
   this.TrackBar1.Scroll += new System.EventHandler(this.TrackBar1_Scroll);
   //
   // chkSpin
   //
   this.chkSpin.BackColor = System.Drawing.SystemColors.Control;
   this.chkSpin.Cursor = System.Windows.Forms.Cursors.Default;
   this.chkSpin.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
   this.chkSpin.ForeColor = System.Drawing.SystemColors.ControlText;
   this.chkSpin.Location = new System.Drawing.Point(547, 439);
   this.chkSpin.Name = "chkSpin";
   this.chkSpin.RightToLeft = System.Windows.Forms.RightToLeft.No;
   this.chkSpin.Size = new System.Drawing.Size(69, 19);
   this.chkSpin.TabIndex = 25;
   this.chkSpin.Text = "Spin";
   this.chkSpin.Click += new System.EventHandler(this.chkSpin_Click);
   this.chkSpin.CheckedChanged += new System.EventHandler(this.chkSpin_CheckedChanged);
   //
   // optTools1
   //
   this.optTools1.Appearance = System.Windows.Forms.Appearance.Button;
   this.optTools1.BackColor = System.Drawing.SystemColors.Control;
   this.optTools1.Cursor = System.Windows.Forms.Cursors.Default;
   this.optTools1.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
   this.optTools1.ForeColor = System.Drawing.SystemColors.ControlText;
   this.optTools1.Location = new System.Drawing.Point(538, 353);
   this.optTools1.Name = "optTools1";
   this.optTools1.RightToLeft = System.Windows.Forms.RightToLeft.No;
   this.optTools1.Size = new System.Drawing.Size(97, 27);
   this.optTools1.TabIndex = 20;
   this.optTools1.TabStop = true;
   this.optTools1.Text = "Zoom In/Out";
   this.optTools1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
   this.optTools1.Click += new System.EventHandler(this.MixedControls_Click);
   //
   // optTools0
   //
   this.optTools0.Appearance = System.Windows.Forms.Appearance.Button;
   this.optTools0.BackColor = System.Drawing.SystemColors.Control;
   this.optTools0.Cursor = System.Windows.Forms.Cursors.Default;
   this.optTools0.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
   this.optTools0.ForeColor = System.Drawing.SystemColors.ControlText;
   this.optTools0.Location = new System.Drawing.Point(538, 310);
   this.optTools0.Name = "optTools0";
   this.optTools0.RightToLeft = System.Windows.Forms.RightToLeft.No;
   this.optTools0.Size = new System.Drawing.Size(97, 27);
   this.optTools0.TabIndex = 19;
   this.optTools0.TabStop = true;
   this.optTools0.Text = "Navigate";
   this.optTools0.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
   this.optTools0.Click += new System.EventHandler(this.MixedControls_Click);
   this.optTools0.CheckedChanged += new System.EventHandler(this.optTools0_CheckedChanged);
   //
   // cmdLoadDocument
   //
   this.cmdLoadDocument.BackColor = System.Drawing.SystemColors.Control;
   this.cmdLoadDocument.Cursor = System.Windows.Forms.Cursors.Default;
   this.cmdLoadDocument.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
   this.cmdLoadDocument.ForeColor = System.Drawing.SystemColors.ControlText;
   this.cmdLoadDocument.Location = new System.Drawing.Point(547, 52);
   this.cmdLoadDocument.Name = "cmdLoadDocument";
   this.cmdLoadDocument.RightToLeft = System.Windows.Forms.RightToLeft.No;
   this.cmdLoadDocument.Size = new System.Drawing.Size(81, 27);
   this.cmdLoadDocument.TabIndex = 18;
   this.cmdLoadDocument.Text = "Load ...";
   this.cmdLoadDocument.Click += new System.EventHandler(this.cmdLoadDocument_Click);
   //
   // cmdZoomOut
   //
   this.cmdZoomOut.BackColor = System.Drawing.SystemColors.Control;
   this.cmdZoomOut.Cursor = System.Windows.Forms.Cursors.Default;
   this.cmdZoomOut.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
   this.cmdZoomOut.ForeColor = System.Drawing.SystemColors.ControlText;
   this.cmdZoomOut.Location = new System.Drawing.Point(528, 181);
   this.cmdZoomOut.Name = "cmdZoomOut";
   this.cmdZoomOut.RightToLeft = System.Windows.Forms.RightToLeft.No;
   this.cmdZoomOut.Size = new System.Drawing.Size(119, 27);
   this.cmdZoomOut.TabIndex = 17;
   this.cmdZoomOut.Text = "Fixed Zoom Out";
   this.cmdZoomOut.Click += new System.EventHandler(this.cmdZoomOut_Click);
   //
   // cmdZoomIn
   //
   this.cmdZoomIn.BackColor = System.Drawing.SystemColors.Control;
   this.cmdZoomIn.Cursor = System.Windows.Forms.Cursors.Default;
   this.cmdZoomIn.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
   this.cmdZoomIn.ForeColor = System.Drawing.SystemColors.ControlText;
   this.cmdZoomIn.Location = new System.Drawing.Point(528, 146);
   this.cmdZoomIn.Name = "cmdZoomIn";
   this.cmdZoomIn.RightToLeft = System.Windows.Forms.RightToLeft.No;
   this.cmdZoomIn.Size = new System.Drawing.Size(119, 27);
   this.cmdZoomIn.TabIndex = 16;
   this.cmdZoomIn.Text = "Fixed Zoom In";
   this.cmdZoomIn.Click += new System.EventHandler(this.cmdZoomIn_Click);
   //
   // cmdFullExtent
   //
   this.cmdFullExtent.BackColor = System.Drawing.SystemColors.Control;
   this.cmdFullExtent.Cursor = System.Windows.Forms.Cursors.Default;
   this.cmdFullExtent.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
   this.cmdFullExtent.ForeColor = System.Drawing.SystemColors.ControlText;
   this.cmdFullExtent.Location = new System.Drawing.Point(528, 215);
   this.cmdFullExtent.Name = "cmdFullExtent";
   this.cmdFullExtent.RightToLeft = System.Windows.Forms.RightToLeft.No;
   this.cmdFullExtent.Size = new System.Drawing.Size(119, 27);
   this.cmdFullExtent.TabIndex = 15;
   this.cmdFullExtent.Text = "Full Extent";
   this.cmdFullExtent.Click += new System.EventHandler(this.cmdFullExtent_Click);
   //
   // Label1
   //
   this.Label1.BackColor = System.Drawing.SystemColors.Control;
   this.Label1.Cursor = System.Windows.Forms.Cursors.Default;
   this.Label1.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
   this.Label1.ForeColor = System.Drawing.SystemColors.Highlight;
   this.Label1.Location = new System.Drawing.Point(528, 388);
   this.Label1.Name = "Label1";
   this.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No;
   this.Label1.Size = new System.Drawing.Size(116, 52);
   this.Label1.TabIndex = 24;
   this.Label1.Text = "Control the spin speed with the slider.";
   //
   // lblNavigate
   //
   this.lblNavigate.BackColor = System.Drawing.SystemColors.Control;
   this.lblNavigate.Cursor = System.Windows.Forms.Cursors.Default;
   this.lblNavigate.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
   this.lblNavigate.ForeColor = System.Drawing.SystemColors.Highlight;
   this.lblNavigate.Location = new System.Drawing.Point(528, 250);
   this.lblNavigate.Name = "lblNavigate";
   this.lblNavigate.RightToLeft = System.Windows.Forms.RightToLeft.No;
   this.lblNavigate.Size = new System.Drawing.Size(126, 53);
   this.lblNavigate.TabIndex = 23;
   this.lblNavigate.Text = "Use the option buttons to select a navigation tool. ";
   //
   // lblZoom
   //
   this.lblZoom.BackColor = System.Drawing.SystemColors.Control;
   this.lblZoom.Cursor = System.Windows.Forms.Cursors.Default;
   this.lblZoom.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
   this.lblZoom.ForeColor = System.Drawing.SystemColors.Highlight;
   this.lblZoom.Location = new System.Drawing.Point(528, 86);
   this.lblZoom.Name = "lblZoom";
   this.lblZoom.RightToLeft = System.Windows.Forms.RightToLeft.No;
   this.lblZoom.Size = new System.Drawing.Size(125, 53);
   this.lblZoom.TabIndex = 22;
   this.lblZoom.Text = "Use the buttons to naviagte the Globe data.";
   //
   // lblLoad
   //
   this.lblLoad.BackColor = System.Drawing.SystemColors.Control;
   this.lblLoad.Cursor = System.Windows.Forms.Cursors.Default;
   this.lblLoad.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
   this.lblLoad.ForeColor = System.Drawing.SystemColors.Highlight;
   this.lblLoad.Location = new System.Drawing.Point(528, 9);
   this.lblLoad.Name = "lblLoad";
   this.lblLoad.RightToLeft = System.Windows.Forms.RightToLeft.No;
   this.lblLoad.Size = new System.Drawing.Size(116, 35);
   this.lblLoad.TabIndex = 21;
   this.lblLoad.Text = "Browse to a 3dd file to load.";
   //
   // Form1
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(662, 514);
   this.Controls.Add(this.TrackBar1);
   this.Controls.Add(this.chkSpin);
   this.Controls.Add(this.optTools1);
   this.Controls.Add(this.optTools0);
   this.Controls.Add(this.cmdLoadDocument);
   this.Controls.Add(this.cmdZoomOut);
   this.Controls.Add(this.cmdZoomIn);
   this.Controls.Add(this.cmdFullExtent);
   this.Controls.Add(this.Label1);
   this.Controls.Add(this.lblNavigate);
   this.Controls.Add(this.lblZoom);
   this.Controls.Add(this.lblLoad);
   this.Controls.Add(this.axGlobeControl1);
   this.Name = "Form1";
   this.Text = "Form1";
   this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
   this.Load += new System.EventHandler(this.Form1_Load);
   ((System.ComponentModel.ISupportInitialize)(this.axGlobeControl1)).EndInit();
   ((System.ComponentModel.ISupportInitialize)(this.TrackBar1)).EndInit();
   this.ResumeLayout(false);

  }
  #endregion

  /// <summary>
  /// The main entry point for the application.
  /// </summary>
  [STAThread]
  static void Main()
  {
   Application.Run(new Form1());
  }

  private void Form1_Load(object sender, System.EventArgs e)
  {
   //Create a new AoInitialize object
   if (m_AoInitialize == null)
   {
    //System.Windows.Forms.MessageBox.Show("Unable to initialize. This application cannot run!");
    this.Close();
   }
   //Determine if the product and 3D extension are available
   esriLicenseStatus licenseStatus = (esriLicenseStatus) m_AoInitialize.IsProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeEngine);
   if (licenseStatus == esriLicenseStatus.esriLicenseAvailable)
   {
    licenseStatus = (esriLicenseStatus) m_AoInitialize.IsExtensionCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeEngine, esriLicenseExtensionCode.esriLicenseExtensionCode3DAnalyst);
    if (licenseStatus == esriLicenseStatus.esriLicenseAvailable)
    {
     licenseStatus = (esriLicenseStatus) m_AoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
     if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut)
     {
      //System.Windows.Forms.MessageBox.Show("The initialization failed. This application cannot run!");
      this.Close();
     }
     else
     {
      licenseStatus = (esriLicenseStatus) m_AoInitialize.CheckOutExtension(esriLicenseExtensionCode.esriLicenseExtensionCode3DAnalyst);
      if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut)
      {
       System.Windows.Forms.MessageBox.Show("Unable to check out the 3D Analyst extension. This application cannot run!");
       this.Close();
      }
     }
    }
   }
   else 
   {    
    System.Windows.Forms.MessageBox.Show("The ArcGIS Engine product is unavailable. This application cannot run!");
    this.Close();
   }

   //Initialize member variables
   m_ActiveView = axGlobeControl1.GlobeDisplay.ActiveViewer;
   m_Camera = m_ActiveView.Camera;
  }

  private void cmdLoadDocument_Click(object sender, System.EventArgs e)
  {
   //Open a file dialog for selecting map documents
   openFileDialog1.Title = "Globe Documents";
   openFileDialog1.DefaultExt = ".3dd";
   openFileDialog1.Filter = "Globe Document(*.3dd)|*.3dd";
   openFileDialog1.ShowDialog();

   //Check a file is selected and that it's a valid Globe document
   //before attempting to load it
   if (openFileDialog1.FileName != "")
   {
    if (axGlobeControl1.Check3dFile(openFileDialog1.FileName) == true)
    {
     axGlobeControl1.Load3dFile(openFileDialog1.FileName);
    }
    else
    {
     MessageBox.Show("Cannot load " + openFileDialog1.FileName);
    }
   }
  }

  private void cmdFullExtent_Click(object sender, System.EventArgs e)
  {
   IGlobeCamera camera = (IGlobeCamera) m_Camera;

   //Make sure that the camera is using global coordinates
   camera.OrientationMode = esriGlobeCameraOrientationMode.esriGlobeCameraOrientationGlobal;

   //Point the camera at 0,0 in lat,long - this is the default target
   IPoint target = new PointClass();
   target.PutCoords(0.0,0.0);
   target.Z = 0.0;
   m_Camera.Target = target;

   //Reset the camera to its default values
   m_Camera.Azimuth = 140;
   m_Camera.Inclination = 45;
   m_Camera.ViewingDistance = 4.0;
   m_Camera.ViewFieldAngle = 30.0;
   m_Camera.RollAngle = 0.0;
   m_Camera.RecalcUp();
   m_ActiveView.Redraw(false);
  }

  private void cmdZoomIn_Click(object sender, System.EventArgs e)
  {
   //Reset the camera field of view angle to 0.9 of its previous value
   double vfa = m_Camera.ViewFieldAngle;
   m_Camera.ViewFieldAngle = vfa * 0.9;
   m_ActiveView.Redraw(false);
  }

  private void cmdZoomOut_Click(object sender, System.EventArgs e)
  {
   //Reset the camera field of view angle to 1.1 times its previous value
   double vfa = m_Camera.ViewFieldAngle;
   m_Camera.ViewFieldAngle = vfa * 1.1;
   m_ActiveView.Redraw(false);
  }

  private void CalculateMoveFactors(double dist)
  {
   bool bIsAtCenter;
   int indexGlobe;

   //See if the camera is pointing at the center of the globe.
   IGlobeViewer globeViewer = (IGlobeViewer) m_ActiveView;
   globeViewer.GetIsTargetAtCenter(out bIsAtCenter, out indexGlobe);

   //If the camera is pointing at the center of the globe then the zoom speed
   //depends on how far away it is, otherwise the zoom factor is fixed. As the
   //camera approaches the globe surface (where dist = 1) the zoom speed slows
   //down. The other factors were worked out by trial and error.
   if (bIsAtCenter == true)
   {
    m_dZoom = cMinZoom + (cMaxZoom - cMinZoom) * (dist - 1.0 / 3.0);
   }
   else
   {
    m_dZoom = 1.1;
   }
  }

  private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  {
   //Release COM objects, check in extension and shutdown
   ESRI.ArcGIS.Utility.COMSupport.AOUninitialize.Shutdown();
   m_AoInitialize.CheckInExtension(esriLicenseExtensionCode.esriLicenseExtensionCode3DAnalyst);
   m_AoInitialize.Shutdown();
  }

  private void axGlobeControl1_OnMouseDown(object sender, ESRI.ArcGIS.GlobeControl.IGlobeControlEvents_OnMouseDownEvent e)
  {
   //Mouse down should initiate a zoom only if the Zoom check box is checked
   if (m_bZooming == false)
   {
    return;
   }

   if (e.button == 1)
   {
    m_bMouseDown = true;
    m_pMousePos.X = e.x;
    m_pMousePos.Y = e.y;
   }
  }

  private void axGlobeControl1_OnMouseUp(object sender, ESRI.ArcGIS.GlobeControl.IGlobeControlEvents_OnMouseUpEvent e)
  {
   //Cancel the zoom operation
   m_bMouseDown = false;
   //Navigate can cancel spin - make sure it starts again
   if (m_dSpinSpeed > 0)
   {
    axGlobeControl1.GlobeViewer.StartSpinning(esriGlobeSpinDirection.esriCounterClockwise);
   }
  }

  private void axGlobeControl1_OnMouseMove(object sender, ESRI.ArcGIS.GlobeControl.IGlobeControlEvents_OnMouseMoveEvent e)
  {
   if (m_bMouseDown == false)
   {
    return;
   }

   //If we're in a zoom operation then
   //Get the difference in mouse position between this and the last one
   double dx = e.x - m_pMousePos.X;
   double dy = e.y - m_pMousePos.Y;
   if ((dx == 0) & (dy == 0))
   {
    return;       
   }

   //Work out how far the observer is currently from the globe and use this
   //distance to determine how far to move
   IPoint observer = m_Camera.Observer;
   double zObs;
   double xObs;
   double yObs;
   double dist;
   observer.QueryCoords(out xObs, out yObs);
   zObs = observer.Z;
   dist = System.Math.Sqrt(xObs * xObs + yObs * yObs + zObs * zObs);
   CalculateMoveFactors(dist);

   //Zoom out and in as the mouse moves up and down the screen respectively
   if ((dy < 0) & (dist < cDistanceZoomLimit))
   {
    m_Camera.Zoom(m_dZoom);
   }
   else if (dy > 0)
   {
    m_Camera.Zoom((1 / m_dZoom));
   }

   m_pMousePos.X = e.x;
   m_pMousePos.Y = e.y;
   m_ActiveView.Redraw(false);
  }

  private void chkSpin_Click(object sender, System.EventArgs e)
  {
   if (chkSpin.CheckState == CheckState.Checked)
            {
    axGlobeControl1.GlobeViewer.StartSpinning(esriGlobeSpinDirection.esriCounterClockwise);
    axGlobeControl1.GlobeViewer.SpinSpeed = 3;
    TrackBar1.Enabled = true;
    m_dSpinSpeed = 3;
   }
   else
   {
    axGlobeControl1.GlobeViewer.StopSpinning();
    TrackBar1.Enabled = false;
    m_dSpinSpeed = 0;
   }
  }

  private void TrackBar1_Scroll(object sender, System.EventArgs e)
  {
   //The globe should increase its spin speed with every increment greater than
   //5 and decrease it for every increment less.
   int sliderPos = (TrackBar1.Value - 5);
   if (sliderPos == 0)
   {
    m_dSpinSpeed = 3;
   }
   else if (sliderPos > 0)
   {
    m_dSpinSpeed = 3 * (sliderPos + 1);
   }
   else
   {
    m_dSpinSpeed = 3 / (1 - sliderPos);
   }

   axGlobeControl1.GlobeViewer.SpinSpeed = m_dSpinSpeed;
  }

  private void MixedControls_Click(object sender, System.EventArgs e)
  {
   RadioButton b = (RadioButton) sender;
   //Set current tool
   switch (b.Name)
   {
    case "optTools0":
     m_bZooming = false;
     axGlobeControl1.Navigate = true;
     axGlobeControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
     break;
    case "optTools1":
     m_bZooming = true;
     axGlobeControl1.Navigate = false;
     axGlobeControl1.MousePointer = esriControlsMousePointer.esriPointerZoom;
     break;
   }
  }

  private void optTools0_CheckedChanged(object sender, System.EventArgs e)
  {
  
  }

  private void chkSpin_CheckedChanged(object sender, System.EventArgs e)
  {
  
  }
 }
}

posted on 2008-06-24 19:35 棋剑小秋 阅读(1314) 评论(0)  编辑  收藏 所属分类: GIS

只有注册用户登录后才能发表评论。


网站导航: