Beispiel #1
0
        private void OpenFileButton_Click(object sender, RoutedEventArgs e)
        {
            // Create an instance of the open file dialog box.
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            // Set filter options and filter index.
            openFileDialog1.Filter      = "Google Earth (.kml .kmz)|*.kml;*.kmz";
            openFileDialog1.FilterIndex = 1;

            openFileDialog1.Multiselect = true;

            // Call the ShowDialog method to show the dialog box.
            bool?userClickedOK = openFileDialog1.ShowDialog();

            // Process input if the user clicked OK.
            if (userClickedOK == true)
            {
                KmlFile kmlFile  = null;
                string  fileName = openFileDialog1.FileName;

                string fileExtension = System.IO.Path.GetExtension(fileName);
                if (fileExtension.Equals(".kmz", StringComparison.OrdinalIgnoreCase))
                {
                    try {
                        using (Stream fileStream = File.OpenRead(fileName)) {
                            KmzFile kmzFile       = KmzFile.Open(fileStream);
                            string  kmlFileString = kmzFile.ReadKml();
                            using (StringReader stringReader = new StringReader(kmlFileString))
                            {
                                kmlFile = KmlFile.Load(stringReader);
                            }
                        };
                    } catch (Exception ex) {
                        MessageBox.Show(ex.Message, "Failed to open a KMZ file", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                }
                else
                {
                    try {
                        using (Stream fileStream = File.OpenRead(fileName)) {
                            kmlFile = KmlFile.Load(fileStream);
                        };
                    } catch (Exception ex) {
                        MessageBox.Show(ex.Message, "Failed to open a KML file", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                }
                KmlTreeViewController kmlTreeViewController = new KmlTreeViewController();
                kmlTreeViewController.SetTreeView(this.KmlItemsTreeView);
                kmlTreeViewController.SetKML(kmlFile);
                kmlTreeViewController.ProcessKml();
                kmlTreeViewController.TreeViewSelectionChanged += c_TreeViewSelectionChanged;

                KmlSchemaNameComboBoxController kmlSchemaComboBoxController = new KmlSchemaNameComboBoxController();
                kmlSchemaComboBoxController.SetComboBox(this.SchemaListComboBox);
                kmlSchemaComboBoxController.SetKML(kmlFile);
                kmlSchemaComboBoxController.ProcessKml();
                kmlSchemaComboBoxController.ComboBoxSelectionChanged += PropertySchemaSelectionChanged;

                kmlSchemaListViewController.SetListView(this.SchemaListView);
                kmlFeatureSchemaListViewController.SetListView(this.PropertySchemaListView);
            }
        }
        private void OpenFileButton_Click(object sender, RoutedEventArgs e)
        {
            // Create an instance of the open file dialog box.
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            // Set filter options and filter index.
            openFileDialog1.Filter = "Google Earth (.kml .kmz)|*.kml;*.kmz";
            openFileDialog1.FilterIndex = 1;

            openFileDialog1.Multiselect = true;

            // Call the ShowDialog method to show the dialog box.
            bool? userClickedOK = openFileDialog1.ShowDialog();

            // Process input if the user clicked OK.
            if (userClickedOK == true)
            {
                KmlFile kmlFile = null;
                string fileName = openFileDialog1.FileName;

                string fileExtension = System.IO.Path.GetExtension(fileName);
                if (fileExtension.Equals(".kmz", StringComparison.OrdinalIgnoreCase)) {
                    try {
                        using(Stream fileStream = File.OpenRead(fileName)) {
                            KmzFile kmzFile = KmzFile.Open(fileStream);
                            string kmlFileString = kmzFile.ReadKml();
                            using(StringReader stringReader = new StringReader(kmlFileString))
                            {
                                kmlFile = KmlFile.Load(stringReader);
                            }
                        };
                    } catch (Exception ex) {
                        MessageBox.Show(ex.Message, "Failed to open a KMZ file", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                } else {
                    try {
                        using(Stream fileStream = File.OpenRead(fileName)) {
                            kmlFile = KmlFile.Load(fileStream);
                        };
                    } catch (Exception ex) {
                        MessageBox.Show(ex.Message, "Failed to open a KML file", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                }
                KmlTreeViewController kmlTreeViewController = new KmlTreeViewController();
                kmlTreeViewController.SetTreeView(this.KmlItemsTreeView);
                kmlTreeViewController.SetKML(kmlFile);
                kmlTreeViewController.ProcessKml();
                kmlTreeViewController.TreeViewSelectionChanged += c_TreeViewSelectionChanged;

                KmlSchemaNameComboBoxController kmlSchemaComboBoxController = new KmlSchemaNameComboBoxController();
                kmlSchemaComboBoxController.SetComboBox(this.SchemaListComboBox);
                kmlSchemaComboBoxController.SetKML(kmlFile);
                kmlSchemaComboBoxController.ProcessKml();
                kmlSchemaComboBoxController.ComboBoxSelectionChanged += PropertySchemaSelectionChanged;

                kmlSchemaListViewController.SetListView(this.SchemaListView);
                kmlFeatureSchemaListViewController.SetListView(this.PropertySchemaListView);
            }
        }