/** * Converts a tile Y number at a certain scale to a latitude coordinate. * * @param tileY the tile Y number that should be converted. * @param scaleFactor the scale factor at which the number should be converted. * @return the latitude value of the tile Y number. */ public static double tileYToLatitudeWithScaleFactor(long tileY, double scaleFactor) { return pixelYToLatitudeWithScaleFactor(tileY * DUMMY_TILE_SIZE, scaleFactor, DUMMY_TILE_SIZE); }
/** * Get LatLong from Pixels. */ public static LatLong fromPixelsWithScaleFactor(double pixelX, double pixelY, double scaleFactor, int tileSize) { return new LatLong(pixelYToLatitudeWithScaleFactor(pixelY, scaleFactor, tileSize), pixelXToLongitudeWithScaleFactor(pixelX, scaleFactor, tileSize)); }
/** * Converts a tile Y number at a certain scale to a latitude coordinate. * * @param tileY the tile Y number that should be converted. * @param scaleFactor the scale factor at which the number should be converted. * @return the latitude value of the tile Y number. */ public static double tileYToLatitudeWithScaleFactor(long tileY, double scaleFactor) { return pixelYToLatitudeWithScaleFactor(tileY * DUMMY_TILE_SIZE, scaleFactor, DUMMY_TILE_SIZE); }
@Test public void pixelYToLatitudeTest() { for (int tileSize : TILE_SIZES) { for (byte zoomLevel = ZOOM_LEVEL_MIN; zoomLevel <= ZOOM_LEVEL_MAX; ++zoomLevel) { long mapSize = MercatorProjection.getMapSize(zoomLevel, tileSize); double latitude = MercatorProjection.pixelYToLatitude(0, mapSize); Assert.assertEquals(MercatorProjection.LATITUDE_MAX, latitude, 0); latitude = MercatorProjection.pixelYToLatitudeWithScaleFactor(0, MercatorProjection.zoomLevelToScaleFactor(zoomLevel), tileSize); Assert.assertEquals(MercatorProjection.LATITUDE_MAX, latitude, 0); latitude = MercatorProjection.pixelYToLatitude((float) mapSize / 2, mapSize); Assert.assertEquals(0, latitude, 0); mapSize = MercatorProjection.getMapSizeWithScaleFactor(MercatorProjection.zoomLevelToScaleFactor(zoomLevel), tileSize); latitude = MercatorProjection.pixelYToLatitudeWithScaleFactor((float) mapSize / 2, MercatorProjection.zoomLevelToScaleFactor(zoomLevel), tileSize); Assert.assertEquals(0, latitude, 0); latitude = MercatorProjection.pixelYToLatitude(mapSize, mapSize); Assert.assertEquals(MercatorProjection.LATITUDE_MIN, latitude, 0); latitude = MercatorProjection.pixelYToLatitudeWithScaleFactor(mapSize, MercatorProjection.zoomLevelToScaleFactor(zoomLevel), tileSize); Assert.assertEquals(MercatorProjection.LATITUDE_MIN, latitude, 0); } verifyInvalidPixelYToLatitude(-1, (byte) 0, tileSize); verifyInvalidPixelYToLatitude(tileSize + 1, (byte) 0, tileSize); } }
/** * Get LatLong from Pixels. */ public static LatLong fromPixelsWithScaleFactor(double pixelX, double pixelY, double scaleFactor, int tileSize) { return new LatLong(pixelYToLatitudeWithScaleFactor(pixelY, scaleFactor, tileSize), pixelXToLongitudeWithScaleFactor(pixelX, scaleFactor, tileSize)); }