de.aipark.api.tile.TileMapper Maven / Gradle / Ivy
package de.aipark.api.tile;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.geom.impl.CoordinateArraySequence;
import de.aipark.api.tile.Tile;
/**
* Created by torgen on 15.06.17.
*/
public class TileMapper {
/**
*
* @param tile
* @return left upper corner of given tile
*/
public static Point getLatLngFromTileIndex(Tile tile){
double lat, lng;
lat = Math.atan(Math.sinh(Math.PI- tile.getY()/Math.pow(2, tile.getZoom())*2*Math.PI))*180/Math.PI;
lng = tile.getX()/Math.pow(2, tile.getZoom())*360-180;
return new Point(new CoordinateArraySequence(new Coordinate[]{new Coordinate(lng,lat)}), new GeometryFactory());
}
/**
*
* @param point point
* @param zoom zoom level
* @return tile of this point with given zoom level
*/
public static Tile getTileIndexFromLatLng(Point point, int zoom){
double xtile = (point.getX() + 180) / 360 * (1<= (1<= (1<