MapPosition: use int to represent zoomLevel
add MapPosition.setFromLatLon utility
This commit is contained in:
parent
a818e2f062
commit
bef8e125fb
@ -21,7 +21,7 @@ public class MapPosition {
|
|||||||
public double lon;
|
public double lon;
|
||||||
public double lat;
|
public double lat;
|
||||||
|
|
||||||
public byte zoomLevel;
|
public int zoomLevel;
|
||||||
public float scale;
|
public float scale;
|
||||||
public float angle;
|
public float angle;
|
||||||
public float tilt;
|
public float tilt;
|
||||||
@ -58,7 +58,7 @@ public class MapPosition {
|
|||||||
this.y = MercatorProjection.latitudeToPixelY(this.lat, zoomLevel);
|
this.y = MercatorProjection.latitudeToPixelY(this.lat, zoomLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MapPosition(double latitude, double longitude, byte zoomLevel, float scale,
|
public MapPosition(double latitude, double longitude, int zoomLevel, float scale,
|
||||||
float angle) {
|
float angle) {
|
||||||
this.zoomLevel = zoomLevel;
|
this.zoomLevel = zoomLevel;
|
||||||
this.scale = scale;
|
this.scale = scale;
|
||||||
@ -79,6 +79,12 @@ public class MapPosition {
|
|||||||
this.y = other.y;
|
this.y = other.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFromLatLon(double latitude, double longitude, int zoomLevel){
|
||||||
|
this.zoomLevel = zoomLevel;
|
||||||
|
this.x = MercatorProjection.longitudeToPixelX(longitude, zoomLevel);
|
||||||
|
this.y = MercatorProjection.latitudeToPixelY(latitude, zoomLevel);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|||||||
@ -56,7 +56,7 @@ public final class MercatorProjection {
|
|||||||
* the zoom level at which the resolution should be calculated.
|
* the zoom level at which the resolution should be calculated.
|
||||||
* @return the ground resolution at the given latitude and zoom level.
|
* @return the ground resolution at the given latitude and zoom level.
|
||||||
*/
|
*/
|
||||||
public static double calculateGroundResolution(double latitude, byte zoomLevel) {
|
public static double calculateGroundResolution(double latitude, int zoomLevel) {
|
||||||
return Math.cos(latitude * (Math.PI / 180)) * EARTH_CIRCUMFERENCE
|
return Math.cos(latitude * (Math.PI / 180)) * EARTH_CIRCUMFERENCE
|
||||||
/ ((long) Tile.TILE_SIZE << zoomLevel);
|
/ ((long) Tile.TILE_SIZE << zoomLevel);
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ public final class MercatorProjection {
|
|||||||
* the zoom level at which the coordinate should be converted.
|
* the zoom level at which the coordinate should be converted.
|
||||||
* @return the pixel Y coordinate of the latitude value.
|
* @return the pixel Y coordinate of the latitude value.
|
||||||
*/
|
*/
|
||||||
public static double latitudeToPixelY(double latitude, byte zoomLevel) {
|
public static double latitudeToPixelY(double latitude, int zoomLevel) {
|
||||||
double sinLatitude = Math.sin(latitude * (Math.PI / 180));
|
double sinLatitude = Math.sin(latitude * (Math.PI / 180));
|
||||||
return (0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI))
|
return (0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI))
|
||||||
* ((long) Tile.TILE_SIZE << zoomLevel);
|
* ((long) Tile.TILE_SIZE << zoomLevel);
|
||||||
@ -105,7 +105,7 @@ public final class MercatorProjection {
|
|||||||
* the zoom level at which the coordinate should be converted.
|
* the zoom level at which the coordinate should be converted.
|
||||||
* @return the tile Y number of the latitude value.
|
* @return the tile Y number of the latitude value.
|
||||||
*/
|
*/
|
||||||
public static long latitudeToTileY(double latitude, byte zoomLevel) {
|
public static long latitudeToTileY(double latitude, int zoomLevel) {
|
||||||
return pixelYToTileY(latitudeToPixelY(latitude, zoomLevel), zoomLevel);
|
return pixelYToTileY(latitudeToPixelY(latitude, zoomLevel), zoomLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ public final class MercatorProjection {
|
|||||||
* the zoom level at which the coordinate should be converted.
|
* the zoom level at which the coordinate should be converted.
|
||||||
* @return the pixel X coordinate of the longitude value.
|
* @return the pixel X coordinate of the longitude value.
|
||||||
*/
|
*/
|
||||||
public static double longitudeToPixelX(double longitude, byte zoomLevel) {
|
public static double longitudeToPixelX(double longitude,int zoomLevel) {
|
||||||
return (longitude + 180) / 360 * ((long) Tile.TILE_SIZE << zoomLevel);
|
return (longitude + 180) / 360 * ((long) Tile.TILE_SIZE << zoomLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,7 +178,7 @@ public final class MercatorProjection {
|
|||||||
* the zoom level at which the coordinate should be converted.
|
* the zoom level at which the coordinate should be converted.
|
||||||
* @return the tile X number of the longitude value.
|
* @return the tile X number of the longitude value.
|
||||||
*/
|
*/
|
||||||
public static long longitudeToTileX(double longitude, byte zoomLevel) {
|
public static long longitudeToTileX(double longitude, int zoomLevel) {
|
||||||
return pixelXToTileX(longitudeToPixelX(longitude, zoomLevel), zoomLevel);
|
return pixelXToTileX(longitudeToPixelX(longitude, zoomLevel), zoomLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,7 +192,7 @@ public final class MercatorProjection {
|
|||||||
* the zoom level at which the coordinate should be converted.
|
* the zoom level at which the coordinate should be converted.
|
||||||
* @return the longitude value of the pixel X coordinate.
|
* @return the longitude value of the pixel X coordinate.
|
||||||
*/
|
*/
|
||||||
public static double pixelXToLongitude(double pixelX, byte zoomLevel) {
|
public static double pixelXToLongitude(double pixelX, int zoomLevel) {
|
||||||
return 360 * ((pixelX / ((long) Tile.TILE_SIZE << zoomLevel)) - 0.5);
|
return 360 * ((pixelX / ((long) Tile.TILE_SIZE << zoomLevel)) - 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,7 +212,7 @@ public final class MercatorProjection {
|
|||||||
* the zoom level at which the coordinate should be converted.
|
* the zoom level at which the coordinate should be converted.
|
||||||
* @return the tile X number.
|
* @return the tile X number.
|
||||||
*/
|
*/
|
||||||
public static int pixelXToTileX(double pixelX, byte zoomLevel) {
|
public static int pixelXToTileX(double pixelX, int zoomLevel) {
|
||||||
return (int) Math.min(Math.max(pixelX / Tile.TILE_SIZE, 0),
|
return (int) Math.min(Math.max(pixelX / Tile.TILE_SIZE, 0),
|
||||||
Math.pow(2, zoomLevel) - 1);
|
Math.pow(2, zoomLevel) - 1);
|
||||||
}
|
}
|
||||||
@ -227,7 +227,7 @@ public final class MercatorProjection {
|
|||||||
* the zoom level at which the coordinate should be converted.
|
* the zoom level at which the coordinate should be converted.
|
||||||
* @return the latitude value of the pixel Y coordinate.
|
* @return the latitude value of the pixel Y coordinate.
|
||||||
*/
|
*/
|
||||||
public static double pixelYToLatitude(double pixelY, byte zoomLevel) {
|
public static double pixelYToLatitude(double pixelY, int zoomLevel) {
|
||||||
double y = 0.5 - (pixelY / ((long) Tile.TILE_SIZE << zoomLevel));
|
double y = 0.5 - (pixelY / ((long) Tile.TILE_SIZE << zoomLevel));
|
||||||
return 90 - 360 * Math.atan(Math.exp(-y * (2 * Math.PI))) / Math.PI;
|
return 90 - 360 * Math.atan(Math.exp(-y * (2 * Math.PI))) / Math.PI;
|
||||||
}
|
}
|
||||||
@ -250,7 +250,7 @@ public final class MercatorProjection {
|
|||||||
* the zoom level at which the coordinate should be converted.
|
* the zoom level at which the coordinate should be converted.
|
||||||
* @return the tile Y number.
|
* @return the tile Y number.
|
||||||
*/
|
*/
|
||||||
public static int pixelYToTileY(double pixelY, byte zoomLevel) {
|
public static int pixelYToTileY(double pixelY, int zoomLevel) {
|
||||||
return (int) Math.min(Math.max(pixelY / Tile.TILE_SIZE, 0),
|
return (int) Math.min(Math.max(pixelY / Tile.TILE_SIZE, 0),
|
||||||
Math.pow(2, zoomLevel) - 1);
|
Math.pow(2, zoomLevel) - 1);
|
||||||
}
|
}
|
||||||
@ -265,7 +265,7 @@ public final class MercatorProjection {
|
|||||||
* the zoom level at which the number should be converted.
|
* the zoom level at which the number should be converted.
|
||||||
* @return the longitude value of the tile X number.
|
* @return the longitude value of the tile X number.
|
||||||
*/
|
*/
|
||||||
public static double tileXToLongitude(long tileX, byte zoomLevel) {
|
public static double tileXToLongitude(long tileX, int zoomLevel) {
|
||||||
return pixelXToLongitude(tileX * Tile.TILE_SIZE, zoomLevel);
|
return pixelXToLongitude(tileX * Tile.TILE_SIZE, zoomLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,7 +279,7 @@ public final class MercatorProjection {
|
|||||||
* the zoom level at which the number should be converted.
|
* the zoom level at which the number should be converted.
|
||||||
* @return the latitude value of the tile Y number.
|
* @return the latitude value of the tile Y number.
|
||||||
*/
|
*/
|
||||||
public static double tileYToLatitude(long tileY, byte zoomLevel) {
|
public static double tileYToLatitude(long tileY, int zoomLevel) {
|
||||||
return pixelYToLatitude(tileY * Tile.TILE_SIZE, zoomLevel);
|
return pixelYToLatitude(tileY * Tile.TILE_SIZE, zoomLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,7 +287,7 @@ public final class MercatorProjection {
|
|||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static Point projectPoint(GeoPoint geopoint, byte z, Point reuse) {
|
// public static Point projectPoint(GeoPoint geopoint, int z, Point reuse) {
|
||||||
// Point out = reuse == null ? new Point() : reuse;
|
// Point out = reuse == null ? new Point() : reuse;
|
||||||
//
|
//
|
||||||
// out.x = (int) MercatorProjection.longitudeToPixelX(geopoint.getLongitude(), z);
|
// out.x = (int) MercatorProjection.longitudeToPixelX(geopoint.getLongitude(), z);
|
||||||
|
|||||||
@ -65,11 +65,11 @@ public class BuildingOverlay extends Overlay {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte mPrevZoom = 0;
|
private int mPrevZoom = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate(MapPosition mapPosition, boolean changed) {
|
public void onUpdate(MapPosition mapPosition, boolean changed) {
|
||||||
byte z = mapPosition.zoomLevel;
|
int z = mapPosition.zoomLevel;
|
||||||
if (z == mPrevZoom)
|
if (z == mPrevZoom)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@ -166,7 +166,7 @@ public class GLRenderer implements GLSurfaceView.Renderer {
|
|||||||
if (tile == null)
|
if (tile == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
holder = new MapTile(x, y, mZoom);
|
holder = new MapTile(x, y, (byte)mZoom);
|
||||||
holder.isVisible = true;
|
holder.isVisible = true;
|
||||||
holder.holder = tile;
|
holder.holder = tile;
|
||||||
tile.isVisible = true;
|
tile.isVisible = true;
|
||||||
|
|||||||
@ -46,11 +46,11 @@ public abstract class ScanBox {
|
|||||||
private Edge ca = new Edge();
|
private Edge ca = new Edge();
|
||||||
private float minX, maxX;
|
private float minX, maxX;
|
||||||
|
|
||||||
protected byte mZoom;
|
protected int mZoom;
|
||||||
|
|
||||||
abstract void setVisible(int y, int x1, int x2);
|
abstract void setVisible(int y, int x1, int x2);
|
||||||
|
|
||||||
public void scan(float[] coords, byte zoom) {
|
public void scan(float[] coords, int zoom) {
|
||||||
mZoom = zoom;
|
mZoom = zoom;
|
||||||
|
|
||||||
maxX = Float.MIN_VALUE;
|
maxX = Float.MIN_VALUE;
|
||||||
|
|||||||
@ -290,13 +290,13 @@ public class TileManager {
|
|||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
|
|
||||||
/* package */MapTile addTile(int x, int y, byte zoomLevel) {
|
/* package */MapTile addTile(int x, int y, int zoomLevel) {
|
||||||
MapTile tile;
|
MapTile tile;
|
||||||
|
|
||||||
tile = QuadTree.getTile(x, y, zoomLevel);
|
tile = QuadTree.getTile(x, y, zoomLevel);
|
||||||
|
|
||||||
if (tile == null) {
|
if (tile == null) {
|
||||||
tile = new MapTile(x, y, zoomLevel);
|
tile = new MapTile(x, y, (byte)zoomLevel);
|
||||||
QuadTree.add(tile);
|
QuadTree.add(tile);
|
||||||
mJobs.add(tile);
|
mJobs.add(tile);
|
||||||
addToCache(tile);
|
addToCache(tile);
|
||||||
@ -392,7 +392,7 @@ public class TileManager {
|
|||||||
// TODO there is probably a better quad-tree distance function
|
// TODO there is probably a better quad-tree distance function
|
||||||
double x = mapPosition.x;
|
double x = mapPosition.x;
|
||||||
double y = mapPosition.y;
|
double y = mapPosition.y;
|
||||||
byte zoom = mapPosition.zoomLevel;
|
int zoom = mapPosition.zoomLevel;
|
||||||
int h = Tile.TILE_SIZE >> 1;
|
int h = Tile.TILE_SIZE >> 1;
|
||||||
long center = h << zoom;
|
long center = h << zoom;
|
||||||
|
|
||||||
|
|||||||
@ -99,7 +99,7 @@ public class GridOverlay extends BasicOverlay {
|
|||||||
|
|
||||||
private int mCurX = -1;
|
private int mCurX = -1;
|
||||||
private int mCurY = -1;
|
private int mCurY = -1;
|
||||||
private byte mCurZ = -1;
|
private int mCurZ = -1;
|
||||||
|
|
||||||
private boolean finished;
|
private boolean finished;
|
||||||
|
|
||||||
|
|||||||
@ -312,28 +312,28 @@ public class MapViewPosition {
|
|||||||
return bbox;
|
return bbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* For x, y in screen coordinates set Point to map-tile
|
// * For x, y in screen coordinates set Point to map-tile
|
||||||
* coordinates at returned scale.
|
// * coordinates at returned scale.
|
||||||
*
|
// *
|
||||||
* @param x screen coordinate
|
// * @param x screen coordinate
|
||||||
* @param y screen coordinate
|
// * @param y screen coordinate
|
||||||
* @param out Point coords will be set
|
// * @param out Point coords will be set
|
||||||
* @return current map scale
|
// * @return current map scale
|
||||||
*/
|
// */
|
||||||
public synchronized float getScreenPointOnMap(float x, float y, PointD out) {
|
// public synchronized float getScreenPointOnMap(float x, float y, PointD out) {
|
||||||
|
//
|
||||||
// scale to -1..1
|
// // scale to -1..1
|
||||||
float mx = 1 - (x / mWidth * 2);
|
// float mx = 1 - (x / mWidth * 2);
|
||||||
float my = 1 - (y / mHeight * 2);
|
// float my = 1 - (y / mHeight * 2);
|
||||||
|
//
|
||||||
unproject(-mx, my, getZ(-my), mu, 0);
|
// unproject(-mx, my, getZ(-my), mu, 0);
|
||||||
|
//
|
||||||
out.x = mCurX + mu[0];
|
// out.x = mCurX + mu[0];
|
||||||
out.y = mCurY + mu[1];
|
// out.y = mCurY + mu[1];
|
||||||
|
//
|
||||||
return (float) mAbsScale;
|
// return (float) mAbsScale;
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the GeoPoint for x,y in screen coordinates.
|
* Get the GeoPoint for x,y in screen coordinates.
|
||||||
@ -628,7 +628,7 @@ public class MapViewPosition {
|
|||||||
updatePosition();
|
updatePosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setZoomLevelLimit(byte zoomLevel) {
|
private void setZoomLevelLimit(int zoomLevel) {
|
||||||
mAbsScale = FastMath.clamp(1 << zoomLevel, MIN_SCALE, MAX_SCALE);
|
mAbsScale = FastMath.clamp(1 << zoomLevel, MIN_SCALE, MAX_SCALE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user