This example demonstrates how to create a label with a text label style in a specific position on the terrain. This example uses the IPosition61 (Copy, Pitch), ILabelStyle61 (FontName, Italic, BackgroundColor, Scale), ITerrainLabel61, ICreator61 (CreatePosition, CreateLabelStyle, CreateTextLabel), IColor61 (FromBGRColor, SetAlpha, and INavigate61 (FlyTo) properties and methods.
privatevoid CreateLabel()
{
string tMsg = String.Empty;
IPosition61 cPos = null;
ILabelStyle61 cLabelStyle = null;
ITerrainLabel61 cTextLabel = null;
try
{
//
// A. Instantiate Terra Explorer Globe
//
SGWorld61 sgworld = new SGWorld61();
//
// B. Create position for label
//
{
// 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 = 500;
// B2. Create Position
cPos = sgworld.Creator.CreatePosition(dXCoord, dYCoord, dAltitude, eAltitudeTypeCode, dYaw, dPitch, dRoll, dDistance);
}
//
// C. Create label style for label
//
{
// C1. Set label style input parameters
SGLabelStyle eLabelStyle = SGLabelStyle.LS_DEFAULT;
// C2. Create label style
cLabelStyle = sgworld.Creator.CreateLabelStyle(eLabelStyle);
// C3. Change label style settings
{
uint nBGRValue = 0xFF0000; // Blue
double dAlpha = 0.5; // 50% opacity
IColor61 cBackgroundColor = cLabelStyle.BackgroundColor; // Get label style background color
cBackgroundColor.FromBGRColor(nBGRValue); // Set background to blue
cBackgroundColor.SetAlpha(dAlpha); // Set transparency to 50%
cLabelStyle.BackgroundColor = cBackgroundColor; // Set label style background color
cLabelStyle.FontName = "Arial"; // Set font name to Arial
cLabelStyle.Italic = true; // Set label style font to italic
cLabelStyle.Scale = 3; // Set label style scale
}
}
//
// D. Create text label using label style
//
{
// D1. Set label style params
string tText = "Skyline";
// D2. Create label style
cTextLabel = sgworld.Creator.CreateTextLabel(cPos, tText, cLabelStyle, 0, "TextLabel");
}
//
// E. FlyTo text label
//
{
IPosition61 cFlyToPos = cPos.Copy();
cFlyToPos.Pitch = -89.0; // Set camera to look downward on text label
sgworld.Navigate.FlyTo(cFlyToPos, ActionCode.AC_FLYTO);
}
}
catch (Exception ex)
{
tMsg = String.Format("CreateLabelButton_Click Exception: {0}", ex.Message);
MessageBox.Show(tMsg);
}
}