This example demonstrates how to create a label with a text label style in a specific position on the terrain. This example uses the IPosition66 (Copy, Pitch), ILabelStyle66 (FontName, Italic, BackgroundColor, Scale), ITerrainLabel66, ICreator66 (CreatePosition, CreateLabelStyle, CreateTextLabel), IColor66 (FromBGRColor, SetAlpha, and INavigate66 (FlyTo) properties and methods.
private void CreateLabel()
{
stringtMsg = String.Empty;
IPosition66 cPos = null;
ILabelStyle66 cLabelStyle = null;
ITerrainLabel66 cTextLabel = null;
try
{
//
// A. Instantiate Terra Explorer Globe
//
var sgworld = new SGWorld66();
//
// 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
var 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, string.Empty, "TextLabel");
}
//
// E. FlyTo text label
//
{
var 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);
}
}