[OSM-dev] [RFC] Parse --clon, --clat and --zoom from command line args

Jan-Benedict Glaw jbglaw at lug-owl.de
Sun May 14 08:30:39 BST 2006


Hi!

Since I was unsuccessful supplying clon and clat from command line
options, I digged into it. Seems that never ever worked. So here's a
patch.

It reworks the initialization a bit, because the tiles setup was too
early: the command line args were parsed *after* tiles
initialization...

The patch also simplifies the parsing of arguments, saving one call to
args[].indexOf().

With this patch applied, I can run it like:

$ sh runapplet.sh jbglaw at lug-owl.de <beeep> --clon=8.76 --clat=51.71

Please notice that line numbers may be a tad off, because my latest
scale bar patch was manually edited out of the whole `svn diff'
output.

Index: src/org/openstreetmap/processing/OsmApplet.java
===================================================================
--- src/org/openstreetmap/processing/OsmApplet.java	(revision 1021)
+++ src/org/openstreetmap/processing/OsmApplet.java	(working copy)
@@ -300,42 +301,53 @@
 			js = JSObject.getWindow(this);
 		}
 
-		tiles = new Tile(this, wmsURL, clat, clon, WINDOW_WIDTH, WINDOW_HEIGHT, zoom);
-		tiles.start();
-
-		System.out.println(tiles);
-
-		recalcStrokeWeight();
-
-		System.out.println("Selected strokeWeight of " + strokeWeight);
-
 		println("check webpage applet parameters for a user/pass");
 		try {
 			userName = param("user");
 			password = param("pass");
-
-			System.out.println("Got user/pass: " + userName + "/" + password);
 		} catch (Exception e) {
 			e.printStackTrace();
 		}
 
-		if (userName == null && password == null && args != null) {
-			println("check command line arguments for a user/pass");
+		if (args != null) {
+			println("Parsing command line arguments");
 			for (int i = 0; i < args.length; ++i) {
-				if (args[i].startsWith("--user") && args[i].indexOf('=') != -1) {
+				if (args[i].startsWith("--user=")) {
 					userName = args[i].substring(args[i].indexOf('=')+1);
 				}
-				if (args[i].startsWith("--pass") && args[i].indexOf('=') != -1) {
+				if (args[i].startsWith("--pass=")) {
 					password = args[i].substring(args[i].indexOf('=')+1);
 				}
-				if (userName != null && password != null)
-					System.out.println("Got user/pass: " + userName + "/" + password);
+				if (args[i].startsWith("--clon=")) {
+					clon = Float.parseFloat(args[i].substring(args[i].indexOf('=')+1));
+				}
+				if (args[i].startsWith("--clat=")) {
+					clat = Float.parseFloat(args[i].substring(args[i].indexOf('=')+1));
+				}
+				if (args[i].startsWith("--zoom=")) {
+					clat = Integer.parseInt(args[i].substring(args[i].indexOf('=')+1));
+				}
 			}
 		}
 
+		System.out.println("Got userName: " + userName);
+		System.out.println("Got password: " + password);
+		System.out.println("Got clon: " + clon);
+		System.out.println("Got clat: " + clat);
+		System.out.println("Got zoom: " + zoom);
+
+		tiles = new Tile(this, wmsURL, clat, clon, WINDOW_WIDTH, WINDOW_HEIGHT, zoom);
+		tiles.start();
+
+		System.out.println(tiles);
+
+		recalcStrokeWeight();
+
+		System.out.println("Selected strokeWeight of " + strokeWeight);
+
 		// try to connect to OSM
 		osm = new Adapter(userName, password, this, apiURL);
-		
+
 		// register as listener of finished commands (to redraw)
 		osm.commandManager.addListener(new CommandManager.Listener(){
 			public void commandFinished(ServerCommand command) {


MfG, JBG

-- 
Jan-Benedict Glaw       jbglaw at lug-owl.de    . +49-172-7608481             _ O _
"Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg  _ _ O
 für einen Freien Staat voll Freier Bürger"  | im Internet! |   im Irak!   O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.openstreetmap.org/pipermail/dev/attachments/20060514/dbed999d/attachment.pgp>


More information about the dev mailing list