diff --git a/src/org/oscim/core/MapPosition.java b/src/org/oscim/core/MapPosition.java index 32b70ede..d518236a 100644 --- a/src/org/oscim/core/MapPosition.java +++ b/src/org/oscim/core/MapPosition.java @@ -21,7 +21,7 @@ public class MapPosition { public double lon; public double lat; - public byte zoomLevel; + public int zoomLevel; public float scale; public float angle; public float tilt; @@ -58,7 +58,7 @@ public class MapPosition { 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) { this.zoomLevel = zoomLevel; this.scale = scale; @@ -79,6 +79,12 @@ public class MapPosition { 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 public String toString() { StringBuilder builder = new StringBuilder(); diff --git a/src/org/oscim/core/MercatorProjection.java b/src/org/oscim/core/MercatorProjection.java index 0ed58cfb..50a3add1 100644 --- a/src/org/oscim/core/MercatorProjection.java +++ b/src/org/oscim/core/MercatorProjection.java @@ -56,7 +56,7 @@ public final class MercatorProjection { * the zoom level at which the resolution should be calculated. * @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 / ((long) Tile.TILE_SIZE << zoomLevel); } @@ -71,7 +71,7 @@ public final class MercatorProjection { * the zoom level at which the coordinate should be converted. * @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)); return (0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI)) * ((long) Tile.TILE_SIZE << zoomLevel); @@ -105,7 +105,7 @@ public final class MercatorProjection { * the zoom level at which the coordinate should be converted. * @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); } @@ -148,7 +148,7 @@ public final class MercatorProjection { * the zoom level at which the coordinate should be converted. * @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); } @@ -178,7 +178,7 @@ public final class MercatorProjection { * the zoom level at which the coordinate should be converted. * @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); } @@ -192,7 +192,7 @@ public final class MercatorProjection { * the zoom level at which the coordinate should be converted. * @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); } @@ -212,7 +212,7 @@ public final class MercatorProjection { * the zoom level at which the coordinate should be converted. * @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), Math.pow(2, zoomLevel) - 1); } @@ -227,7 +227,7 @@ public final class MercatorProjection { * the zoom level at which the coordinate should be converted. * @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)); 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. * @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), Math.pow(2, zoomLevel) - 1); } @@ -265,7 +265,7 @@ public final class MercatorProjection { * the zoom level at which the number should be converted. * @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); } @@ -279,7 +279,7 @@ public final class MercatorProjection { * the zoom level at which the number should be converted. * @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); } @@ -287,7 +287,7 @@ public final class MercatorProjection { 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; // // out.x = (int) MercatorProjection.longitudeToPixelX(geopoint.getLongitude(), z); diff --git a/src/org/oscim/overlay/BuildingOverlay.java b/src/org/oscim/overlay/BuildingOverlay.java index a5cc20d1..b76f3de9 100644 --- a/src/org/oscim/overlay/BuildingOverlay.java +++ b/src/org/oscim/overlay/BuildingOverlay.java @@ -65,11 +65,11 @@ public class BuildingOverlay extends Overlay { return false; } - private byte mPrevZoom = 0; + private int mPrevZoom = 0; @Override public void onUpdate(MapPosition mapPosition, boolean changed) { - byte z = mapPosition.zoomLevel; + int z = mapPosition.zoomLevel; if (z == mPrevZoom) return; diff --git a/src/org/oscim/renderer/GLRenderer.java b/src/org/oscim/renderer/GLRenderer.java index 64e95f09..06ca59e1 100644 --- a/src/org/oscim/renderer/GLRenderer.java +++ b/src/org/oscim/renderer/GLRenderer.java @@ -166,7 +166,7 @@ public class GLRenderer implements GLSurfaceView.Renderer { if (tile == null) continue; - holder = new MapTile(x, y, mZoom); + holder = new MapTile(x, y, (byte)mZoom); holder.isVisible = true; holder.holder = tile; tile.isVisible = true; diff --git a/src/org/oscim/renderer/ScanBox.java b/src/org/oscim/renderer/ScanBox.java index 684d7495..086ad7f2 100644 --- a/src/org/oscim/renderer/ScanBox.java +++ b/src/org/oscim/renderer/ScanBox.java @@ -46,11 +46,11 @@ public abstract class ScanBox { private Edge ca = new Edge(); private float minX, maxX; - protected byte mZoom; + protected int mZoom; 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; maxX = Float.MIN_VALUE; diff --git a/src/org/oscim/renderer/TileManager.java b/src/org/oscim/renderer/TileManager.java index e128b48d..5d0983d6 100644 --- a/src/org/oscim/renderer/TileManager.java +++ b/src/org/oscim/renderer/TileManager.java @@ -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; tile = QuadTree.getTile(x, y, zoomLevel); if (tile == null) { - tile = new MapTile(x, y, zoomLevel); + tile = new MapTile(x, y, (byte)zoomLevel); QuadTree.add(tile); mJobs.add(tile); addToCache(tile); @@ -392,7 +392,7 @@ public class TileManager { // TODO there is probably a better quad-tree distance function double x = mapPosition.x; double y = mapPosition.y; - byte zoom = mapPosition.zoomLevel; + int zoom = mapPosition.zoomLevel; int h = Tile.TILE_SIZE >> 1; long center = h << zoom; diff --git a/src/org/oscim/renderer/overlays/GridOverlay.java b/src/org/oscim/renderer/overlays/GridOverlay.java index 441568d8..8b14f98d 100644 --- a/src/org/oscim/renderer/overlays/GridOverlay.java +++ b/src/org/oscim/renderer/overlays/GridOverlay.java @@ -99,7 +99,7 @@ public class GridOverlay extends BasicOverlay { private int mCurX = -1; private int mCurY = -1; - private byte mCurZ = -1; + private int mCurZ = -1; private boolean finished; diff --git a/src/org/oscim/view/MapViewPosition.java b/src/org/oscim/view/MapViewPosition.java index 1bb2ea8e..cfaa549f 100644 --- a/src/org/oscim/view/MapViewPosition.java +++ b/src/org/oscim/view/MapViewPosition.java @@ -312,28 +312,28 @@ public class MapViewPosition { return bbox; } - /** - * For x, y in screen coordinates set Point to map-tile - * coordinates at returned scale. - * - * @param x screen coordinate - * @param y screen coordinate - * @param out Point coords will be set - * @return current map scale - */ - public synchronized float getScreenPointOnMap(float x, float y, PointD out) { - - // scale to -1..1 - float mx = 1 - (x / mWidth * 2); - float my = 1 - (y / mHeight * 2); - - unproject(-mx, my, getZ(-my), mu, 0); - - out.x = mCurX + mu[0]; - out.y = mCurY + mu[1]; - - return (float) mAbsScale; - } +// /** +// * For x, y in screen coordinates set Point to map-tile +// * coordinates at returned scale. +// * +// * @param x screen coordinate +// * @param y screen coordinate +// * @param out Point coords will be set +// * @return current map scale +// */ +// public synchronized float getScreenPointOnMap(float x, float y, PointD out) { +// +// // scale to -1..1 +// float mx = 1 - (x / mWidth * 2); +// float my = 1 - (y / mHeight * 2); +// +// unproject(-mx, my, getZ(-my), mu, 0); +// +// out.x = mCurX + mu[0]; +// out.y = mCurY + mu[1]; +// +// return (float) mAbsScale; +// } /** * Get the GeoPoint for x,y in screen coordinates. @@ -628,7 +628,7 @@ public class MapViewPosition { updatePosition(); } - private void setZoomLevelLimit(byte zoomLevel) { + private void setZoomLevelLimit(int zoomLevel) { mAbsScale = FastMath.clamp(1 << zoomLevel, MIN_SCALE, MAX_SCALE); }