Index: trunk/src/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSource.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSource.java	(revision 9152)
+++ trunk/src/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSource.java	(revision 9167)
@@ -16,5 +16,4 @@
 import java.util.regex.Pattern;
 
-import org.openstreetmap.gui.jmapviewer.OsmMercator;
 import org.openstreetmap.gui.jmapviewer.Tile;
 import org.openstreetmap.gui.jmapviewer.TileXY;
@@ -23,5 +22,5 @@
 import org.openstreetmap.gui.jmapviewer.tilesources.TMSTileSource;
 import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.data.Bounds;
+import org.openstreetmap.josm.data.ProjectionBounds;
 import org.openstreetmap.josm.data.coor.EastNorth;
 import org.openstreetmap.josm.data.coor.LatLon;
@@ -40,5 +39,4 @@
     private final Set<String> serverProjections;
     private EastNorth topLeftCorner;
-    private Bounds worldBounds;
     private int[] tileXMax;
     private int[] tileYMax;
@@ -96,10 +94,10 @@
      */
     public void initProjection(Projection proj) {
-        this.worldBounds = getWorldBounds();
-        EastNorth min = proj.latlon2eastNorth(worldBounds.getMin());
-        EastNorth max = proj.latlon2eastNorth(worldBounds.getMax());
+        ProjectionBounds worldBounds = proj.getWorldBoundsBoxEastNorth();
+        EastNorth min = worldBounds.getMin();
+        EastNorth max = worldBounds.getMax();
         this.topLeftCorner = new EastNorth(min.east(), max.north());
 
-        LatLon bottomRight = new LatLon(worldBounds.getMinLat(), worldBounds.getMaxLon());
+        EastNorth bottomRight = new EastNorth(worldBounds.getMax().east(), worldBounds.getMin().north());
 
         // use 256 as "tile size" to keep the scale in line with default tiles in Mercator projection
@@ -113,5 +111,5 @@
             // this makes the zoom levels "glued" to standard TMS zoom levels
             degreesPerTile[zoom] = (SCALE_DENOMINATOR_ZOOM_LEVEL_1 / Math.pow(2, zoom - 1)) * crsScale;
-            TileXY maxTileIndex = latLonToTileXY(bottomRight.toCoordinate(), zoom);
+            TileXY maxTileIndex = eastNorthToTileXY(bottomRight, zoom);
             tileXMax[zoom] = maxTileIndex.getXIndex();
             tileYMax[zoom] = maxTileIndex.getYIndex();
@@ -243,4 +241,8 @@
         Projection proj = Main.getProjection();
         EastNorth enPoint = proj.latlon2eastNorth(new LatLon(lat, lon));
+        return eastNorthToTileXY(enPoint, zoom);
+    }
+
+    private TileXY eastNorthToTileXY(EastNorth enPoint, int zoom) {
         double scale = getDegreesPerTile(zoom);
         return new TileXY(
@@ -356,23 +358,3 @@
         return degreesPerTile[zoom];
     }
-
-    /**
-     * returns world bounds, but detect situation, when default bounds are provided (-90, -180, 90, 180), and projection
-     * returns very close values for both min and max X. To work around this problem, cap this projection on north and south
-     * pole, the same way they are capped in Mercator projection, so conversions should work properly
-     */
-    private static Bounds getWorldBounds() {
-        Projection proj = Main.getProjection();
-        Bounds bounds = proj.getWorldBoundsLatLon();
-        EastNorth min = proj.latlon2eastNorth(bounds.getMin());
-        EastNorth max = proj.latlon2eastNorth(bounds.getMax());
-
-        if (Math.abs(min.getX() - max.getX()) < 1 && bounds.equals(new Bounds(new LatLon(-90, -180), new LatLon(90, 180)))) {
-            return new Bounds(
-                    new LatLon(OsmMercator.MIN_LAT, bounds.getMinLon()),
-                    new LatLon(OsmMercator.MAX_LAT, bounds.getMaxLon())
-                    );
-        }
-        return bounds;
-    }
 }
