[josm-dev] patch (bounds for osmarender plugin)

Matteo matgott at tin.it
Thu Aug 7 02:26:58 BST 2008


Il Thursday 07 August 2008 02:27:21 andrzej zaborowski ha scritto:
> 2008/8/6 Matteo <matgott at tin.it>:
> > Hi, this is a little patch for the osmarender plugin that use the
> > "bounds" tag.
>
> -ENOPATCH
I attach the patch, and copy it here in the body

********** BEGIN **********
--- OsmarenderPlugin.java.orig	2008-08-07 03:20:24.000000000 +0200
+++ OsmarenderPlugin.java	2008-08-07 03:20:44.000000000 +0200
@@ -3,6 +3,9 @@
 import java.awt.event.ActionEvent;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.BufferedReader;
+import java.io.FileReader;
 import java.util.Collection;
 import java.util.HashSet;
 
@@ -29,7 +32,6 @@
 import org.openstreetmap.josm.plugins.Plugin;
 import org.openstreetmap.josm.tools.GBC;
 
-
 public class OsmarenderPlugin extends Plugin {
 
     private class Action extends AbstractAction {
@@ -43,6 +45,13 @@
             LatLon bottomLeft = 
Main.map.mapView.getLatLon(0,Main.map.mapView.getHeight());
             LatLon topRight = 
Main.map.mapView.getLatLon(Main.map.mapView.getWidth(), 0);
             Bounds b = new Bounds(bottomLeft, topRight);
+            
+            try {
+            	writeGenerated(b);
+            } catch(Exception ex) {
+            	//how handle the exception?
+            }
+            
 			CollectBackReferencesVisitor backRefsV =
 				new CollectBackReferencesVisitor(Main.ds, true);
             DataSet fromDataSet = new DataSet();
@@ -69,9 +78,9 @@
                 // get the exec line
                 String exec = firefox;
                 if (System.getProperty("os.name").startsWith("Windows"))
-                    exec += " 
file:///"+getPluginDir().replace('\\','/').replace(" ","%20")+"osm-map-features.xml\"";
+                    exec += " 
file:///"+getPluginDir().replace('\\','/').replace(" ","%20")+"generated.xml\"";
                 else
-                    exec += " "+getPluginDir()+"osm-map-features.xml";
+                    exec += " "+getPluginDir()+"generated.xml";
 
                 // launch up the viewer
                 Runtime.getRuntime().exec(exec);
@@ -135,4 +144,36 @@
             }
         };
     }
+    
+    private void writeGenerated(Bounds b) throws IOException {
+    	String bounds_tag = "<bounds " +
+    		"minlat=\"" + b.min.lat() + "\" " +
+    		"maxlat=\"" + b.max.lat() + "\" " +
+    		"minlon=\"" + b.min.lon() + "\" " +
+    		"maxlon=\"" + b.max.lon() + "\" " + "/>";
+    	
+    	BufferedReader reader = new BufferedReader(
+    			new FileReader( getPluginDir() + "osm-map-features.xml") );
+    	PrintWriter writer = new PrintWriter( getPluginDir() + "generated.xml");
+		
+		// osm-map-fetaures.xml contain two placemark
+		// (bounds_mkr1 and bounds_mkr2). We write the bounds tag
+		// between the two
+    	String str = null;
+    	while( (str = reader.readLine()) != null ) {
+    		if(str.contains("<!--bounds_mkr1-->")) {
+    			writer.println(str);
+    			writer.println("    " + bounds_tag);
+    			while(!str.contains("<!--bounds_mkr2-->")) {
+    				str = reader.readLine();
+    			}
+    			writer.println(str);
+    		} else {
+    			writer.println(str);
+    		}
+    	}
+
+    	writer.close();
+    }
 }
+
********** END **********

-- 
* Matteo Gottardi | matgott at tin.it
* ICQ UIN 20381372
* Linux - the choice of a GNU generation
* GPG Fingerprint:
* B9EE 108F 52C8 D50C B667 B1F2 AB56 8A01 BA3D 36A1


More information about the josm-dev mailing list