Skip to content
Snippets Groups Projects

Adicionado as classes Tile e PointD

Merged Davisson Henrique Paulino requested to merge Modelagem into develop
2 files
+ 71
0
Compare changes
  • Side-by-side
  • Inline
Files
2
package ufpr.inf.pet.geoloc;
/**
* Created by vmocelin on 27/05/15.
*/
public class TilesManager {
private static double raioTerra = 6378137;
private double minLatitude;
private double maxLatitude;
private double minLongitude;
private double maxLongitude;
private int maxZoom = 5;
private int tamTile = 256;
private int viewWidth;
private int viewHeight;
private int tilesX;
private int tilesY;
private int zoom = 0;
private PointD location = new PointD();
private static double clip(double n, double minValue, double maxValue)
{
return Math.min(Math.max(n, minValue), maxValue);
}
public int tamanhoMapa(){
return (int) 256 << zoom;
}
public PointD longLatToXY(double latitude, double longitude){
latitude = clip(latitude, minLatitude, maxLatitude);
longitude = clip(longitude, minLongitude, maxLongitude);
double x = (longitude + 180) / 360;
double sinLatitude = Math.sin(latitude * Math.PI / 180);
double y = 0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI);
int mapSize = tamanhoMapa();
PointD pointD = new PointD();
pointD.setX((int) clip(x * mapSize + 0.5, 0, mapSize - 1));
pointD.setY((int) clip(y * mapSize + 0.5, 0, mapSize - 1));
return pointD;
}
public PointD xyToLongLat(int pixelX, int pixelY) {
double mapSize = tamanhoMapa();
double x = (clip(pixelX, 0, mapSize - 1) / mapSize) - 0.5;
double y = 0.5 - (clip(pixelY, 0, mapSize - 1) / mapSize);
PointD pointD = new PointD();
pointD.setX(90 - 360 * Math.atan(Math.exp(-y * 2 * Math.PI)) / Math.PI);
pointD.setY(360 * x);
return pointD;
}
public double getMinLatitude() {
return minLatitude;
}
public void setMinLatitude(double minLatitude) {
this.minLatitude = minLatitude;
}
public double getMaxLatitude() {
return maxLatitude;
}
public void setMaxLatitude(double maxLatitude) {
this.maxLatitude = maxLatitude;
}
public double getMinLongitude() {
return minLongitude;
}
public void setMinLongitude(double minLongitude) {
this.minLongitude = minLongitude;
}
public double getMaxLongitude() {
return maxLongitude;
}
public void setMaxLongitude(double maxLongitude) {
this.maxLongitude = maxLongitude;
}
public int getMaxZoom() {
return maxZoom;
}
public void setMaxZoom(int maxZoom) {
this.maxZoom = maxZoom;
}
public int getTamTile() {
return tamTile;
}
public void setTamTile(int tamTile) {
this.tamTile = tamTile;
}
public int getViewWidth() {
return viewWidth;
}
public void setViewWidth(int viewWidth) {
this.viewWidth = viewWidth;
}
public int getViewHeight() {
return viewHeight;
}
public void setViewHeight(int viewHeight) {
this.viewHeight = viewHeight;
}
public int getTilesX() {
return tilesX;
}
public void setTilesX(int tilesX) {
this.tilesX = tilesX;
}
public int getTilesY() {
return tilesY;
}
public void setTilesY(int tilesY) {
this.tilesY = tilesY;
}
public int getZoom() {
return zoom;
}
public void setZoom(int zoom) {
this.zoom = zoom;
}
public PointD getLocation() {
return location;
}
public void setLocation(PointD location) {
this.location = location;
}
}
Loading