Creating a Text Label

This example demonstrates how to create a label with a text label style in a specific position on the terrain. This example uses the IPosition81 (Copy, Pitch), ILabelStyle81 (FontName, Italic, BackgroundColor, Scale), ITerrainLabel81, ICreator81 (CreatePosition, CreateLabelStyle, CreateTextLabel), IColor81 (FromBGRColor, SetAlpha, and INavigate81 (FlyTo) properties and methods.

 

private void CreateLabel()

        {

            string tMsg = String.Empty;

            IPosition81 cPos = null;

            ILabelStyle81 cLabelStyle = null;

            ITerrainLabel81 cTextLabel = null;

 

            try

            {

                //

                // A. Instantiate TerraExplorer Object

                //

                var SGWorld = newSGWorld81();

 

                //

                // B.  Create position for label

                //

                {

                    // B1. Set position  input parameters (San Francisco shore)

                    doubledXCoord = -122.49460;

                    doubledYCoord = 37.78816;

                    doubledAltitude = 100.0;

                    AltitudeTypeCode eAltitudeTypeCode = AltitudeTypeCode.ATC_TERRAIN_RELATIVE;

                    doubledYaw = 0.0;

                    doubledPitch = 0.0;

                    doubledRoll = 0.0;

                    doubledDistance = 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

                    {

                        uintnBGRValue = 0xFF0000;  // Blue

                        doubledAlpha = 0.5;        // 50% opacity

                        varcBackgroundColor = 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

                    stringtText = "Skyline";

 

                    // D2. Create label style

                    cTextLabel = SGWorld.Creator.CreateTextLabel(cPos, tText, cLabelStyle, string.Empty, "TextLabel");

                }

 

                //

                // E. FlyTo text label

                //

                {

                    varcFlyToPos = 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);

            }

        }