Commit bf4d4990 authored by Vytor Calixto's avatar Vytor Calixto 👾
Browse files

Adicionada 3 novas funções a TileManager

PointD calcRatio(double, double) que retorna um ponto com valores entre 0 e 1
Point getTileXY(double, double) que retorna o indice da tile nas coordenadas específicas
atualizaAreaVisivel(double, double, int) que atualiza a área visível
parent ac26b581
package ufpr.inf.pet.geoloc;
import android.graphics.Point;
import android.graphics.Rect;
/**
* Created by vmocelin on 27/05/15.
*/
......@@ -16,13 +19,61 @@ public class TilesManager {
private int tilesX;
private int tilesY;
private int zoom = 0;
private PointD location = new PointD();
private PointD location = new PointD(0,0);
private Rect areaVisivel;
public TilesManager(int tamTile, int viewWidth, int viewHeight) {
this.tamTile = tamTile;
this.viewHeight = viewHeight;
this.viewWidth = viewWidth;
tilesX = (int) ((float) viewWidth / tamTile);
tilesY = (int) ((float) viewHeight / tamTile);
atualizaAreaVisivel(location.getX(), location.getY(), zoom);
}
private void atualizaAreaVisivel(double longitude, double latitude, int zoom) {
location.setX(longitude);
location.setY(latitude);
this.zoom = zoom;
Point tileId = getTileXY(location.getX(), location.getY());
int meioTileX = (int) ((float) (tilesX + 1)/2f);
int meioTileY = (int) ((float) (tilesY + 1)/2f);
areaVisivel = new Rect(tileId.x - meioTileX, tileId.y - meioTileY, tileId.x + meioTileX, tileId.y + meioTileY);
}
private static double clip(double n, double minValue, double maxValue)
{
return Math.min(Math.max(n, minValue), maxValue);
}
// Retorna um ponto, cujas coordenadas variam de 0 a 1, dando assim uma proporção do mapa
public PointD calcRatio(double longitude, double latitude) {
// Para o eixo X, basta uma simples regra de 3
// (Longitude - minLongitude) / (maxLongitude - minLongitude)
double ratioX = (longitude - minLongitude) / (maxLongitude - minLongitude);
// Para o eixo Y é necessária certa matemágica trigonométrica
// (0.5 - log((1+senoLatitude)/(1-senoLatitude)))/4*pi
// Sendo senoLatitude = sen(latitude * PI/180)
double senoLatitude = Math.sin(latitude * Math.PI / 180.0);
double ratioY = (0.5 - Math.log((1 + senoLatitude)/(1 - senoLatitude))) / (4 * Math.PI);
return new PointD(ratioX, ratioY);
}
// Dado uma longitude e latitude, retorna o indice (ponto) que determina um tile
private Point getTileXY(double longitude, double latitude) {
PointD ratio = calcRatio(longitude, latitude);
int tamMapa = tamanhoMapa();
return new Point((int) ratio.getX() * tamMapa, (int) ratio.getY() * tamMapa);
}
public int tamanhoMapa(){
return (int) 256 << zoom;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment