add animateTo for BoundingBox
This commit is contained in:
parent
eb0b7a8c0c
commit
df7c7200e5
@ -49,7 +49,6 @@ public final class MercatorProjection {
|
|||||||
/**
|
/**
|
||||||
* Calculates the distance on the ground that is represented by a single
|
* Calculates the distance on the ground that is represented by a single
|
||||||
* pixel on the map.
|
* pixel on the map.
|
||||||
*
|
|
||||||
* @param latitude
|
* @param latitude
|
||||||
* the latitude coordinate at which the resolution should be
|
* the latitude coordinate at which the resolution should be
|
||||||
* calculated.
|
* calculated.
|
||||||
@ -65,7 +64,6 @@ public final class MercatorProjection {
|
|||||||
/**
|
/**
|
||||||
* Converts a latitude coordinate (in degrees) to a pixel Y coordinate at a
|
* Converts a latitude coordinate (in degrees) to a pixel Y coordinate at a
|
||||||
* certain zoom level.
|
* certain zoom level.
|
||||||
*
|
|
||||||
* @param latitude
|
* @param latitude
|
||||||
* the latitude coordinate that should be converted.
|
* the latitude coordinate that should be converted.
|
||||||
* @param zoomLevel
|
* @param zoomLevel
|
||||||
@ -84,10 +82,14 @@ public final class MercatorProjection {
|
|||||||
* ((long) Tile.TILE_SIZE << mapPosition.zoomLevel);
|
* ((long) Tile.TILE_SIZE << mapPosition.zoomLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static double latitudeToY(double latitude) {
|
||||||
|
double sinLatitude = Math.sin(latitude * (Math.PI / 180));
|
||||||
|
return 0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a latitude coordinate (in degrees) to a tile Y number at a
|
* Converts a latitude coordinate (in degrees) to a tile Y number at a
|
||||||
* certain zoom level.
|
* certain zoom level.
|
||||||
*
|
|
||||||
* @param latitude
|
* @param latitude
|
||||||
* the latitude coordinate that should be converted.
|
* the latitude coordinate that should be converted.
|
||||||
* @param zoomLevel
|
* @param zoomLevel
|
||||||
@ -130,7 +132,6 @@ public final class MercatorProjection {
|
|||||||
/**
|
/**
|
||||||
* Converts a longitude coordinate (in degrees) to a pixel X coordinate at a
|
* Converts a longitude coordinate (in degrees) to a pixel X coordinate at a
|
||||||
* certain zoom level.
|
* certain zoom level.
|
||||||
*
|
|
||||||
* @param longitude
|
* @param longitude
|
||||||
* the longitude coordinate that should be converted.
|
* the longitude coordinate that should be converted.
|
||||||
* @param zoomLevel
|
* @param zoomLevel
|
||||||
@ -146,10 +147,13 @@ public final class MercatorProjection {
|
|||||||
* ((long) Tile.TILE_SIZE << mapPosition.zoomLevel);
|
* ((long) Tile.TILE_SIZE << mapPosition.zoomLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static double longitudeToX(double longitude) {
|
||||||
|
return (longitude + 180) / 360;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a longitude coordinate (in degrees) to the tile X number at a
|
* Converts a longitude coordinate (in degrees) to the tile X number at a
|
||||||
* certain zoom level.
|
* certain zoom level.
|
||||||
*
|
|
||||||
* @param longitude
|
* @param longitude
|
||||||
* the longitude coordinate that should be converted.
|
* the longitude coordinate that should be converted.
|
||||||
* @param zoomLevel
|
* @param zoomLevel
|
||||||
@ -163,7 +167,6 @@ public final class MercatorProjection {
|
|||||||
/**
|
/**
|
||||||
* Converts a pixel X coordinate at a certain zoom level to a longitude
|
* Converts a pixel X coordinate at a certain zoom level to a longitude
|
||||||
* coordinate.
|
* coordinate.
|
||||||
*
|
|
||||||
* @param pixelX
|
* @param pixelX
|
||||||
* the pixel X coordinate that should be converted.
|
* the pixel X coordinate that should be converted.
|
||||||
* @param zoomLevel
|
* @param zoomLevel
|
||||||
@ -176,7 +179,6 @@ public final class MercatorProjection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a pixel X coordinate to the tile X number.
|
* Converts a pixel X coordinate to the tile X number.
|
||||||
*
|
|
||||||
* @param pixelX
|
* @param pixelX
|
||||||
* the pixel X coordinate that should be converted.
|
* the pixel X coordinate that should be converted.
|
||||||
* @param zoomLevel
|
* @param zoomLevel
|
||||||
@ -191,7 +193,6 @@ public final class MercatorProjection {
|
|||||||
/**
|
/**
|
||||||
* Converts a pixel Y coordinate at a certain zoom level to a latitude
|
* Converts a pixel Y coordinate at a certain zoom level to a latitude
|
||||||
* coordinate.
|
* coordinate.
|
||||||
*
|
|
||||||
* @param pixelY
|
* @param pixelY
|
||||||
* the pixel Y coordinate that should be converted.
|
* the pixel Y coordinate that should be converted.
|
||||||
* @param zoomLevel
|
* @param zoomLevel
|
||||||
@ -205,7 +206,6 @@ public final class MercatorProjection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a pixel Y coordinate to the tile Y number.
|
* Converts a pixel Y coordinate to the tile Y number.
|
||||||
*
|
|
||||||
* @param pixelY
|
* @param pixelY
|
||||||
* the pixel Y coordinate that should be converted.
|
* the pixel Y coordinate that should be converted.
|
||||||
* @param zoomLevel
|
* @param zoomLevel
|
||||||
@ -220,7 +220,6 @@ public final class MercatorProjection {
|
|||||||
/**
|
/**
|
||||||
* Converts a tile X number at a certain zoom level to a longitude
|
* Converts a tile X number at a certain zoom level to a longitude
|
||||||
* coordinate.
|
* coordinate.
|
||||||
*
|
|
||||||
* @param tileX
|
* @param tileX
|
||||||
* the tile X number that should be converted.
|
* the tile X number that should be converted.
|
||||||
* @param zoomLevel
|
* @param zoomLevel
|
||||||
@ -234,7 +233,6 @@ public final class MercatorProjection {
|
|||||||
/**
|
/**
|
||||||
* Converts a tile Y number at a certain zoom level to a latitude
|
* Converts a tile Y number at a certain zoom level to a latitude
|
||||||
* coordinate.
|
* coordinate.
|
||||||
*
|
|
||||||
* @param tileY
|
* @param tileY
|
||||||
* the tile Y number that should be converted.
|
* the tile Y number that should be converted.
|
||||||
* @param zoomLevel
|
* @param zoomLevel
|
||||||
|
@ -24,6 +24,7 @@ import org.oscim.core.BoundingBox;
|
|||||||
import org.oscim.core.GeoPoint;
|
import org.oscim.core.GeoPoint;
|
||||||
import org.oscim.core.MapPosition;
|
import org.oscim.core.MapPosition;
|
||||||
import org.oscim.core.MercatorProjection;
|
import org.oscim.core.MercatorProjection;
|
||||||
|
import org.oscim.core.Tile;
|
||||||
import org.oscim.utils.FastMath;
|
import org.oscim.utils.FastMath;
|
||||||
|
|
||||||
import android.graphics.Point;
|
import android.graphics.Point;
|
||||||
@ -551,6 +552,7 @@ public class MapViewPosition {
|
|||||||
//mZoomLevel = mMapView.limitZoomLevel(zoomLevel);
|
//mZoomLevel = mMapView.limitZoomLevel(zoomLevel);
|
||||||
setZoomLevelLimit(zoomLevel);
|
setZoomLevelLimit(zoomLevel);
|
||||||
mMapScale = 1 << mZoomLevel;
|
mMapScale = 1 << mZoomLevel;
|
||||||
|
mScale = 1;
|
||||||
updatePosition();
|
updatePosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -576,10 +578,49 @@ public class MapViewPosition {
|
|||||||
private double mEndX;
|
private double mEndX;
|
||||||
private double mEndY;
|
private double mEndY;
|
||||||
private float mDuration = 500;
|
private float mDuration = 500;
|
||||||
private Point mTmpPoint;
|
|
||||||
|
public synchronized void animateTo(BoundingBox bbox) {
|
||||||
|
double dx = MercatorProjection.longitudeToX(bbox.getMaxLongitude())
|
||||||
|
- MercatorProjection.longitudeToX(bbox.getMinLongitude());
|
||||||
|
double dy = MercatorProjection.latitudeToY(bbox.getMinLatitude())
|
||||||
|
- MercatorProjection.latitudeToY(bbox.getMaxLatitude());
|
||||||
|
|
||||||
|
double log4 = Math.log(4);
|
||||||
|
|
||||||
|
double zx = -log4 * Math.log(dx) + (mWidth / Tile.TILE_SIZE);
|
||||||
|
double zy = -log4 * Math.log(dy) + (mHeight / Tile.TILE_SIZE);
|
||||||
|
|
||||||
|
double z = Math.min(zx, zy);
|
||||||
|
|
||||||
|
if (z > MAX_ZOOMLEVEL)
|
||||||
|
z = MAX_ZOOMLEVEL;
|
||||||
|
else if (z < MIN_ZOOMLEVEL)
|
||||||
|
z = MIN_ZOOMLEVEL;
|
||||||
|
|
||||||
|
mZoomLevel = (byte) Math.floor(z);
|
||||||
|
mScale = (float) (1 + (z - mZoomLevel));
|
||||||
|
// global scale
|
||||||
|
mMapScale = (1 << mZoomLevel) * mScale;
|
||||||
|
//Log.d(TAG, "zoom: " + bbox + " " + zx + " " + zy + " / " + mScale + " " + mZoomLevel);
|
||||||
|
updatePosition();
|
||||||
|
|
||||||
|
// reset rotation/tilt
|
||||||
|
mTilt = 0;
|
||||||
|
mRotation = 0;
|
||||||
|
updateMatrix();
|
||||||
|
|
||||||
|
GeoPoint geoPoint = bbox.getCenterPoint();
|
||||||
|
mEndX = MercatorProjection.longitudeToPixelX(geoPoint.getLongitude(), mZoomLevel);
|
||||||
|
mEndY = MercatorProjection.latitudeToPixelY(geoPoint.getLatitude(), mZoomLevel);
|
||||||
|
mStartX = mPosX;
|
||||||
|
mStartY = mPosY;
|
||||||
|
|
||||||
|
mDuration = 300;
|
||||||
|
mHandler.start((int) mDuration);
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void animateTo(GeoPoint geoPoint) {
|
public synchronized void animateTo(GeoPoint geoPoint) {
|
||||||
MercatorProjection.projectPoint(geoPoint, mZoomLevel, mTmpPoint);
|
//MercatorProjection.projectPoint(geoPoint, mZoomLevel, mTmpPoint);
|
||||||
|
|
||||||
mEndX = MercatorProjection.longitudeToPixelX(geoPoint.getLongitude(), mZoomLevel);
|
mEndX = MercatorProjection.longitudeToPixelX(geoPoint.getLongitude(), mZoomLevel);
|
||||||
mEndY = MercatorProjection.latitudeToPixelY(geoPoint.getLatitude(), mZoomLevel);
|
mEndY = MercatorProjection.latitudeToPixelY(geoPoint.getLatitude(), mZoomLevel);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user