/// <summary> /// Parses command line arguments (starting with a '/' or a WorldWindUri) /// </summary> /// <param name="args">The command line arguments to parse</param> private static void ParseArgs(string[] args) { //pass args to the shapefileloader to parse it //(load a shapefile if a string begins with worldwind::/shapefile/) try { NLT.Plugins.ShapeFileLoaderGUI.m_ShapeLoad.ParseUri(args); } catch {/* probably because m_ShapeLoad has not been initialized yet * or the plugin does not exist*/} cmdArgs = args; foreach(string rawArg in args) { string arg = rawArg.Trim(); if(arg.Length<=0) continue; try { //check for url call // TODO: do not hardcode the URI scheme here if(arg.StartsWith("worldwind://")) { worldWindUri = WorldWindUri.Parse( arg ); } else if(arg.StartsWith("/")) { if (arg.Length<=1) { throw new ArgumentException("Empty command line option."); } string key = arg.Substring(1,1).ToLower(CultureInfo.CurrentCulture); switch(key) { case "f": // /F = Full screen startFullScreen = true; break; case "s": if(issetCurrentSettingsDirectory) { // once set, don't reset(e.g. when a second instance // of World Wind is sending it's commanline arguments continue; } // /S = Full path to directory to use to use for settings & log files // For example, /S=E:\My Stuff\NASA\WW if (arg.Length<6) { // need 6 characters to specify a drive's root directory(e.g. /S=E:\) throw new ArgumentException("Invalid value(too short) for command line option /S: " + arg ); } if (arg.Substring(2,1) != "=") { throw new ArgumentException("Invalid value(no = after S) for command line option /S: " + arg ); } // TODO: test value via regex? CurrentSettingsDirectory = arg.Substring(3); issetCurrentSettingsDirectory = true; break; default: throw new ArgumentException("Unknown command line option: " + arg ); } } else throw new ArgumentException("Unknown command line option: " + arg ); } catch (Exception ex) // something generally went wrong { Log.Write(ex); //throw new ArgumentException("Error parsing command line options: " + ex.Message ); } } }
/// <summary> /// Pastes the contents of the clipboard into the app /// </summary> void menuItemEditPaste_Click(object sender, System.EventArgs e) { IDataObject iData = Clipboard.GetDataObject(); if(!iData.GetDataPresent(DataFormats.Text)) return; string clipBoardString = (string)iData.GetData(DataFormats.Text); try { worldWindUri = WorldWindUri.Parse(clipBoardString); ProcessWorldWindUri(); } catch (UriFormatException caught) { MessageBox.Show(caught.Message, "Unable to paste - you are not stupid!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void ProcessWorldWindUri() { if (worldWindUri.RawUrl.IndexOf("wmsimage") >= 0) ProcessWmsEncodedUri(); if (worldWindUri.RawUrl.IndexOf("install") >= 0) ProcessInstallEncodedUri(); worldWindow.Goto(worldWindUri); worldWindUri = null; }
private void menuItemCoordsToClipboard_Click(object sender, System.EventArgs e) { if (this.worldWindow.CurrentWorld == null) return; WorldWindUri uri = new WorldWindUri(worldWindow.CurrentWorld.Name, worldWindow.DrawArgs.WorldCamera); string uriString = uri.ToString(); Clipboard.SetDataObject(uriString, true); }
public void ParseUri(string[] args) { foreach(string rawArg in args) { string arg = rawArg.Trim(); if(arg.Length<=0) continue; if(arg.StartsWith("worldwind://")) { arg.Trim().ToLower(CultureInfo.InvariantCulture); WorldWindUri uri = new WorldWindUri(); string url = arg.Replace("worldwind://", ""); if(url.Length == 0) throw new UriFormatException("Incomplete URI"); string[] functions = url.Split('!'); foreach(string function in functions) { if(function.IndexOf("shapefile/") == 0) { if(m_ShapeFileRootDirectory == null) { m_ShapeFileRootDirectory = String.Format("{0}\\ShapeFiles", Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath)); } string functionString = function.Replace("shapefile/", "").Trim(); if(functionString.ToLower().EndsWith(".xml")) { //loads xml+zip or xml+shp from url loadXMLFileFromURL(functionString); } else if(functionString.ToLower().EndsWith(".zip")) { //Loads .zip from remote path loadZipFileFromURL(functionString); } else if(functionString.ToLower().EndsWith(".shp")) { //loads .shp+.dbf from remote path loadShpFileFromURL(functionString); } else throw new UriFormatException("Wrong URI format"); } } } } }
/// <summary> /// Parses a worldwind uri string /// Updated by CM = worldwind://goto/lat=51.41&lon=5.479 /// or worldwind://goto/lat=51.41&lon5.479&view=0.25 /// or /// worldwind://wmsimage=displayname%3Dtestlayer%2526transparency%3D50%2526altitude%3D10000%2526link%3Dhttp%3A%2F%2Fviz.globe.gov%2Fviz-bin%2Fwmt.cgi%3Fservice%3DWMS%26version%3D1.1.1%26request%3DGetMap%26layers%3DRATMAX%26format%3Dimage%2Fpng%26width%3D512%26height%3D512%26bbox%3D-180%2C-90%2C180%2C90%26srs%3DEPSG%3A4326 /// </summary> /// <param name="uriString"></param> /// <returns></returns> public static WorldWindUri Parse( string worldWindUri ) { try { WorldWindUri uri = new WorldWindUri(); worldWindUri = worldWindUri.Trim(); uri._preserveCase = worldWindUri; //set our case-sensitive one, hack for worldwind://install= //then continue as before worldWindUri = worldWindUri.ToLower(CultureInfo.InvariantCulture); uri._rawUrl = worldWindUri; if(!worldWindUri.StartsWith( Scheme + "://")) throw new UriFormatException("Invalid protocol, expected " + Scheme + "://"); string url = worldWindUri.Replace( Scheme + "://", ""); if(url.Length == 0) throw new UriFormatException("Incomplete URI"); //url = url.Replace("///", "!"); // I wanted to allow a sure to split "functions" inside of the url by using "//" string[] functions = url.Split('!'); foreach(string function in functions) { if(function.IndexOf("goto/") == 0) { string functionString = function.Replace("goto/", "").Trim(); string[] functionParameters = functionString.Split('&'); foreach(string curParam in functionParameters) { string[] nv = curParam.Split(new char[]{'='},2); if (nv.Length!=2) continue; string key = nv[0].ToLower(); string value = nv[1]; double doubleVal = double.NaN; string urlDecodedValue = HttpUtility.UrlDecode(value); double.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out doubleVal); switch(key.ToLower()) { case "lat": case "latitude": uri.Latitude = Angle.FromDegrees(doubleVal); break; case "lon": case "longitude": uri.Longitude = Angle.FromDegrees(doubleVal); break; case "altitude": case "alt": uri.Altitude = doubleVal; break; case "view": case "viewrange": uri.ViewRange = Angle.FromDegrees(doubleVal); break; // TODO: Decide on URI parameter names case "bank": uri.Bank = Angle.FromDegrees(doubleVal); break; case "dir": case "direction": uri.Direction = Angle.FromDegrees(doubleVal); break; case "tilt": uri.Tilt = Angle.FromDegrees(doubleVal); break; case "world": uri.World = value; break; case "layer": uri.Layer = urlDecodedValue; break; } } } } return uri; } catch(Exception caught) { throw new UriFormatException( "The worldwind:// URI could not be parsed. (The URI used was: "+worldWindUri+" and the error generated was: "+caught.Message+")"); } }
/// <summary> /// Computes a WorldWind URL (as string) /// </summary> /// <param name="ww"></param> /// <returns></returns> public String GotoURL(WorldWindow ww) { WorldWindUri uri = new WorldWindUri(); uri.Latitude = Angle.FromDegrees(this.pn.Lat); uri.Longitude = Angle.FromDegrees(this.pn.Lon); return uri.ToString(); }
/// <summary> /// Parses a worldwind uri string /// Updated by CM = worldwind://goto/lat=51.41&lon=5.479 /// or worldwind://goto/lat=51.41&lon5.479&view=0.25 /// or /// worldwind://wmsimage=displayname%3Dtestlayer%2526transparency%3D50%2526altitude%3D10000%2526link%3Dhttp%3A%2F%2Fviz.globe.gov%2Fviz-bin%2Fwmt.cgi%3Fservice%3DWMS%26version%3D1.1.1%26request%3DGetMap%26layers%3DRATMAX%26format%3Dimage%2Fpng%26width%3D512%26height%3D512%26bbox%3D-180%2C-90%2C180%2C90%26srs%3DEPSG%3A4326 /// </summary> /// <param name="uriString"></param> /// <returns></returns> public static WorldWindUri Parse(string worldWindUri) { try { WorldWindUri uri = new WorldWindUri(); worldWindUri = worldWindUri.Trim(); uri._preserveCase = worldWindUri; //set our case-sensitive one, hack for worldwind://install= //then continue as before worldWindUri = worldWindUri.ToLower(CultureInfo.InvariantCulture); uri._rawUrl = worldWindUri; if (!worldWindUri.StartsWith(Scheme + "://")) { throw new UriFormatException("Invalid protocol, expected " + Scheme + "://"); } string url = worldWindUri.Replace(Scheme + "://", ""); if (url.Length == 0) { throw new UriFormatException("Incomplete URI"); } //url = url.Replace("///", "!"); // I wanted to allow a sure to split "functions" inside of the url by using "//" string[] functions = url.Split('!'); foreach (string function in functions) { if (function.IndexOf("goto/") == 0) { string functionString = function.Replace("goto/", "").Trim(); string[] functionParameters = functionString.Split('&'); foreach (string curParam in functionParameters) { string[] nv = curParam.Split(new char[] { '=' }, 2); if (nv.Length != 2) { continue; } string key = nv[0].ToLower(); string value = nv[1]; double doubleVal = double.NaN; string urlDecodedValue = HttpUtility.UrlDecode(value); double.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out doubleVal); switch (key.ToLower()) { case "lat": case "latitude": uri.Latitude = Angle.FromDegrees(doubleVal); break; case "lon": case "longitude": uri.Longitude = Angle.FromDegrees(doubleVal); break; case "altitude": case "alt": uri.Altitude = doubleVal; break; case "view": case "viewrange": uri.ViewRange = Angle.FromDegrees(doubleVal); break; // TODO: Decide on URI parameter names case "bank": uri.Bank = Angle.FromDegrees(doubleVal); break; case "dir": case "direction": uri.Direction = Angle.FromDegrees(doubleVal); break; case "tilt": uri.Tilt = Angle.FromDegrees(doubleVal); break; case "world": uri.World = value; break; case "layer": uri.Layer = urlDecodedValue; break; } } } } return(uri); } catch (Exception caught) { throw new UriFormatException("The worldwind:// URI could not be parsed. (The URI used was: " + worldWindUri + " and the error generated was: " + caught.Message + ")"); } }