@Test public void latitudeToPixelYTest() { for (int tileSize : TILE_SIZES) { for (byte zoomLevel = ZOOM_LEVEL_MIN; zoomLevel <= ZOOM_LEVEL_MAX; ++zoomLevel) { double pixelY = MercatorProjection.latitudeToPixelY(MercatorProjection.LATITUDE_MAX, zoomLevel, tileSize); Assert.assertEquals(0, pixelY, 0); pixelY = MercatorProjection.latitudeToPixelY(MercatorProjection.LATITUDE_MAX, MercatorProjection.zoomLevelToScaleFactor(zoomLevel), tileSize); Assert.assertEquals(0, pixelY, 0); long mapSize = MercatorProjection.getMapSize(zoomLevel, tileSize); pixelY = MercatorProjection.latitudeToPixelY(0, zoomLevel, tileSize); Assert.assertEquals((float) mapSize / 2, pixelY, 0); pixelY = MercatorProjection.latitudeToPixelY(0, MercatorProjection.zoomLevelToScaleFactor(zoomLevel), tileSize); Assert.assertEquals((float) mapSize / 2, pixelY, 0); pixelY = MercatorProjection.latitudeToPixelY(MercatorProjection.LATITUDE_MIN, zoomLevel, tileSize); Assert.assertEquals(mapSize, pixelY, 0); pixelY = MercatorProjection.latitudeToPixelY(MercatorProjection.LATITUDE_MIN, MercatorProjection.zoomLevelToScaleFactor(zoomLevel), tileSize); Assert.assertEquals(mapSize, pixelY, 0); } } }
public static double latitudeToPixelY(double latitude, double scaleFactor, int tileSize) { double sinLatitude = Math.sin(latitude * (Math.PI / 180)); long mapSize = getMapSize(scaleFactor, tileSize); double pixelY = (0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI)) * mapSize; return Math.min(Math.max(0, pixelY), mapSize); }
MercatorProjection { public static double latitudeToPixelY(double latitude, double scaleFactor, int tileSize) { double sinLatitude = Math.sin(latitude * (Math.PI / 180)); long mapSize = getMapSize(scaleFactor, tileSize); double pixelY = (0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI)) * mapSize; return Math.min(Math.max(0, pixelY), mapSize); } }
MercatorProjection { public static double latitudeToPixelY(double latitude, double scaleFactor, int tileSize) { double sinLatitude = Math.sin(latitude * (Math.PI / 180)); long mapSize = getMapSize(scaleFactor, tileSize); double pixelY = (0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI)) * mapSize; return Math.min(Math.max(0, pixelY), mapSize); } private  MercatorProjection(); }
MercatorProjection { public static double latitudeToPixelY(double latitude, double scaleFactor, int tileSize) { double sinLatitude = Math.sin(latitude * (Math.PI / 180)); long mapSize = getMapSize(scaleFactor, tileSize); double pixelY = (0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI)) * mapSize; return Math.min(Math.max(0, pixelY), mapSize); } private  MercatorProjection(); static double calculateGroundResolution(double latitude, double scaleFactor, int tileSize); static double calculateGroundResolution(double latitude, byte zoomLevel, int tileSize); static LatLong fromPixels(double pixelX, double pixelY, double scaleFactor, int tileSize); static LatLong fromPixels(double pixelX, double pixelY, byte zoomLevel, int tileSize); static long getMapSize(double scaleFactor, int tileSize); static long getMapSize(byte zoomLevel, int tileSize); static Point getPixel(LatLong latLong, double scaleFactor, int tileSize); static Point getPixel(LatLong latLong, byte zoomLevel, int tileSize); static double latitudeToPixelY(double latitude, double scaleFactor, int tileSize); static double latitudeToPixelY(double latitude, byte zoomLevel, int tileSize); static long latitudeToTileY(double latitude, double scaleFactor); static long latitudeToTileY(double latitude, byte zoomLevel); static double longitudeToPixelX(double longitude, double scaleFactor, int tileSize); static double longitudeToPixelX(double longitude, byte zoomLevel, int tileSize); static long longitudeToTileX(double longitude, double scaleFactor); static long longitudeToTileX(double longitude, byte zoomLevel); static double metersToPixels(float meters, double latitude, double scaleFactor, int tileSize); static double metersToPixels(float meters, double latitude, byte zoom, int tileSize); static double pixelXToLongitude(double pixelX, double scaleFactor, int tileSize); static double pixelXToLongitude(double pixelX, byte zoomLevel, int tileSize); static long pixelXToTileX(double pixelX, double scaleFactor, int tileSize); static long pixelXToTileX(double pixelX, byte zoomLevel, int tileSize); static double pixelYToLatitude(double pixelY, double scaleFactor, int tileSize); static double pixelYToLatitude(double pixelY, byte zoomLevel, int tileSize); static long pixelYToTileY(double pixelY, double scaleFactor, int tileSize); static long pixelYToTileY(double pixelY, byte zoomLevel, int tileSize); static double scaleFactorToZoomLevel(double scaleFactor); static long tileToPixel(long tileNumber, int tileSize); static double tileXToLongitude(long tileX, double scaleFactor); static double tileXToLongitude(long tileX, byte zoomLevel); static double tileYToLatitude(long tileY, double scaleFactor); static double tileYToLatitude(long tileY, byte zoomLevel); static double zoomLevelToScaleFactor(byte zoomLevel); }
MercatorProjection { public static double latitudeToPixelY(double latitude, double scaleFactor, int tileSize) { double sinLatitude = Math.sin(latitude * (Math.PI / 180)); long mapSize = getMapSize(scaleFactor, tileSize); double pixelY = (0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI)) * mapSize; return Math.min(Math.max(0, pixelY), mapSize); } private  MercatorProjection(); static double calculateGroundResolution(double latitude, double scaleFactor, int tileSize); static double calculateGroundResolution(double latitude, byte zoomLevel, int tileSize); static LatLong fromPixels(double pixelX, double pixelY, double scaleFactor, int tileSize); static LatLong fromPixels(double pixelX, double pixelY, byte zoomLevel, int tileSize); static long getMapSize(double scaleFactor, int tileSize); static long getMapSize(byte zoomLevel, int tileSize); static Point getPixel(LatLong latLong, double scaleFactor, int tileSize); static Point getPixel(LatLong latLong, byte zoomLevel, int tileSize); static double latitudeToPixelY(double latitude, double scaleFactor, int tileSize); static double latitudeToPixelY(double latitude, byte zoomLevel, int tileSize); static long latitudeToTileY(double latitude, double scaleFactor); static long latitudeToTileY(double latitude, byte zoomLevel); static double longitudeToPixelX(double longitude, double scaleFactor, int tileSize); static double longitudeToPixelX(double longitude, byte zoomLevel, int tileSize); static long longitudeToTileX(double longitude, double scaleFactor); static long longitudeToTileX(double longitude, byte zoomLevel); static double metersToPixels(float meters, double latitude, double scaleFactor, int tileSize); static double metersToPixels(float meters, double latitude, byte zoom, int tileSize); static double pixelXToLongitude(double pixelX, double scaleFactor, int tileSize); static double pixelXToLongitude(double pixelX, byte zoomLevel, int tileSize); static long pixelXToTileX(double pixelX, double scaleFactor, int tileSize); static long pixelXToTileX(double pixelX, byte zoomLevel, int tileSize); static double pixelYToLatitude(double pixelY, double scaleFactor, int tileSize); static double pixelYToLatitude(double pixelY, byte zoomLevel, int tileSize); static long pixelYToTileY(double pixelY, double scaleFactor, int tileSize); static long pixelYToTileY(double pixelY, byte zoomLevel, int tileSize); static double scaleFactorToZoomLevel(double scaleFactor); static long tileToPixel(long tileNumber, int tileSize); static double tileXToLongitude(long tileX, double scaleFactor); static double tileXToLongitude(long tileX, byte zoomLevel); static double tileYToLatitude(long tileY, double scaleFactor); static double tileYToLatitude(long tileY, byte zoomLevel); static double zoomLevelToScaleFactor(byte zoomLevel); static final double EARTH_CIRCUMFERENCE; static final double LATITUDE_MAX; static final double LATITUDE_MIN; }