Creating a Circle

This example demonstrates how to create a circle, set its properties, and then fly to it. This example uses the ICreator81 (CreatePosition, CreateColor, CreateCircle, CreateMessage), INavigate81 (FlyTo), IPosition81 (Copy, Pitch), IColor81, ITerrainRegularPolygon81  (Radius, Message), IFillStyle81 (Color) and ITerraExplorerMessage81 (ID) properties and methods.

 

private void CreateCircle()

        {

            string tMsg = String.Empty;

            IPosition81 cPos = null;

            IColor81 cFillColor = null;

            ITerrainRegularPolygon81 cCircle = null;

            ITerraExplorerMessage81 cMessage = null;

 

            try

            {

                //

                // A. Instantiate TerraExplorer Project

                //

                var SGWorld = newSGWorld81();

 

                //

                // B.  Create position for circle

                //

                // B1. Set position input parameters (San Francisco 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

                    intnRed = 0;

                    intnGreen = 255;

                    intnBlue = 0;

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

                    uintnLineColor = 0xFFFF0000;   // Abgr value - Solid blue

                    doubledCircleRadius = 200;     // in meters

 

                    // C2. Create circle

                    cCircle = SGWorld.Creator.CreateCircle(cPos, dCircleRadius, nLineColor, cFillColor, string.Empty, "Circle");

                }

 

                //

                // E. Get and change circle properties

                //

                {

                    // E1. Get & Set circle radius

                    doubledNewCircleRadius = 300;

                    doubledCurrentCircleRadius = cCircle.Radius; // Get circle radius

                    cCircle.Radius = dNewCircleRadius;            // Set new circle radius 

 

                    // E2. Get fill style and change its properties

                    uintnRGB_Red = 0xFF0000;  // uing Rgb - Red color

                    doubledAlpha = 0.2;       // 80% transparent

                    varcFillStyle = 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;

                    stringtMessage = "Hello Circle";

                    MsgType eMsgType = MsgType.TYPE_TEXT;

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

                //

                {

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

            }

        }