Add a MouseWheel event to Arcglobe to enable the mouse zoom-in and zoom-out function.

Source: Internet
Author: User

Add the following code to the MainForm. cs file:

Private void MainForm_Load (object sender, EventArgs e)
{

// Add the scroll wheel zoom-in and zoom-out function to Arcglobe.
This. MouseWheel + = new System. Windows. Forms. MouseEventHandler (axglobecontrolpoliconmousewheel );
}
Private void axglobecontrolpoliconmousewheel (object sender, MouseEventArgs e)
{
Try
{
Cursor. current = new System. windows. forms. cursor (@".. \.. \ Resources \ ZOOMINOUT. CUR "); // convert the mouse style to a custom mouse Style
// M_cursor = new System. Windows. Forms. Cursor (@ "... \ .. \ Resources \ ZOOMINOUT. CUR ");
System. Drawing. Point pSceLoc = axGlobeControl1.PointToScreen (axGlobeControl1.Location );
System. Drawing. Point Pt = this. PointToScreen (e. Location );
If (Pt. X <pSceLoc. X | Pt. x> pSceLoc. X + axGlobeControl1.Width | Pt. Y <pSceLoc. Y | Pt. y> pSceLoc. Y + axGlobeControl1.Height)
{
Return;
}

Double scale = 0.2;
If (e. Delta <0) scale =-scale;

IGlobeCamera pGlobeCamera = axGlobeControl1.GlobeCamera;
ICamera pCamera = pGlobeCamera as ICamera;
IGlobeDisplay pGlobeDisplay = axGlobeControl1.GlobeDisplay;
If (pGlobeCamera. OrientationMode = esriGlobeCameraOrientationMode. esriGlobeCameraOrientationGlobal)
{
Double zt, xo, yo, zo;
PGlobeCamera. GetObserverLatLonAlt (out xo, out yo, out zo );
PGlobeDisplay. GetSurfaceElevation (xo, yo, true, out zt );
IPoint pObserver = new PointClass ();
PObserver. PutCoords (xo, yo );
Double zt1 = zt * (UnitSacleToMeter (axGlobeControl1.Globe. GlobeUnits ));
Zo = (zo-zt1) * (1 + scale );
PGlobeCamera. SetObserverLatLonAlt (xo, yo, zo );
}
Else
{
PCamera. ViewingDistance + = pCamera. ViewingDistance * scale;
}
AxGlobeControl1.GlobeDisplay. RefreshViewers ();
}
Catch
{
}
}

/// <Summary>
/// The UnitSacleToMeter method is used to obtain the coefficient from unit to meter.
/// </Summary>
/// <Param name = "unit"> </param>
/// <Returns> </returns>
Public static double UnitSacleToMeter (esriUnits unit)
{
Switch (unit)
{
Case esriUnits. esriKilometers:
Return 1000;
Case esriUnits. esriMeters:
Return 1;
Default:
Return-1;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.