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 16156)
+++ /applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapLayer.java	(revision 16157)
@@ -127,4 +127,15 @@
                     }
                 }));
+        
+        tileOptionMenu.add(new JMenuItem(
+        		new AbstractAction(tr("Flush Tile Cache")) {
+        			public void actionPerformed(ActionEvent ae) {
+        				System.out.print("flushing all tiles...");
+        				for (SlippyMapTile t : tileStorage.values()) {
+        					t.dropImage();
+        					}
+        				System.out.println("done");
+        				}
+        			}));
         // end of adding menu commands
 
@@ -161,6 +172,8 @@
     /**
      * Zoom in, go closer to map.
+     * 
+     * @return	true, if zoom increasing was successfull, false othervise
      */
-    public void increaseZoomLevel() {
+    public boolean increaseZoomLevel() {
         if (currentZoomLevel < SlippyMapPreferences.getMaxZoomLvl()) {
             currentZoomLevel++;
@@ -170,11 +183,15 @@
             System.err.println("current zoom lvl ("+currentZoomLevel+") couldnt be increased. "+
                              "MaxZoomLvl ("+SlippyMapPreferences.getMaxZoomLvl()+") reached.");
-        }
+            return false;
+            }
+        return true;
     }
 
     /**
      * Zoom out from map.
+     * 
+     * @return	true, if zoom increasing was successfull, false othervise
      */
-    public void decreaseZoomLevel() {
+    public boolean decreaseZoomLevel() {
         if (currentZoomLevel > SlippyMapPreferences.getMinZoomLvl()) {
             Main.debug("decreasing zoom level to: " + currentZoomLevel);
@@ -183,5 +200,7 @@
         } else {
             System.err.println("current zoom lvl couldnt be decreased. MinZoomLvl reached.");
-        }
+            return false;
+        }
+        return true;
     }
 
@@ -249,10 +268,11 @@
     void loadAllTiles() {
         MapView mv = Main.map.mapView;
+        int zoom = currentZoomLevel;
         LatLon topLeft = mv.getLatLon(0, 0);
         LatLon botRight = mv.getLatLon(mv.getWidth(), mv.getHeight());
-        z12x0 = lonToTileX(topLeft.lon());
-        z12x1 = lonToTileX(botRight.lon());
-        z12y0 = latToTileY(topLeft.lat());
-        z12y1 = latToTileY(botRight.lat());
+        z12x0 = lonToTileX(topLeft.lon(), zoom);
+        z12x1 = lonToTileX(botRight.lon(), zoom);
+        z12y0 = latToTileY(topLeft.lat(), zoom);
+        z12y1 = latToTileY(botRight.lat(), zoom);
         if (z12x0 > z12x1) {
             int tmp = z12x0;
@@ -365,8 +385,9 @@
         g = bufferImage.getGraphics();
 
-        z12x0 = lonToTileX(topLeft.lon());
-        z12x1 = lonToTileX(botRight.lon());
-        z12y0 = latToTileY(topLeft.lat());
-        z12y1 = latToTileY(botRight.lat());
+        int zoom = currentZoomLevel;
+        z12x0 = lonToTileX(topLeft.lon(), zoom);
+        z12x1 = lonToTileX(botRight.lon(), zoom);
+        z12y0 = latToTileY(topLeft.lat(), zoom);
+        z12y1 = latToTileY(botRight.lat(), zoom);
 
         if (z12x0 > z12x1) {
@@ -387,7 +408,7 @@
 
         for (int x = z12x0 - 1; x <= z12x1 + 1; x++) {
-            double lon = tileXToLon(x);
+            double lon = tileXToLon(x, zoom);
             for (int y = z12y0 - 1; y <= z12y1 + 1; y++) {
-                LatLon tmpLL = new LatLon(tileYToLat(y), lon);
+                LatLon tmpLL = new LatLon(tileYToLat(y, zoom), lon);
                 pixelpos[x - z12x0 + 1][y - z12y0 + 1] = mv.getPoint(Main.proj
                         .latlon2eastNorth(tmpLL));
@@ -605,22 +626,22 @@
     }
 
-    private int latToTileY(double lat) {
+    private int latToTileY(double lat, int zoom) {
         double l = lat / 180 * Math.PI;
         double pf = Math.log(Math.tan(l) + (1 / Math.cos(l)));
-        return (int) (Math.pow(2.0, currentZoomLevel - 1) * (Math.PI - pf) / Math.PI);
-    }
-
-    private int lonToTileX(double lon) {
-        return (int) (Math.pow(2.0, currentZoomLevel - 3) * (lon + 180.0) / 45.0);
-    }
-
-    private double tileYToLat(int y) {
+        return (int) (Math.pow(2.0, zoom - 1) * (Math.PI - pf) / Math.PI);
+    }
+
+    private int lonToTileX(double lon, int zoom) {
+    	return (int) (Math.pow(2.0, zoom - 3) * (lon + 180.0) / 45.0);
+    }
+
+    private double tileYToLat(int y, int zoom) {
         return Math.atan(Math.sinh(Math.PI
-                - (Math.PI * y / Math.pow(2.0, currentZoomLevel - 1))))
+        		- (Math.PI * y / Math.pow(2.0, zoom - 1))))
                 * 180 / Math.PI;
     }
 
-    private double tileXToLon(int x) {
-        return x * 45.0 / Math.pow(2.0, currentZoomLevel - 3) - 180.0;
+    private double tileXToLon(int x, int zoom) {
+    	return x * 45.0 / Math.pow(2.0, zoom - 3) - 180.0;
     }
 
