AsterixDisplayAnalyser.Asterix_To_KML_Provider.BuildKML C# (CSharp) Метод

BuildKML() публичный Метод

public BuildKML ( ) : void
Результат void
        public void BuildKML()
        {
            string exampleFileName = "";
            string exampleFileExt = "kmz";
            string file_name = "ASTX_TO_KML";

            // Use a Document as the root of the KML
            geDocument doc = new geDocument();
            doc.Name = "Asterix to KML";

            // Create a new style to be added the doc
            geStyle myStyle = new geStyle("myStyle");

            //add a new IconStyle to the style
            myStyle.IconStyle = new geIconStyle();
            myStyle.IconStyle.Icon = new geIcon("ac_image.png");
            myStyle.IconStyle.Scale = 1.0F; //or (float)1

            myStyle.LabelStyle = new geLabelStyle();
            myStyle.LabelStyle.Color.SysColor = Color.White;

            myStyle.LineStyle = new geLineStyle();
            myStyle.LineStyle.Color.SysColor = Color.Black;
            myStyle.LineStyle.Width = 4;

            //Add the style
            doc.StyleSelectors.Add(myStyle);

            foreach (DynamicDisplayBuilder.TargetType Target in TargetList)
            {
                //Create a Placemark to put in the document
                //This placemark is going to be a point
                //but it could be anything in the Geometry class
                gePlacemark pm = new gePlacemark();

                //Create some coordinates for the point at which
                //this placemark will sit. (Lat / Lon)
                geCoordinates coords = new geCoordinates(
                    new geAngle90(Target.Lat),
                new geAngle180(Target.Lon));

                double LevelInMeeters = 0.0;

                // Assign the altitude
                if (Target.ModeC != null)
                {
                    if (Target.ModeC != "---")
                        LevelInMeeters = (double.Parse(Target.ModeC) * 100.00) * SharedData.FeetToMeeters;
                }

                coords.Altitude = (float)LevelInMeeters;

                //Create a point with these new coordinates
                gePoint point = new gePoint(coords);
                point.AltitudeMode = geAltitudeModeEnum.absolute;
                point.Extrude = true;

                //Assign the point to the Geometry property of the
                //placemark.
                pm.Geometry = point;

                //Set the placemark's style to the style we created above
                pm.StyleUrl = "#myStyle";

                if (Properties.Settings.Default.GE_Show_ModeA)
                    pm.Name = Target.ModeA;

                if (Properties.Settings.Default.GE_Show_ModeC)
                {
                    if (Properties.Settings.Default.Show_ModeC_as_FL)
                        pm.Name = pm.Name + "  " + "FL:" + Target.ModeC;
                    else
                        pm.Name = pm.Name + "  " + LevelInMeeters.ToString() + "m";
                }

                if (Properties.Settings.Default.GE_Show_ModeC)
                {
                    pm.Name = pm.Name + " " + Target.ACID_Mode_S;
                }

                pm.Snippet = "Snipet Test";
                pm.Description = "Blaa Bla Blaaaa";

                //Finally, add the placemark to the document
                doc.Features.Add(pm);
            }

            geKML kml = new geKML(doc);

            //Add supporting files to the KMZ (assuming it's going to be rendered as KMZ
            byte[] myFile = File.ReadAllBytes(@"C:\ASTERIX\GE\ac_image.png");
            kml.Files.Add("ac_image.png", myFile);

            exampleFileName = Properties.Settings.Default.GE_Dest_Path + "\\" + file_name + "." + exampleFileExt;
            File.WriteAllBytes(exampleFileName, kml.ToKMZ());

            // Clear the list
            TargetList.Clear();
        }

Usage Example

