Index: applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/ImageryLayer.java
===================================================================
--- applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/ImageryLayer.java	(revision 24540)
+++ applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/ImageryLayer.java	(revision 24541)
@@ -6,4 +6,5 @@
 import javax.swing.ImageIcon;
 
+import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.ProjectionBounds;
 import org.openstreetmap.josm.gui.MapView;
@@ -23,4 +24,5 @@
     public ImageryLayer(String name) {
         super(name);
+        mv = Main.map.mapView;
     }
 
Index: applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/tms/TMSLayer.java
===================================================================
--- applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/tms/TMSLayer.java	(revision 24540)
+++ applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/tms/TMSLayer.java	(revision 24541)
@@ -53,6 +53,6 @@
 import org.openstreetmap.josm.gui.layer.Layer;
 import org.openstreetmap.josm.plugins.imagery.ImageryInfo;
+import org.openstreetmap.josm.plugins.imagery.ImageryLayer;
 import org.openstreetmap.josm.plugins.imagery.ImageryInfo.ImageryType;
-import org.openstreetmap.josm.plugins.imagery.ImageryLayer;
 
 /**
@@ -134,7 +134,6 @@
     }
 
-    private void setTileStorage(TileSource tileSource)
-    {
-        int origZoom = currentZoomLevel;
+    private void initTileSource(TileSource tileSource)
+    {
         this.tileSource = tileSource;
         boolean requireAttr = tileSource.requiresAttribution();
@@ -150,15 +149,9 @@
         }
 
-        // The minimum should also take care of integer parsing
-        // errors which would leave us with a zoom of -1 otherwise
+        currentZoomLevel = getBestZoom();
         if (tileSource.getMaxZoom() < currentZoomLevel)
             currentZoomLevel = tileSource.getMaxZoom();
         if (tileSource.getMinZoom() > currentZoomLevel)
             currentZoomLevel = tileSource.getMinZoom();
-        if (currentZoomLevel != origZoom) {
-            out("changed currentZoomLevel loading new tile store from " + origZoom + " to " + currentZoomLevel);
-            out("tileSource.getMinZoom(): " + tileSource.getMinZoom());
-            out("tileSource.getMaxZoom(): " + tileSource.getMaxZoom());
-        }
         clearTileCache();
         //tileloader = new OsmTileLoader(this);
@@ -172,4 +165,14 @@
     }
 
+    private double getPPDeg() {
+        return mv.getWidth()/(mv.getLatLon(mv.getWidth(), mv.getHeight()/2).lon()-mv.getLatLon(0, mv.getHeight()/2).lon());
+    }
+
+    private int getBestZoom() {
+        double ret = Math.log(getPPDeg()*360/tileSource.getTileSize())/Math.log(2);
+        System.out.println("Detected best zoom " + ret);
+        return (int)Math.round(ret);
+    }
+
     @SuppressWarnings("serial")
     public TMSLayer(ImageryInfo info) {
@@ -179,14 +182,11 @@
         this.setVisible(true);
 
-        currentZoomLevel = TMSPreferences.getMinZoomLvl(null); //FIXME: detect current zoom level
-
         if (info.getImageryType() == ImageryType.TMS) {
-            setTileStorage(new TMSTileSource(info.getName(),info.getURL()));
+            initTileSource(new TMSTileSource(info.getName(),info.getURL()));
         } else if (info.getImageryType() == ImageryType.BING) {
-            setTileStorage(new BingAerialTileSource());
+            initTileSource(new BingAerialTileSource());
         } else throw new AssertionError();
 
         tileOptionMenu = new JPopupMenu();
-
 
         autoZoom = TMSPreferences.PROP_DEFAULT_AUTOZOOM.get();
@@ -783,11 +783,14 @@
     }
 
-    public Point pixelPos(LatLon ll) {
+    private Point pixelPos(LatLon ll) {
         return Main.map.mapView.getPoint(Main.proj.latlon2eastNorth(ll).add(getDx(), getDy()));
     }
-    public Point pixelPos(Tile t) {
+    private Point pixelPos(Tile t) {
         double lon = tileXToLon(t.getXtile(), t.getZoom());
         LatLon tmpLL = new LatLon(tileYToLat(t.getYtile(), t.getZoom()), lon);
         return pixelPos(tmpLL);
+    }
+    private LatLon getShiftedLatLon(EastNorth en) {
+        return Main.proj.eastNorth2latlon(en.add(-getDx(), -getDy()));
     }
     private class TileSet {
@@ -800,6 +803,5 @@
          */
         TileSet(EastNorth topLeft, EastNorth botRight, int zoom) {
-            this(Main.proj.eastNorth2latlon(topLeft.add(-getDx(), -getDy())),
-                 Main.proj.eastNorth2latlon(botRight.add(-getDx(), -getDy())),zoom);
+            this(getShiftedLatLon(topLeft), getShiftedLatLon(botRight),zoom);
         }
 
@@ -1039,5 +1041,5 @@
             g.setFont(ATTR_FONT);
             String attributionText = tileSource.getAttributionText(currentZoomLevel,
-                    Main.proj.eastNorth2latlon(topLeft), Main.proj.eastNorth2latlon(botRight));
+                    getShiftedLatLon(topLeft), getShiftedLatLon(botRight));
             Rectangle2D stringBounds = g.getFontMetrics().getStringBounds(attributionText, g);
             {
Index: applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/wms/WMSLayer.java
===================================================================
--- applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/wms/WMSLayer.java	(revision 24540)
+++ applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/wms/WMSLayer.java	(revision 24541)
@@ -105,5 +105,4 @@
         initializeImages();
         this.info = new ImageryInfo(info);
-        mv = Main.map.mapView;
         if(this.info.getPixelPerDegree() == 0.0)
             this.info.setPixelPerDegree(getPPD());
