Continuous zoom preparation

This commit is contained in:
Victor Shcherb 2012-07-01 02:20:11 +02:00
parent fb1bb6387a
commit c3481e629b
13 changed files with 86 additions and 76 deletions

View file

@ -333,15 +333,6 @@ public class MapUtils {
return result;
}
public static int getLengthXFromMeters(float zoom, double latitude, double longitude, double meters, float tileSize, int widthOfDisplay) {
double tileNumberX = MapUtils.getTileNumberX(zoom, longitude);
double tileNumberLeft = tileNumberX - ((double) widthOfDisplay) / (2d * tileSize);
double tileNumberRight = tileNumberX + ((double) widthOfDisplay) / (2d * tileSize);
double dist = getDistance(latitude, getLongitudeFromTile(zoom, tileNumberLeft), latitude, getLongitudeFromTile(zoom,
tileNumberRight));
return (int) ((double) widthOfDisplay / dist * meters);
}
public static int getPixelShiftX(int zoom, double long1, double long2, int tileSize){
return (int) ((getTileNumberX(zoom, long1) - getTileNumberX(zoom, long2)) * tileSize);

View file

@ -59,22 +59,13 @@ public class DownloadTilesDialog {
return;
}
final int max = mapSource.getMaximumZoomSupported();
// get narrow zoom
final int zoom = mapView.getZoom();
// calculate pixel rectangle
Rect boundsRect = new Rect(0, 0, mapView.getWidth(), mapView.getHeight());
float tileX = (float) MapUtils.getTileNumberX(zoom, mapView.getLongitude());
float tileY = (float) MapUtils.getTileNumberY(zoom, mapView.getLatitude());
float w = mapView.getCenterPointX();
float h = mapView.getCenterPointY();
RectF tilesRect = new RectF();
final RectF latlonRect = new RectF();
mapView.calculateTileRectangle(boundsRect, w, h, tileX, tileY, tilesRect);
latlonRect.top = (float) MapUtils.getLatitudeFromTile(zoom, tilesRect.top);
latlonRect.left = (float) MapUtils.getLongitudeFromTile(zoom, tilesRect.left);
latlonRect.bottom = (float) MapUtils.getLatitudeFromTile(zoom, tilesRect.bottom);
latlonRect.right = (float) MapUtils.getLongitudeFromTile(zoom, tilesRect.right);
mapView.calculateLatLonRectangle(boundsRect, latlonRect);
Builder builder = new AlertDialog.Builder(ctx);
LayoutInflater inflater = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View file

@ -41,7 +41,6 @@ import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
@ -156,12 +155,6 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
startProgressDialog = new ProgressDialog(this);
startProgressDialog.setCancelable(true);
((OsmandApplication) getApplication()).checkApplicationIsBeingInitialized(this, startProgressDialog);
startProgressDialog.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
getMapView().refreshMap(true);
}
});
parseLaunchIntentLocation();
mapView = (OsmandMapTileView) findViewById(R.id.MapView);
@ -177,7 +170,7 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
startProgressDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
mapView.refreshMap();
mapView.refreshMap(true);
}
});
@ -412,7 +405,7 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
}
}
public void changeZoom(int newZoom){
public void changeZoom(float newZoom){
boolean changeLocation = settings.AUTO_ZOOM_MAP.get();
mapView.getAnimatedDraggingThread().startZooming(newZoom, changeLocation);
if (getMyApplication().accessibilityEnabled())
@ -672,7 +665,7 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
if(locationLayer.getLastKnownLocation() != null){
Location lastKnownLocation = locationLayer.getLastKnownLocation();
AnimateDraggingMapThread thread = mapView.getAnimatedDraggingThread();
int fZoom = mapView.getZoom() < 13 ? 13 : mapView.getZoom();
float fZoom = mapView.getFloatZoom() < 13 ? 13 : mapView.getFloatZoom();
thread.startMoving( lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude(), fZoom, false);
}
}
@ -774,8 +767,8 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
long now = System.currentTimeMillis();
if (isMapLinkedToLocation()) {
if(settings.AUTO_ZOOM_MAP.get() && location.hasSpeed()){
float z = defineZoomFromSpeed(location.getSpeed(), mapView.getZoom());
if(Math.abs(mapView.getZoom() - z) > .33f){
float z = defineZoomFromSpeed(location.getSpeed(), mapView.getFloatZoom());
if(Math.abs(mapView.getFloatZoom() - z) >= OsmandMapTileView.ZOOM_DELTA_1){
// prevent ui hysteresis (check time interval for autozoom)
if(now - lastTimeAutoZooming > 5000){
lastTimeAutoZooming = now;
@ -813,7 +806,7 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
mapView.refreshMap();
}
public float defineZoomFromSpeed(float speed, int currentZoom){
public float defineZoomFromSpeed(float speed, float currentZoom){
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
@ -973,7 +966,7 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
AnimateDraggingMapThread animatedThread = mapView.getAnimatedDraggingThread();
if(animatedThread.isAnimating() && animatedThread.getTargetZoom() != 0){
settings.setMapLocationToShow(animatedThread.getTargetLatitude(), animatedThread.getTargetLongitude(),
animatedThread.getTargetZoom());
(int) animatedThread.getTargetZoom());
}
settings.setLastKnownMapZoom(mapView.getZoom());

View file

@ -366,7 +366,7 @@ public class MapActivityLayers {
WptPt loc = toShow.findPointToShow();
if(loc != null){
mapView.getAnimatedDraggingThread().startMoving(loc.lat, loc.lon,
mapView.getZoom(), true);
mapView.getFloatZoom(), true);
}
mapView.refreshMap();
return true;

View file

@ -261,7 +261,7 @@ public class NavigatePointActivity extends Activity implements SearchActivityChi
// in case when it is dialog
if(activity != null) {
OsmandMapTileView v = activity.getMapView();
v.getAnimatedDraggingThread().startMoving(lat, lon, v.getZoom(), true);
v.getAnimatedDraggingThread().startMoving(lat, lon, v.getFloatZoom(), true);
} else {
settings.setMapLocationToShow(lat, lon, Math.max(12, settings.getLastKnownMapZoom()),
getString(R.string.point_on_map, lat, lon));

View file

@ -288,7 +288,7 @@ public class ParkingPositionLayer extends OsmandMapLayer implements ContextMenuL
AnimateDraggingMapThread thread = view.getAnimatedDraggingThread();
LatLon parkingPoint = view.getSettings().getParkingPosition();
if (parkingPoint != null) {
int fZoom = view.getZoom() < 15 ? 15 : view.getZoom();
float fZoom = view.getFloatZoom() < 15 ? 15 : view.getFloatZoom();
thread.startMoving(parkingPoint.getLatitude(), parkingPoint.getLongitude(), fZoom, true);
}
}

View file

@ -32,7 +32,7 @@ public class AnimateDraggingMapThread {
private float targetRotate = 0;
private double targetLatitude = 0;
private double targetLongitude = 0;
private int targetZoom = 0;
private float targetZoom = 0;
public AnimateDraggingMapThread(OsmandMapTileView tileView){
@ -107,17 +107,16 @@ public class AnimateDraggingMapThread {
}
public void startMoving(final double finalLat, final double finalLon, final int endZoom, final boolean notifyListener){
public void startMoving(final double finalLat, final double finalLon, final float endZoom, final boolean notifyListener){
stopAnimatingSync();
double startLat = tileView.getLatitude();
double startLon = tileView.getLongitude();
float rotate = tileView.getRotate();
final int startZoom = tileView.getZoom();
final float startZoom = tileView.getFloatZoom();
int tileSize = tileView.getSourceTileSize();
int mZoom = startZoom;
float mZoom = startZoom;
boolean skipAnimation = false;
float mStX = (float) ((MapUtils.getTileNumberX(mZoom, startLon) - MapUtils.getTileNumberX(mZoom, finalLon)) * tileSize);
float mStY = (float) ((MapUtils.getTileNumberY(mZoom, startLat) - MapUtils.getTileNumberY(mZoom, finalLat)) * tileSize);
@ -129,7 +128,7 @@ public class AnimateDraggingMapThread {
mStX = (float) ((MapUtils.getTileNumberX(mZoom, startLon) - MapUtils.getTileNumberX(mZoom, finalLon)) * tileSize);
mStY = (float) ((MapUtils.getTileNumberY(mZoom, startLat) - MapUtils.getTileNumberY(mZoom, finalLat)) * tileSize);
}
final int moveZoom = mZoom;
final float moveZoom = mZoom;
// check if animation needed
skipAnimation = skipAnimation || (Math.abs(moveZoom - startZoom) >= 3 || Math.abs(endZoom - moveZoom) > 3);
if (skipAnimation) {
@ -196,7 +195,7 @@ public class AnimateDraggingMapThread {
}
private void animatingZoomInThread(int zoomStart, int zoomEnd, float animationTime, boolean notifyListener){
private void animatingZoomInThread(float zoomStart, float zoomEnd, float animationTime, boolean notifyListener){
float curZoom = zoomStart;
animationTime *= Math.abs(zoomEnd - zoomStart);
// AccelerateInterpolator interpolator = new AccelerateInterpolator(1);
@ -234,12 +233,12 @@ public class AnimateDraggingMapThread {
}
public void startZooming(final int zoomEnd, final boolean notifyListener){
public void startZooming(final float zoomEnd, final boolean notifyListener){
final float animationTime = ZOOM_ANIMATION_TIME;
startThreadAnimating(new Runnable(){
@Override
public void run() {
final int zoomStart = tileView.getZoom();
final float zoomStart = tileView.getFloatZoom();
setTargetValues(zoomEnd, tileView.getLatitude(), tileView.getLongitude());
animatingZoomInThread(zoomStart, zoomEnd, animationTime, notifyListener);
pendingRotateAnimation();
@ -291,7 +290,7 @@ public class AnimateDraggingMapThread {
targetZoom = 0;
}
private void setTargetValues(int zoom, double lat, double lon){
private void setTargetValues(float zoom, double lat, double lon){
targetZoom = zoom;
targetLatitude = lat;
targetLongitude = lon;
@ -315,7 +314,7 @@ public class AnimateDraggingMapThread {
}
}
public int getTargetZoom() {
public float getTargetZoom() {
return targetZoom;
}

View file

@ -302,10 +302,10 @@ public class MapControlsLayer extends OsmandMapLayer {
zoomInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(view.isZooming()){
activity.changeZoom(view.getZoom() + 2);
if (view.isZooming()) {
activity.changeZoom(view.getZoom() + 2 );
} else {
activity.changeZoom(view.getZoom() + 1);
activity.changeZoom(view.getZoom() + 1 );
}
}
@ -314,8 +314,7 @@ public class MapControlsLayer extends OsmandMapLayer {
zoomOutButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
activity.changeZoom(view.getZoom() - 1);
activity.changeZoom(view.getZoom() - 1 );
}
});
}
@ -392,7 +391,7 @@ public class MapControlsLayer extends OsmandMapLayer {
/////////////////////// Ruler ///////////////////
// cache values for ruler
ShadowText cacheRulerText = null;
int cacheRulerZoom = 0;
float cacheRulerZoom = 0;
double cacheRulerTileX = 0;
double cacheRulerTileY = 0;
float cacheRulerTextLen = 0;
@ -401,16 +400,15 @@ public class MapControlsLayer extends OsmandMapLayer {
// update cache
if (view.isZooming()) {
cacheRulerText = null;
} else if(view.getZoom() != cacheRulerZoom ||
} else if(view.getFloatZoom() != cacheRulerZoom ||
Math.abs(view.getXTile() - cacheRulerTileX) + Math.abs(view.getYTile() - cacheRulerTileY) > 1){
cacheRulerZoom = view.getZoom();
cacheRulerZoom = view.getFloatZoom();
cacheRulerTileX = view.getXTile();
cacheRulerTileY = view.getYTile();
double latitude = view.getLatitude();
double tileNumberLeft = cacheRulerTileX - ((double) view.getWidth()) / (2d * view.getTileSize());
double tileNumberRight = cacheRulerTileX + ((double) view.getWidth()) / (2d * view.getTileSize());
double dist = MapUtils.getDistance(latitude, MapUtils.getLongitudeFromTile(view.getZoom(), tileNumberLeft), latitude,
MapUtils.getLongitudeFromTile(view.getZoom(), tileNumberRight));
double leftLon = view.calcLongitude(- view.getWidth() / 2);
double rightLon = view.calcLongitude(+ view.getWidth() / 2);
double dist = MapUtils.getDistance(latitude, leftLon, latitude, rightLon);
double pixDensity = view.getWidth() / dist;
double roundedDist = OsmAndFormatter.calculateRoundedDist(dist * screenRulerPercent, view.getContext());

View file

@ -420,7 +420,7 @@ public class MapInfoLayer extends OsmandMapLayer {
AnimateDraggingMapThread thread = view.getAnimatedDraggingThread();
LatLon pointToNavigate = view.getSettings().getPointToNavigate();
if (pointToNavigate != null) {
int fZoom = view.getZoom() < 15 ? 15 : view.getZoom();
float fZoom = view.getFloatZoom() < 15 ? 15 : view.getFloatZoom();
thread.startMoving(pointToNavigate.getLatitude(), pointToNavigate.getLongitude(), fZoom, true);
}
}

View file

@ -53,6 +53,9 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
protected final int emptyTileDivisor = 16;
public static final float ZOOM_DELTA = 3;
public static final float ZOOM_DELTA_1 = 1/3f;
public interface OnTrackBallListener {
public boolean onTrackBallEvent(MotionEvent e);
@ -330,8 +333,18 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
return (int) zoom;
}
public float getFloatZoom() {
return zoom;
}
public boolean isZooming(){
return zoom != getZoom();
// zooming scale
float diff = (zoom - getZoom()) * ZOOM_DELTA;
if(Math.abs(diff - Math.round(diff)) < 0.0001) {
return false;
}
return true;
// return zoom != getZoom();
}
public void setMapLocationListener(IMapLocationListener l) {
@ -392,6 +405,29 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
this.mapPosition = type;
}
public double calcLongitude(int pixelFromCenter) {
return MapUtils.getLongitudeFromTile(getZoom(), getXTile() + pixelFromCenter / getTileSize());
}
public double calcLatitude(int pixelFromCenter) {
return MapUtils.getLatitudeFromTile(getZoom(), getXTile() + pixelFromCenter / getTileSize());
}
public void calculateLatLonRectangle(Rect pixRect, RectF latLonRect) {
int z = (int) zoom;
float tileX = (float) MapUtils.getTileNumberX(z, getLongitude());
float tileY = (float) MapUtils.getTileNumberY(z, getLatitude());
float w = getCenterPointX();
float h = getCenterPointY();
RectF tilesRect = new RectF();
calculateTileRectangle(pixRect, w, h, tileX, tileY, tilesRect);
latlonRect.top = (float) MapUtils.getLatitudeFromTile(z, tilesRect.top);
latlonRect.left = (float) MapUtils.getLongitudeFromTile(z, tilesRect.left);
latlonRect.bottom = (float) MapUtils.getLatitudeFromTile(z, tilesRect.bottom);
latlonRect.right = (float) MapUtils.getLongitudeFromTile(z, tilesRect.right);
}
public void calculateTileRectangle(Rect pixRect, float cx, float cy, float ctilex, float ctiley, RectF tileRect) {
float x1 = calcDiffTileX(pixRect.left - cx, pixRect.top - cy);

View file

@ -82,8 +82,11 @@ public class PointLocationLayer extends OsmandMapLayer {
int locationX = view.getMapXForPoint(lastKnownLocation.getLongitude());
int locationY = view.getMapYForPoint(lastKnownLocation.getLatitude());
int radius = MapUtils.getLengthXFromMeters(view.getZoom(), view.getLatitude(), view.getLongitude(),
lastKnownLocation.getAccuracy(), view.getTileSize(), view.getWidth());
double lonLeft = view.calcLongitude(- view.getWidth() / 2);
double lonRight = view.calcLongitude(+ view.getWidth() / 2);
double dist = MapUtils.getDistance(view.getLatitude(), lonLeft, view.getLatitude(), lonRight);
int radius = (int) (((double) view.getWidth()) / dist * lastKnownLocation.getAccuracy());
if (radius > RADIUS * dm.density) {
int allowedRad = Math.min(view.getWidth() / 2, view.getHeight() / 2);
canvas.drawCircle(locationX, locationY, Math.min(radius, allowedRad), area);

View file

@ -73,7 +73,7 @@ public class RouteInfoLayer extends OsmandMapLayer implements IRouteInformationL
if(info.getDescriptionRoute() != null) {
contextMenu.setLocation(new LatLon(l.getLatitude(), l.getLongitude()), info.getDescriptionRoute());
}
view.getAnimatedDraggingThread().startMoving(l.getLatitude(), l.getLongitude(), view.getZoom(), true);
view.getAnimatedDraggingThread().startMoving(l.getLatitude(), l.getLongitude(), view.getFloatZoom(), true);
}
}
view.refreshMap();
@ -91,7 +91,7 @@ public class RouteInfoLayer extends OsmandMapLayer implements IRouteInformationL
if(info.getDescriptionRoute() != null){
contextMenu.setLocation(new LatLon(l.getLatitude(), l.getLongitude()), info.getDescriptionRoute());
}
view.getAnimatedDraggingThread().startMoving(l.getLatitude(), l.getLongitude(), view.getZoom(), true);
view.getAnimatedDraggingThread().startMoving(l.getLatitude(), l.getLongitude(), view.getFloatZoom(), true);
}
view.refreshMap();
}

View file

@ -23,7 +23,7 @@ public class RouteLayer extends OsmandMapLayer {
private final RoutingHelper helper;
private Rect boundsRect;
private RectF tileRect;
private RectF latlonRect;
private List<Location> points = new ArrayList<Location>();
private Paint paint;
@ -38,7 +38,7 @@ public class RouteLayer extends OsmandMapLayer {
private void initUI() {
boundsRect = new Rect(0, 0, view.getWidth(), view.getHeight());
tileRect = new RectF();
latlonRect = new RectF();
paint = new Paint();
fluorescent = view.getSettings().FLUORESCENT_OVERLAYS.get();
if (view.getSettings().FLUORESCENT_OVERLAYS.get()) {
@ -77,12 +77,11 @@ public class RouteLayer extends OsmandMapLayer {
} else {
boundsRect = new Rect(0, 0, w, h);
}
view.calculateTileRectangle(boundsRect, view.getCenterPointX(), view.getCenterPointY(), view.getXTile(), view.getYTile(),
tileRect);
double topLatitude = MapUtils.getLatitudeFromTile(view.getZoom(), tileRect.top);
double leftLongitude = MapUtils.getLongitudeFromTile(view.getZoom(), tileRect.left);
double bottomLatitude = MapUtils.getLatitudeFromTile(view.getZoom(), tileRect.bottom);
double rightLongitude = MapUtils.getLongitudeFromTile(view.getZoom(), tileRect.right);
view.calculateLatLonRectangle(boundsRect, latlonRect);
double topLatitude = latlonRect.top;
double leftLongitude = latlonRect.left;
double bottomLatitude = latlonRect.bottom;
double rightLongitude = latlonRect.right;
double lat = topLatitude - bottomLatitude + 0.1;
double lon = rightLongitude - leftLongitude + 0.1;
fillLocationsToShow(topLatitude + lat, leftLongitude - lon, bottomLatitude - lat, rightLongitude + lon);