document MapViewPosition.getViewBox

This commit is contained in:
Hannes Janetzek 2013-04-30 13:27:30 +02:00
parent d94874882c
commit d71b90df10

View File

@ -251,32 +251,34 @@ public class MapViewPosition {
} }
/** /**
* ... * Get the minimal axis-aligned BoundingBox that encloses
* the visible part of the map.
* *
* @return BoundingBox containing view * @return BoundingBox containing view
*/ */
public synchronized BoundingBox getViewBox() { public synchronized BoundingBox getViewBox() {
float[] coords = mBBoxCoords; float[] coords = mBBoxCoords;
// get depth at bottom and top
float t = getZ(1); float t = getZ(1);
float t2 = getZ(-1); float t2 = getZ(-1);
// project screen corners onto map
unproject(1, -1, t, coords, 0); unproject(1, -1, t, coords, 0);
unproject(-1, -1, t, coords, 2); unproject(-1, -1, t, coords, 2);
unproject(-1, 1, t2, coords, 4); unproject(-1, 1, t2, coords, 4);
unproject(1, 1, t2, coords, 6); unproject(1, 1, t2, coords, 6);
double dx, dy;
double minX = Double.MAX_VALUE; double minX = Double.MAX_VALUE;
double minY = Double.MAX_VALUE; double minY = Double.MAX_VALUE;
double maxX = Double.MIN_VALUE; double maxX = Double.MIN_VALUE;
double maxY = Double.MIN_VALUE; double maxY = Double.MIN_VALUE;
// get axis-aligned bbox coordinates enclosing
// enclosing the map trapezoid
for (int i = 0; i < 8; i += 2) { for (int i = 0; i < 8; i += 2) {
dx = mCurX - coords[i + 0]; double dx = mCurX - coords[i + 0];
dy = mCurY - coords[i + 1]; double dy = mCurY - coords[i + 1];
minX = Math.min(minX, dx); minX = Math.min(minX, dx);
maxX = Math.max(maxX, dx); maxX = Math.max(maxX, dx);
@ -284,17 +286,15 @@ public class MapViewPosition {
maxY = Math.max(maxY, dy); maxY = Math.max(maxY, dy);
} }
minX = MercatorProjection.toLongitude(minX / mCurScale); // scale map-pixel coordinates at current scale
maxX = MercatorProjection.toLongitude(maxX / mCurScale); // to absolute coordinates and apply mercator
minY = MercatorProjection.toLatitude(minY / mCurScale); // projection.
maxY = MercatorProjection.toLatitude(maxY / mCurScale); double minLon = MercatorProjection.toLongitude(minX / mCurScale);
double maxLon = MercatorProjection.toLongitude(maxX / mCurScale);
double minLat = MercatorProjection.toLatitude(maxY / mCurScale);
double maxLat = MercatorProjection.toLatitude(minY / mCurScale);
// yea, this is upside down.. return new BoundingBox(minLat, minLon, maxLat, maxLon);
BoundingBox bbox = new BoundingBox(maxY, minX, minY, maxX);
Log.d(TAG, "getScreenBoundingBox " + bbox);
return bbox;
} }
/** /**
@ -578,7 +578,7 @@ public class MapViewPosition {
mAbsY = MercatorProjection.latitudeToY(latitude); mAbsY = MercatorProjection.latitudeToY(latitude);
} }
synchronized void setMapPosition(MapPosition mapPosition) { synchronized void setMapPosition(MapPosition mapPosition) {
setZoomLevelLimit(mapPosition.zoomLevel); setZoomLevelLimit(mapPosition.zoomLevel);
mAbsX = mapPosition.x; mAbsX = mapPosition.x;
mAbsY = mapPosition.y; mAbsY = mapPosition.y;
@ -608,7 +608,6 @@ public class MapViewPosition {
private double mEndScale; private double mEndScale;
private float mStartRotation; private float mStartRotation;
private float mDuration = 500; private float mDuration = 500;
private final static double LOG4 = Math.log(4); private final static double LOG4 = Math.log(4);
@ -767,7 +766,7 @@ public class MapViewPosition {
changed = true; changed = true;
} }
if (mAnimMove && mAnimScale){ if (mAnimMove && mAnimScale) {
mRotation = mStartRotation * (1 - adv); mRotation = mStartRotation * (1 - adv);
updateMatrix(); updateMatrix();
} }