This example demonstrates how to create a circle, set its properties, and then fly to it. This example uses the ICreator61 (CreatePosition, CreateColor, CreateCircle, CreateMessage), INavigate61 (FlyTo), IPosition61 (Copy, Pitch), IColor61, ITerrainRegularPolygon61 (Radius, Message), IFillStyle61 (Color) and ITerraExplorerMessage61 (ID) interfaces.
privatevoid CreateCircle()
{
string tMsg = String.Empty;
IPosition61 cPos = null;
IColor61 cFillColor = null;
ITerrainRegularPolygon61 cCircle = null;
ITerraExplorerMessage61 cMessage = null;
try
{
//
// A. Instantiate Terra Explorer Globe
//
SGWorld61 sgworld = new SGWorld61();
//
// B. Create position for circle
//
// B1. Set position input parameters (San Fransico shore)
double dXCoord = -122.49460;
double dYCoord = 37.78816;
double dAltitude = 100.0;
AltitudeTypeCode eAltitudeTypeCode = AltitudeTypeCode.ATC_TERRAIN_RELATIVE;
double dYaw = 0.0;
double dPitch = 0.0;
double dRoll = 0.0;
double dDistance = 5000;
// B2. Create Position
cPos = sgworld.Creator.CreatePosition(dXCoord, dYCoord, dAltitude, eAltitudeTypeCode, dYaw, dPitch, dRoll, dDistance);
//
// C. create FillColor for circle
//
{
// C1. Set fill color input params - RGB and Alpha
int nRed = 0;
int nGreen = 255;
int nBlue = 0;
int nAlpha = 0x7F; // 50% opacity
// C2. Create fill color
cFillColor = sgworld.Creator.CreateColor(nRed, nGreen, nBlue, nAlpha);
}
//
// D. Create circle using created position and fill color (for line color use Abgr uint value)
//
{
// D1. Set circle input params
uint nLineColor = 0xFFFF0000; // Abgr value - Solid blue
double dCircleRadius = 200; // in meters
// C2. Create circle
cCircle = sgworld.Creator.CreateCircle(cPos, dCircleRadius, nLineColor, cFillColor, 0, "Circle");
}
//
// E. Get and change circle properties
//
{
// E1. Get & Set circle radius
double dNewCircleRadius = 300;
double dCurrentCircleRadius = cCircle.Radius; // Get circle radius
cCircle.Radius = dNewCircleRadius; // Set new circle radius
// E2. Get fill style and change its properties
uint nRGB_Red = 0xFF0000; // uing Rgb - Red color
double dAlpha = 0.2; // 80% transparent
IFillStyle61 cFillStyle = cCircle.FillStyle;
cFillStyle.Color.FromRGBColor(nRGB_Red);
cFillStyle.Color.SetAlpha(dAlpha);
}
//
// F. Add Message to created circle
//
{
// F1. Set message input parameters
MsgTargetPosition eMsgTarget = MsgTargetPosition.MTP_POPUP;
string tMessage = "Hello Circle";
MsgType eMsgType = MsgType.TYPE_TEXT;
bool bIsBringToFront = true;
// F2. Create message and add to circle
cMessage = sgworld.Creator.CreateMessage(eMsgTarget, tMessage, eMsgType, bIsBringToFront);
cCircle.Message.MessageID = cMessage.ID;
}
//
// G. FlyTo created circle
//
{
IPosition61 cFlyToPos = cPos.Copy();
cFlyToPos.Pitch = -89.0; // Set camera to look downward on circle
sgworld.Navigate.FlyTo(cFlyToPos, ActionCode.AC_FLYTO);
}
}
catch (Exception ex)
{
tMsg = String.Format("CreateCircleButton_Click Exception: {0}", ex.Message);
MessageBox.Show(tMsg);
}
}