Index: /utils/josm/plugins/ywms/resources/ymap.html
===================================================================
--- /utils/josm/plugins/ywms/resources/ymap.html	(revision 2282)
+++ /utils/josm/plugins/ywms/resources/ymap.html	(revision 2283)
@@ -34,5 +34,5 @@
         window.resizeTo(width,height);
     </script>
-    <script type="text/javascript" src="http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=YahooDemo"></script>
+    <script type="text/javascript" src="http://api.maps.yahoo.com/ajaxymap?v=3.4&appid=z7qRk3_V34HAbY_SkC7u7GAgG5nDTblw.cuL1OS5LWGwkIIUeGjg4qsnJDPpmhoF"></script>
   </head>
   
@@ -62,15 +62,42 @@
           // other map types work as well but only satellite allowed for use with OSM!
           var map = new YMap(document.getElementById("map"), YAHOO_MAP_SAT);
+          map.removeZoomScale();
           var zac = map.getBestZoomAndCenter(points);
           var level = zac.zoomLevel;
+           
+           // funny Yahoo bug seems to return 0 if your section is too small
+           if( level == 0 ) level = 1;
+           if (level>1) level--;
+           
+           map.drawZoomAndCenter(zac.YGeoPoint,level);
 
-          // funny Yahoo bug seems to return 0 if your section is too small
-          if (level==0) level=1;
-
-          map.drawZoomAndCenter(zac.YGeoPoint,level);
+		  // Get the on-screen coordinates of the points
+		  xy0 = map.convertLatLonXY(points[0]);
+		  xy1 = map.convertLatLonXY(points[1]);
+		  
+		  // Create a new size for the map. This makes the need of clipping the image unnecesary.
+		  new_width  = Math.abs( xy0.x - xy1.x);
+		  new_height = Math.abs( xy0.y - xy1.y);
+		  
+		  // Apply the new width-height
+          mapDiv.style.width  = new_width;
+          mapDiv.style.height = new_height;
+          map.resizeTo( new YSize(new_width, new_height));
+          
+		  /// DEBUG: colour the interesting area
+		  var cPT2 = new YGeoPoint(tllat, tllon); 
+		  var cPT3 = new YGeoPoint(tllat, brlon); 
+		  var cPT4 = new YGeoPoint(brlat, brlon); 
+		  var cPT5 = new YGeoPoint(brlat, tllon); 
+		  // args: array of pts, color, width, alpha 
+		  var poly1 = new YPolyline([cPT2,cPT3,cPT4,cPT5, cPT2],'blue',7,0.7); 
+		  //map.addOverlay(poly1);
+		 
           var bounds = map.getBoundsLatLon();
 
           // Dumps the actual bounding box
           dump("bbox=" + bounds.LonMin + "," + bounds.LatMin + "," + bounds.LonMax + "," + bounds.LatMax + "\n");
+          dump("new_width=" + new_width + "\n");
+          dump("new_height=" + new_height + "\n");
       }
     </script>
Index: /utils/josm/plugins/ywms/src/org/openstreetmap/josm/plugins/ywms/ImageLoader.java
===================================================================
--- /utils/josm/plugins/ywms/src/org/openstreetmap/josm/plugins/ywms/ImageLoader.java	(revision 2282)
+++ /utils/josm/plugins/ywms/src/org/openstreetmap/josm/plugins/ywms/ImageLoader.java	(revision 2283)
@@ -53,7 +53,8 @@
 	private URL yahooUrl;
 	double[] orig_bbox = null;
-	double[] final_bbox = null;
-	int width = -1;
-	int height = -1;
+    int width = -1;
+    int height = -1;
+    int final_width = -1;
+    int final_height = -1;
 	Image image;
 	List<String> firefoxFiles = new ArrayList<String>();
@@ -128,9 +129,12 @@
 	        {
 	        	System.out.println("YWMS::" + line);
-	            if( line.startsWith("bbox=") )
-	            {
-	            	final_bbox = getBbox(line);
-	                // System.out.println("YWMS::BBOX: (" + final_bbox[0] + "," + final_bbox[1] + "), (" + final_bbox[2] + "," + final_bbox[3] + ")");
-	            }
+                if( line.startsWith("new_width=") )
+                {
+                    final_width = (int)Math.round( Double.parseDouble( line.substring(10)) );
+                }
+                else if( line.startsWith("new_height=") )
+                {
+                    final_height = (int)Math.round( Double.parseDouble( line.substring(11)) );
+                }
 	            else if( line.startsWith(GECKO_DEBUG_LINE))
 	            {
@@ -168,11 +172,11 @@
 	        }
 
-	        if( final_bbox == null  && imageFilePpm == null && !firefoxFiles.isEmpty() )
+	        if( final_width == -1 && imageFilePpm == null && !firefoxFiles.isEmpty() )
 	        {
 	        	throw new ImageLoaderException("Is there any other firefox window open with same profile?");
 	        }
-	        if( final_bbox == null )
-	        {
-	        	throw new ImageLoaderException("Couldn't find bounding box. Is browser.dom.window.dump.enabled set in Firefox config?");
+	        if( final_width == -1)
+	        {
+	        	throw new ImageLoaderException("Couldn't find new dimension. Is browser.dom.window.dump.enabled set in Firefox config?");
 	        }
 	        if( imageFilePpm == null )
@@ -221,17 +225,10 @@
 	private void resizeImage() 
 	{
-		int calcwidth = (int)Math.round((final_bbox[2] - final_bbox[0]) * width / (orig_bbox[2] - orig_bbox[0]));
-		int calcheight = (int)Math.round((final_bbox[3] - final_bbox[1]) * height / (orig_bbox[3] - orig_bbox[1]));
-
-		int cropWidth = (calcwidth - width) / 2;
-		int cropHeight = (calcheight - height) / 2;
-	
 		Toolkit tk = Toolkit.getDefaultToolkit();
-        // save("/tmp/image_orig.jpg");
-        image = tk.createImage (new FilteredImageSource (image.getSource(), new CropImageFilter(0, 0, width, height)));
-        image = tk.createImage (new FilteredImageSource (image.getSource(), new ReplicateScaleFilter(calcwidth, calcheight)));
-        image = tk.createImage (new FilteredImageSource (image.getSource(), new CropImageFilter(cropWidth, cropHeight, width, height)));
-		// BufferedImage img = (BufferedImage)image.getScaledInstance(calcwidth, calcwidth, BufferedImage.SCALE_DEFAULT);
-		// image = img.getSubimage(cropl, cropt, width, height);
+        //save("/tmp/image_orig.png");
+        image = tk.createImage (new FilteredImageSource (image.getSource(), new CropImageFilter(0, 0, final_width, final_height)));
+        //save("/tmp/image_crop.png");
+        image = tk.createImage (new FilteredImageSource (image.getSource(), new ReplicateScaleFilter(width, height)));
+        //save("/tmp/image_scale.png");
 	}
 
@@ -265,9 +262,16 @@
 	 * @throws IOException When error saving the file
 	 */
-	public void save(String fileName) throws IOException
-	{
-        FileOutputStream fileStream = new FileOutputStream(fileName);
-        ImageIO.write(getBufferedImage(), "png", fileStream);
-        fileStream.close();
+	public void save(String fileName)
+	{
+        try
+        {
+            FileOutputStream fileStream = new FileOutputStream(fileName);
+            ImageIO.write(getBufferedImage(), "png", fileStream);
+            fileStream.close();
+        }
+        catch(Exception e)
+        {
+            e.printStackTrace();
+        }
 	}
 	
