@Test public void pixelXToLongitudeTest() { for (int tileSize : TILE_SIZES) { for (byte zoomLevel = ZOOM_LEVEL_MIN; zoomLevel <= ZOOM_LEVEL_MAX; ++zoomLevel) { long mapSize = MercatorProjection.getMapSize(zoomLevel, tileSize); double longitude = MercatorProjection.pixelXToLongitude(0, mapSize); Assert.assertEquals(LatLongUtils.LONGITUDE_MIN, longitude, 0); longitude = MercatorProjection.pixelXToLongitudeWithScaleFactor(0, MercatorProjection.zoomLevelToScaleFactor(zoomLevel), tileSize); Assert.assertEquals(LatLongUtils.LONGITUDE_MIN, longitude, 0); longitude = MercatorProjection.pixelXToLongitude((float) mapSize / 2, mapSize); Assert.assertEquals(0, longitude, 0); mapSize = MercatorProjection.getMapSizeWithScaleFactor(MercatorProjection.zoomLevelToScaleFactor(zoomLevel), tileSize); longitude = MercatorProjection.pixelXToLongitudeWithScaleFactor((float) mapSize / 2, MercatorProjection.zoomLevelToScaleFactor(zoomLevel), tileSize); Assert.assertEquals(0, longitude, 0); longitude = MercatorProjection.pixelXToLongitude(mapSize, mapSize); Assert.assertEquals(LatLongUtils.LONGITUDE_MAX, longitude, 0); longitude = MercatorProjection.pixelXToLongitudeWithScaleFactor(mapSize, MercatorProjection.zoomLevelToScaleFactor(zoomLevel), tileSize); Assert.assertEquals(LatLongUtils.LONGITUDE_MAX, longitude, 0); } verifyInvalidPixelXToLongitude(-1, (byte) 0, tileSize); verifyInvalidPixelXToLongitude(tileSize + 1, (byte) 0, tileSize); } }
public static double pixelXToLongitude(double pixelX, long mapSize) { if (pixelX < 0 || pixelX > mapSize) { throw new IllegalArgumentException("invalid pixelX coordinate " + mapSize + ": " + pixelX); } return 360 * ((pixelX / mapSize) - 0.5); }
MercatorProjection { public static double pixelXToLongitude(double pixelX, long mapSize) { if (pixelX < 0 || pixelX > mapSize) { throw new IllegalArgumentException("invalid pixelX coordinate " + mapSize + ": " + pixelX); } return 360 * ((pixelX / mapSize) - 0.5); } }
MercatorProjection { public static double pixelXToLongitude(double pixelX, long mapSize) { if (pixelX < 0 || pixelX > mapSize) { throw new IllegalArgumentException("invalid pixelX coordinate " + mapSize + ": " + pixelX); } return 360 * ((pixelX / mapSize) - 0.5); } private  MercatorProjection(); }
MercatorProjection { public static double pixelXToLongitude(double pixelX, long mapSize) { if (pixelX < 0 || pixelX > mapSize) { throw new IllegalArgumentException("invalid pixelX coordinate " + mapSize + ": " + pixelX); } return 360 * ((pixelX / mapSize) - 0.5); } private  MercatorProjection(); static double calculateGroundResolutionWithScaleFactor(double latitude, double scaleFactor, int tileSize); static double calculateGroundResolution(double latitude, long mapSize); static LatLong fromPixelsWithScaleFactor(double pixelX, double pixelY, double scaleFactor, int tileSize); static LatLong fromPixels(double pixelX, double pixelY, long mapSize); static long getMapSizeWithScaleFactor(double scaleFactor, int tileSize); static long getMapSize(byte zoomLevel, int tileSize); static Point getPixelWithScaleFactor(LatLong latLong, double scaleFactor, int tileSize); static Point getPixel(LatLong latLong, long mapSize); static Point getPixelAbsolute(LatLong latLong, long mapSize); static Point getPixelRelative(LatLong latLong, long mapSize, double x, double y); static Point getPixelRelative(LatLong latLong, long mapSize, Point origin); static Point getPixelRelativeToTile(LatLong latLong, Tile tile); static double latitudeToPixelYWithScaleFactor(double latitude, double scaleFactor, int tileSize); static double latitudeToPixelY(double latitude, byte zoomLevel, int tileSize); static double latitudeToPixelY(double latitude, long mapSize); static int latitudeToTileYWithScaleFactor(double latitude, double scaleFactor); static int latitudeToTileY(double latitude, byte zoomLevel); static double longitudeToPixelXWithScaleFactor(double longitude, double scaleFactor, int tileSize); static double longitudeToPixelX(double longitude, byte zoomLevel, int tileSize); static double longitudeToPixelX(double longitude, long mapSize); static int longitudeToTileXWithScaleFactor(double longitude, double scaleFactor); static int longitudeToTileX(double longitude, byte zoomLevel); static double metersToPixelsWithScaleFactor(float meters, double latitude, double scaleFactor, int tileSize); static double metersToPixels(float meters, double latitude, long mapSize); static double pixelXToLongitudeWithScaleFactor(double pixelX, double scaleFactor, int tileSize); static double pixelXToLongitude(double pixelX, long mapSize); static int pixelXToTileXWithScaleFactor(double pixelX, double scaleFactor, int tileSize); static int pixelXToTileX(double pixelX, byte zoomLevel, int tileSize); static double pixelYToLatitudeWithScaleFactor(double pixelY, double scaleFactor, int tileSize); static double pixelYToLatitude(double pixelY, long mapSize); static int pixelYToTileYWithScaleFactor(double pixelY, double scaleFactor, int tileSize); static int pixelYToTileY(double pixelY, byte zoomLevel, int tileSize); static double scaleFactorToZoomLevel(double scaleFactor); static long tileToPixel(long tileNumber, int tileSize); static double tileXToLongitudeWithScaleFactor(long tileX, double scaleFactor); static double tileXToLongitude(long tileX, byte zoomLevel); static double tileYToLatitudeWithScaleFactor(long tileY, double scaleFactor); static double tileYToLatitude(long tileY, byte zoomLevel); static double zoomLevelToScaleFactor(byte zoomLevel); }
MercatorProjection { public static double pixelXToLongitude(double pixelX, long mapSize) { if (pixelX < 0 || pixelX > mapSize) { throw new IllegalArgumentException("invalid pixelX coordinate " + mapSize + ": " + pixelX); } return 360 * ((pixelX / mapSize) - 0.5); } private  MercatorProjection(); static double calculateGroundResolutionWithScaleFactor(double latitude, double scaleFactor, int tileSize); static double calculateGroundResolution(double latitude, long mapSize); static LatLong fromPixelsWithScaleFactor(double pixelX, double pixelY, double scaleFactor, int tileSize); static LatLong fromPixels(double pixelX, double pixelY, long mapSize); static long getMapSizeWithScaleFactor(double scaleFactor, int tileSize); static long getMapSize(byte zoomLevel, int tileSize); static Point getPixelWithScaleFactor(LatLong latLong, double scaleFactor, int tileSize); static Point getPixel(LatLong latLong, long mapSize); static Point getPixelAbsolute(LatLong latLong, long mapSize); static Point getPixelRelative(LatLong latLong, long mapSize, double x, double y); static Point getPixelRelative(LatLong latLong, long mapSize, Point origin); static Point getPixelRelativeToTile(LatLong latLong, Tile tile); static double latitudeToPixelYWithScaleFactor(double latitude, double scaleFactor, int tileSize); static double latitudeToPixelY(double latitude, byte zoomLevel, int tileSize); static double latitudeToPixelY(double latitude, long mapSize); static int latitudeToTileYWithScaleFactor(double latitude, double scaleFactor); static int latitudeToTileY(double latitude, byte zoomLevel); static double longitudeToPixelXWithScaleFactor(double longitude, double scaleFactor, int tileSize); static double longitudeToPixelX(double longitude, byte zoomLevel, int tileSize); static double longitudeToPixelX(double longitude, long mapSize); static int longitudeToTileXWithScaleFactor(double longitude, double scaleFactor); static int longitudeToTileX(double longitude, byte zoomLevel); static double metersToPixelsWithScaleFactor(float meters, double latitude, double scaleFactor, int tileSize); static double metersToPixels(float meters, double latitude, long mapSize); static double pixelXToLongitudeWithScaleFactor(double pixelX, double scaleFactor, int tileSize); static double pixelXToLongitude(double pixelX, long mapSize); static int pixelXToTileXWithScaleFactor(double pixelX, double scaleFactor, int tileSize); static int pixelXToTileX(double pixelX, byte zoomLevel, int tileSize); static double pixelYToLatitudeWithScaleFactor(double pixelY, double scaleFactor, int tileSize); static double pixelYToLatitude(double pixelY, long mapSize); static int pixelYToTileYWithScaleFactor(double pixelY, double scaleFactor, int tileSize); static int pixelYToTileY(double pixelY, byte zoomLevel, int tileSize); static double scaleFactorToZoomLevel(double scaleFactor); static long tileToPixel(long tileNumber, int tileSize); static double tileXToLongitudeWithScaleFactor(long tileX, double scaleFactor); static double tileXToLongitude(long tileX, byte zoomLevel); static double tileYToLatitudeWithScaleFactor(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; }