Index: applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapKey.java
===================================================================
--- applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapKey.java	(revision 16139)
+++ applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapKey.java	(revision 16153)
@@ -12,4 +12,5 @@
  * @author LuVar <lubomir.varga@freemap.sk>
  * @author Dave Hansen <dave@sr71.net>
+ * @author Dave Hansen <dave@linux.vnet.ibm.com>
  *
  */
@@ -29,5 +30,5 @@
 	 */
 	public final boolean valid;
-	public SlippyMapKey(int level, int x, int y) {
+	public SlippyMapKey(int x, int y, int level) {
 		this.x = x;
 		this.y = y;
Index: applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapLayer.java
===================================================================
--- applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapLayer.java	(revision 16139)
+++ applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapLayer.java	(revision 16153)
@@ -40,5 +40,6 @@
  * @author LuVar <lubomir.varga@freemap.sk>
  * @author Dave Hansen <dave@sr71.net>
- *
+ * @author Dave Hansen <dave@linux.vnet.ibm.com>
+ * 
  */
 public class SlippyMapLayer extends Layer implements ImageObserver,
@@ -279,5 +280,5 @@
         for (int x = z12x0 - 1; x <= z12x1; x++) {
             for (int y = z12y0 - 1; y <= z12y1; y++) {
-                SlippyMapKey key = new SlippyMapKey(currentZoomLevel, x, y);
+                SlippyMapKey key = new SlippyMapKey(x, y, currentZoomLevel);
                 SlippyMapTile tile = tileStorage.get(key);
                 if (!key.valid) {
@@ -295,19 +296,39 @@
     }
 
-    /*
-     * Attempt to approximate how much the image is
-     * being scaled.  For instance, a 100x100 image
-     * being scaled to 50x50 would return 0.25.
-     */
-    double getImageScaling(Image img, Point p0, Point p1)
-    {
-        int realWidth = img.getWidth(this);
-        int realHeight = img.getHeight(this);
-        if (realWidth == -1 || realHeight == -1)
-                return 1.0;
-        int drawWidth = p1.x - p0.x;
-        int drawHeight = p1.x - p0.x;
-
-        double drawArea = drawWidth * drawHeight;
+	/*
+	 * Attempt to approximate how much the image is being scaled. For instance,
+	 * a 100x100 image being scaled to 50x50 would return 0.25.
+	 */
+	Image lastScaledImage = null;
+
+	double getImageScaling(Image img, Point p0, Point p1) {
+		int realWidth = img.getWidth(this);
+		int realHeight = img.getHeight(this);
+		if (realWidth == -1 || realHeight == -1) {
+			/*
+			 * We need a good image against which to work. If
+			 * the current one isn't loaded, then try the last one.
+			 * Should be good enough. If we've never seen one, then
+			 * guess.        
+			 */
+			if (lastScaledImage != null) {
+				return getImageScaling(lastScaledImage, p0, p1);
+			}
+			realWidth = 256;
+			realHeight = 256;
+		} else {
+			lastScaledImage = img;
+		}
+		/*
+		 * If the zoom scale gets really, really off, these can get into
+		 * the millions, so make this a double to prevent integer
+		 * overflows.        
+		 */
+		double drawWidth = p1.x - p0.x;
+		double drawHeight = p1.x - p0.x;
+		// stem.out.println("drawWidth: " + drawWidth + " drawHeight: " +
+		// drawHeight);
+
+		double drawArea = drawWidth * drawHeight;
         double realArea = realWidth * realHeight;
 
@@ -384,5 +405,5 @@
         for (int x = z12x0 - 1; x <= z12x1; x++) {
             for (int y = z12y0 - 1; y <= z12y1; y++) {
-                SlippyMapKey key = new SlippyMapKey(currentZoomLevel, x, y);
+                SlippyMapKey key = new SlippyMapKey(x, y, currentZoomLevel);
                 SlippyMapTile tile;
                 tile = tileStorage.get(key);
@@ -532,5 +553,5 @@
         }
 
-        SlippyMapKey key = new SlippyMapKey(currentZoomLevel, tilex, tiley);
+        SlippyMapKey key = new SlippyMapKey(tilex, tiley, currentZoomLevel);
         if (!key.valid) {
             System.err.println("getTileForPixelpos("+px+","+py+") made invalid key");
@@ -561,5 +582,5 @@
                 new JSeparator(),
                 // color,
-                new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)),
+                new JMenuItem(new RenameLayerAction(this.getAssociatedFile(), this)),
                 new JSeparator(),
                 new JMenuItem(new LayerListPopup.InfoAction(this)) };
Index: applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapTile.java
===================================================================
--- applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapTile.java	(revision 16139)
+++ applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapTile.java	(revision 16153)
@@ -17,4 +17,5 @@
  * @author LuVar <lubomir.varga@freemap.sk>
  * @author Dave Hansen <dave@sr71.net>
+ * @author Dave Hansen <dave@linux.vnet.ibm.com>
  * 
  */
@@ -22,9 +23,11 @@
 {
     private Image  tileImage;
-	long timestamp;
+	private long timestamp;
 
-    int x;
-    int y;
-    int z;
+	private int x;
+	private int y;
+	private int z;
+    
+    private boolean imageDownloaded = false;
 
     private String metadata;
@@ -65,4 +68,8 @@
     }
 
+    public Image getImageNoTimestamp() {
+    	return tileImage;
+    }
+    
     public Image getImage()
     {
@@ -71,10 +78,32 @@
     }
 
+    public int getZoom() {
+    	return z;
+    }
+    
     public void dropImage()
     {
+		if(tileImage != null) {
+			tileImage.flush();
+		}
 		tileImage = null;
 		//  This should work in theory but doesn't seem to actually
 		//  reduce the X server memory usage
 		//tileImage.flush();
+    }
+    
+    public void markAsDownloaded() {
+    	imageDownloaded = true;
+    }
+    
+    public boolean isDownloaded() {
+    	return imageDownloaded;
+    }
+    
+    public void abortDownload() {
+    	if (imageDownloaded) {
+    		return;
+    	}
+    	dropImage();
     }
 
