コード例 #1
0
        /// <summary>
        /// Loads a KML file
        /// </summary>
        private void LoadKMLFile()
        {
            if (KMLPath == null || m_KMLIcons == null)
            {
                return;
            }

            Cleanup();
            m_parser.Cleanup();

            WaitMessage waitMessage = new WaitMessage();

            m_KMLIcons.Add(waitMessage);

            // Create a reader to read the file
            try
            {
                string kml = m_loader.LoadKML(KMLPath);
                KMLPath = m_loader.RealKMLPath;
                if (kml != null)
                {
                    try
                    {
                        // Load the actual kml data
                        m_parser.ReadKML(kml, m_KMLIcons, KMLPath);
                    }
                    catch (Exception ex)
                    {
                        Log.Write(Log.Levels.Error, "KMLImporter: " + ex.ToString());
                        MessageBox.Show(
                            String.Format(CultureInfo.InvariantCulture, "Error loading KML file '{0}':\n\n{1}", KMLPath, ex.ToString()),
                            "KMLImporter error",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error,
                            MessageBoxDefaultButton.Button1,
                            true ? MessageBoxOptions.RtlReading : MessageBoxOptions.ServiceNotification);
                    }
                }
            }
            catch (Exception ex) // Catch error if stream reader failed
            {
                Log.Write(Log.Levels.Error, "KMLImporter: " + ex.ToString());
                MessageBox.Show(
                    String.Format(CultureInfo.InvariantCulture, "Error opening KML file '{0}':\n\n{1}", KMLPath, ex.ToString()),
                    "KMLImporter error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error,
                    MessageBoxDefaultButton.Button1,
                    true ? MessageBoxOptions.RtlReading : MessageBoxOptions.ServiceNotification);
            }

            // Cleanup
            m_KMLIcons.Remove(waitMessage);
            KMLPath = null;
        }
コード例 #2
0
ファイル: KMLImporter.cs プロジェクト: jpespartero/WorldWind
		/// <summary>
		/// Loads a KML file
		/// </summary>
		private void LoadKMLFile()
		{
			if (KMLPath == null || KMLIcons == null)
				return;

			Cleanup();

			WaitMessage waitMessage = new WaitMessage();
			KMLIcons.ChildObjects.Add(waitMessage);

			// Create a reader to read the file
			try
			{
				System.IO.StreamReader sr = new StreamReader(KMLPath);

				// Read all data from the reader
				string kml = sr.ReadToEnd();

				try
				{
					// Load the actual kml data
					LoadKML(kml, KMLIcons);
				}
				catch (Exception ex)
				{
					Log.Write(Log.Levels.Error, "KMLImporter: " + ex.ToString());
					MessageBox.Show(
						String.Format(CultureInfo.InvariantCulture, "Error loading KML file '{0}':\n\n{1}", KMLPath, ex.ToString()), 
						"KMLImporter error", 
						MessageBoxButtons.OK,
						MessageBoxIcon.Error,
						MessageBoxDefaultButton.Button1,
						base.Application.RightToLeft == RightToLeft.Yes ? MessageBoxOptions.RtlReading : MessageBoxOptions.ServiceNotification);
				}

				// Close the reader
				sr.Close();
			}
			catch(Exception ex) // Catch error if stream reader failed
			{
				Log.Write(Log.Levels.Error, "KMLImporter: " + ex.ToString());
				MessageBox.Show(
					String.Format(CultureInfo.InvariantCulture, "Error opening KML file '{0}':\n\n{1}", KMLPath, ex.ToString()), 
					"KMLImporter error", 
					MessageBoxButtons.OK,
					MessageBoxIcon.Error,
					MessageBoxDefaultButton.Button1,
					base.Application.RightToLeft == RightToLeft.Yes ? MessageBoxOptions.RtlReading : MessageBoxOptions.ServiceNotification);
			}

			// Cleanup
			KMLIcons.ChildObjects.Remove(waitMessage);
			KMLPath = null;				
		}