Index: applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java
===================================================================
--- applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java	(revision 35056)
+++ applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java	(revision 35190)
@@ -56,5 +56,5 @@
 
     /** Maximum zoom level */
-    public static final int MAX_ZOOM = 22;
+    public static final int MAX_ZOOM = 24;
     /** Minimum zoom level */
     public static final int MIN_ZOOM = 0;
Index: applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmMercator.java
===================================================================
--- applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmMercator.java	(revision 35056)
+++ applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmMercator.java	(revision 35190)
@@ -29,6 +29,6 @@
     public static final OsmMercator MERCATOR_256 = new OsmMercator();
 
-    /** tile size of the displayed tiles */
-    private int tileSize = DEFAUL_TILE_SIZE;
+    /** tile size of the displayed tiles. Use long so all calculations will be in 64bit to properly handle zooms above 22 for 256 tile size */
+    private long tileSize = DEFAUL_TILE_SIZE;
 
     /**
@@ -57,13 +57,13 @@
      * @return number of pixels
      */
-    public int getMaxPixels(int aZoomlevel) {
+    public long getMaxPixels(int aZoomlevel) {
         return tileSize * (1 << aZoomlevel);
     }
 
-    public int falseEasting(int aZoomlevel) {
+    public long falseEasting(int aZoomlevel) {
         return getMaxPixels(aZoomlevel) / 2;
     }
 
-    public int falseNorthing(int aZoomlevel) {
+    public long falseNorthing(int aZoomlevel) {
         return -1 * getMaxPixels(aZoomlevel) / 2;
     }
@@ -80,5 +80,5 @@
      * @return the distance
      */
-    public double getDistance(int x1, int y1, int x2, int y2, int zoomLevel) {
+    public double getDistance(long x1, long y1, long x2, long y2, int zoomLevel) {
         double la1 = yToLat(y1, zoomLevel);
         double lo1 = xToLon(x1, zoomLevel);
@@ -130,5 +130,5 @@
      */
     public double lonToX(double aLongitude, int aZoomlevel) {
-        int mp = getMaxPixels(aZoomlevel);
+        long mp = getMaxPixels(aZoomlevel);
         double x = (mp * (aLongitude + 180L)) / 360L;
         return Math.min(x, mp);
@@ -160,5 +160,5 @@
         double sinLat = Math.sin(Math.toRadians(aLat));
         double log = Math.log((1.0 + sinLat) / (1.0 - sinLat));
-        int mp = getMaxPixels(aZoomlevel);
+        long mp = getMaxPixels(aZoomlevel);
         double y = mp * (0.5 - (log / (4.0 * Math.PI)));
         return Math.min(y, mp - 1);
@@ -183,5 +183,5 @@
      * @return ]-180..180[
      */
-    public double xToLon(int aX, int aZoomlevel) {
+    public double xToLon(long aX, int aZoomlevel) {
         return ((360d * aX) / getMaxPixels(aZoomlevel)) - 180.0;
     }
@@ -195,7 +195,6 @@
      * @return [MIN_LAT..MAX_LAT] is about [-85..85]
      */
-    public double yToLat(int aY, int aZoomlevel) {
-        aY += falseNorthing(aZoomlevel);
-        double latitude = (Math.PI / 2) - (2 * Math.atan(Math.exp(-1.0 * aY / radius(aZoomlevel))));
+    public double yToLat(long aY, int aZoomlevel) {
+        double latitude = (Math.PI / 2) - (2 * Math.atan(Math.exp(-1.0 * (aY + falseNorthing(aZoomlevel)) / radius(aZoomlevel))));
         return -1 * Math.toDegrees(latitude);
     }
Index: applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTMSTileSource.java
===================================================================
--- applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTMSTileSource.java	(revision 35056)
+++ applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTMSTileSource.java	(revision 35190)
@@ -12,4 +12,5 @@
 import java.util.Set;
 
+import org.openstreetmap.gui.jmapviewer.JMapViewer;
 import org.openstreetmap.gui.jmapviewer.OsmMercator;
 import org.openstreetmap.gui.jmapviewer.Tile;
@@ -73,10 +74,10 @@
     @Override
     public int getMaxZoom() {
-        return 21;
+        return JMapViewer.MAX_ZOOM;
     }
 
     @Override
     public int getMinZoom() {
-        return 0;
+        return JMapViewer.MIN_ZOOM;
     }
 