Пример #1
0
        private void Update_PlotTrack_Data()
        {
            if (this.checkEnableDisplay.Checked == true)
            {

                // First clear all the data from the previous cycle.
                if (DinamicOverlay.Markers.Count > 0)
                    DinamicOverlay.Markers.Clear();

                if (PredictionOverlay.Markers.Count > 0)
                    PredictionOverlay.Markers.Clear();

                // Now get the data since the last cycle and display it on the map
                DynamicDisplayBuilder DP = new DynamicDisplayBuilder();
                System.Collections.Generic.List<DynamicDisplayBuilder.TargetType> TargetList = new System.Collections.Generic.List<DynamicDisplayBuilder.TargetType>();

                // Here handle display od live data
                if (SharedData.bool_Listen_for_Data == true)
                {
                    DynamicDisplayBuilder.GetDisplayData(false, out TargetList);

                    if (FirstCycleDisplayEnabled)
                    {
                        FirstCycleDisplayEnabled = false;
                        TargetList.Clear();
                    }

                    this.lblNumberofTargets.Text = TargetList.Count.ToString();

                    bool Build_Local_Display = comboBoxLiveDisplayMode.Text != "Google Earth";
                    bool Provide_To_Google_Earth = comboBoxLiveDisplayMode.Text != "Local";
                    bool ProvideWebData = comboBoxLiveDisplayMode.Text == "Local & Web" || comboBoxLiveDisplayMode.Text == "Web";
                    Asterix_To_KML_Provider ASTX_TO_KML = new Asterix_To_KML_Provider();
                    WBTD WebBasedDisplayProvider = new WBTD();
                    PredictionBuilder Prediction_B = new PredictionBuilder();

                    try
                    {
                        foreach (DynamicDisplayBuilder.TargetType Target in TargetList)
                        {
                            if (Passes_Check_For_Flight_Level_Filter(Target.ModeC))
                            {
                                // If SSR code filtering is to be applied
                                if (this.checkBoxFilterBySSR.Checked == true && (this.textBoxSSRCode.Text.Length == 4))
                                {
                                    if (Target.ModeA == this.textBoxSSRCode.Text)
                                    {
                                        Target.MyMarker.ToolTipMode = MarkerTooltipMode.Never;
                                        Target.MyMarker.Position = new PointLatLng(Target.Lat, Target.Lon);
                                        BuildDynamicLabelText(Target, ref Target.MyMarker);
                                        SetLabelAttributes(ref Target.MyMarker);

                                        if (Build_Local_Display)
                                        {
                                            DinamicOverlay.Markers.Add(Target.MyMarker);

                                            if (SharedData.Prediction1_Enabled)
                                                Prediction_B.Build_Prediction_Marker(Target.MyMarker.Position, Target.MyMarker.CALLSIGN_STRING, MySqlProvider.PredictionTableNumberType.One, ref PredictionOverlay);

                                            if (SharedData.Prediction2_Enabled)
                                                Prediction_B.Build_Prediction_Marker(Target.MyMarker.Position, Target.MyMarker.CALLSIGN_STRING, MySqlProvider.PredictionTableNumberType.Two, ref PredictionOverlay);

                                            if (SharedData.Prediction3_Enabled)
                                                Prediction_B.Build_Prediction_Marker(Target.MyMarker.Position, Target.MyMarker.CALLSIGN_STRING, MySqlProvider.PredictionTableNumberType.Three, ref PredictionOverlay);

                                        }

                                        if (Provide_To_Google_Earth)
                                            ASTX_TO_KML.AddNewTarget(Target);

                                        if (ProvideWebData)
                                            WebBasedDisplayProvider.SetTargetData(Target.Lat.ToString(), Target.Lon.ToString(), Target.ACID_Mode_S,
                                                Target.ModeA, Target.ModeC);
                                    }
                                }
                                else // No SSR filter so just display all of them
                                {
                                    Target.MyMarker.ToolTipMode = MarkerTooltipMode.Never;
                                    Target.MyMarker.Position = new PointLatLng(Target.Lat, Target.Lon);
                                    BuildDynamicLabelText(Target, ref Target.MyMarker);
                                    SetLabelAttributes(ref Target.MyMarker);

                                    if (Build_Local_Display)
                                    {
                                        DinamicOverlay.Markers.Add(Target.MyMarker);

                                        if (SharedData.Prediction1_Enabled)
                                            Prediction_B.Build_Prediction_Marker(Target.MyMarker.Position, Target.MyMarker.CALLSIGN_STRING, MySqlProvider.PredictionTableNumberType.One, ref PredictionOverlay);

                                        if (SharedData.Prediction2_Enabled)
                                            Prediction_B.Build_Prediction_Marker(Target.MyMarker.Position, Target.MyMarker.CALLSIGN_STRING, MySqlProvider.PredictionTableNumberType.Two, ref PredictionOverlay);

                                        if (SharedData.Prediction3_Enabled)
                                            Prediction_B.Build_Prediction_Marker(Target.MyMarker.Position, Target.MyMarker.CALLSIGN_STRING, MySqlProvider.PredictionTableNumberType.Three, ref PredictionOverlay);
                                    }

                                    if (Provide_To_Google_Earth)
                                        ASTX_TO_KML.AddNewTarget(Target);

                                    if (ProvideWebData)
                                        WebBasedDisplayProvider.SetTargetData(Target.Lat.ToString(), Target.Lon.ToString(), Target.ACID_Mode_S,
                                           Target.ModeA, Target.ModeC);
                                }
                            }
                        }
                    }
                    catch
                    {

                    }

                    Cursor.Position = new Point(Cursor.Position.X + 1, Cursor.Position.Y);
                    Cursor.Position = new Point(Cursor.Position.X - 1, Cursor.Position.Y);

                    // Check if there were any items, if so then tell KML to build the file
                    if (Provide_To_Google_Earth)
                        ASTX_TO_KML.BuildKML();

                    if (ProvideWebData)
                        WebBasedDisplayProvider.WriteTrackData();

                }
                else // Here handle display of passive display (buffered data)
                {
                    DynamicDisplayBuilder.GetDisplayData(true, out TargetList);

                    this.lblNumberofTargets.Text = TargetList.Count.ToString();

                    foreach (DynamicDisplayBuilder.TargetType Target in TargetList)
                    {
                        if (Passes_Check_For_Flight_Level_Filter(Target.ModeC))
                        {
                            // If SSR code filtering is to be applied
                            if (this.checkBoxFilterBySSR.Checked == true && (this.comboBoxSSRFilterBox.Items.Count > 0))
                            {
                                if (Target.ModeA == this.comboBoxSSRFilterBox.Items[SSR_Filter_Last_Index].ToString())
                                {
                                    GMap.NET.WindowsForms.Markers.GMapMarkerCross MyMarker = new GMap.NET.WindowsForms.Markers.GMapMarkerCross(new PointLatLng(Target.Lat, Target.Lon));
                                    MyMarker.ToolTipMode = MarkerTooltipMode.Always;
                                    MyMarker.ToolTipText = BuildPassiveLabelText(Target);
                                    SetLabelAttributes(ref MyMarker);
                                    DinamicOverlay.Markers.Add(MyMarker);
                                }
                            }
                            else // No filter so just display all of them
                            {
                                GMap.NET.WindowsForms.Markers.GMapMarkerCross MyMarker = new GMap.NET.WindowsForms.Markers.GMapMarkerCross(new PointLatLng(Target.Lat, Target.Lon));
                                MyMarker.ToolTipMode = MarkerTooltipMode.Always;
                                MyMarker.ToolTipText = BuildPassiveLabelText(Target);
                                SetLabelAttributes(ref MyMarker);
                                DinamicOverlay.Markers.Add(MyMarker);
                            }
                        }
                    }
                }
            }
        }
Asterix_To_KML_Provider