TerraExplorer provides the ability to embed all TerraExplorer components: the 3D Window, the Information Window (Project Tree), and external 3D windows as ActiveX components, in your custom application GUI or in a Web page. This article contains a step-by-step guide to embedding ActiveX controls in C#. The steps refer to Visual Studio 2019.
- Download and install TerraExplorer.
- Create a new Windows Forms application project in Visual Studio, using C#:
- In Visual Studio, click Create a new project.
- Select a C# Windows Form App project. Name the project 'TerraExplorerShowcaseCSharp', and click OK.
- Create a new x64 solution platform and apply it to the current solution:
- Build > Configuration Manager > Active solution platform > Create a new 64 bit platform
- Apply the platform on the current solution.
- Reference TerraExplorerX and AxInterop.TerraExplorerX. From the Project menu > References > select Add References.
- Click the COM Components tab and locate TerraExplorerX 1.0 Type Library from the available references.
- In the Reference Manager dialog, click Browse and then add C:\Program Files\Skyline\TerraExplorer Pro\AxInterop.TerraExplorerX.dll
- Add the using directive for TerraExplorerX and AxTerraExplorerX namespaces in the Form1 code.
using TerraExplorerX;
using AxTerraExplorerX; - In the designer code Form1.Designer.cs, at the Form1 class, add the Panel objects:
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Panel panel2; - In the designer code Form1.Designer.cs, at the InitializeComponent, set the form size and create Panel objects in which the ActiveX components will be stored.
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1097, 769);
this.Controls.Add(this.panel2);
this.Controls.Add(this.panel1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
//
// add the panel to the form and instantiate it
//
this.panel1 = new System.Windows.Forms.Panel();
this.panel2 = new System.Windows.Forms.Panel();
this.SuspendLayout();
this.Controls.Add(this.panel2);
this.Controls.Add(this.panel1);
//
// panel1
//
this.panel1.Location = new System.Drawing.Point(330, 5);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(762, 762);
this.panel1.TabIndex = 0;
//
// panel2
//
this.panel2.Location = new System.Drawing.Point(12, 5);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(305, 762);
this.panel2.TabIndex = 1; - In the Form1 code, define a variable to hold an SGWorld object instance.
Note: This variable is used later to access extensive TerraExplorer API.
private SGWorld80 sgworld;
- Define AxHost variables to hold the AxTE3DWindow and the AxTEInformationTree components.
private AxHost ThreeDWindow, InfoTree;
- Initialize an SGWorld object in the Form1_Load event.
Note: This object automatically finds the ActiveX controls that you have placed on the form and interacts with them.
Note: You should initialize this object only after the ActiveX object was already created, i.e., in the Form1_Load() event.
sgworld = new SGWorld80();
- Now you can use SGWorld object to control the TerraExplorer ActiveX. The following code loads a .fly project and flies to a specific location.
public partial class Form1 : Form
{
private SGWorld80 sgworld;
private AxHost ThreeDWindow, InfoTree;
public Form1()
{
InitializeComponent();
ThreeDWindow = new AxTE3DWindow() { Dock = DockStyle.Fill };
panel1.Controls.Add(ThreeDWindow);
InfoTree = new AxTEInformationWindow() { Dock = DockStyle.Fill };
panel2.Controls.Add(InfoTree);
}
private void Form1_Load(object sender, EventArgs e)
{
sgworld = new SGWorld80();
// Register to OnLoadFinished globe event
sgworld.OnLoadFinished += Sgworld_OnLoadFinished;
// Open Project in asynchronous mode
string flyFile = "http://www.skylineglobe.com/SkylineGlobeLayers/SG_ExternalFlys/skylineglobe7.fly";
sgworld.Project.Open(flyFile, true, null, null);
MessageBox.Show("Opening project " + flyFile + " in async mode");
}
private void Sgworld_OnLoadFinished(bool bSuccess)
{
MessageBox.Show("Received project loaded event. Click OK to fly to Washington DC.");
IPosition80 Orlando = sgworld.Creator.CreatePosition(-81.37504215, 28.54353898, 0, AltitudeTypeCode.ATC_TERRAIN_RELATIVE, 235.00487, -26.045611, 0, 873);
sgworld.Navigate.FlyTo(Orlando);
}
}