use of net.osmand.data.RotatedTileBox in project Osmand by osmandapp.
the class AnimateDraggingMapThread method startMoving.
public void startMoving(final double finalLat, final double finalLon, final int endZoom, final boolean notifyListener, final Runnable finishAminationCallback) {
stopAnimatingSync();
final RotatedTileBox rb = tileView.getCurrentRotatedTileBox().copy();
double startLat = rb.getLatitude();
double startLon = rb.getLongitude();
float rotate = rb.getRotate();
final int startZoom = rb.getZoom();
final double startZoomFP = rb.getZoomFloatPart();
boolean skipAnimation = false;
float mStX = rb.getPixXFromLatLon(startLat, startLon) - rb.getPixXFromLatLon(finalLat, finalLon);
float mStY = rb.getPixYFromLatLon(startLat, startLon) - rb.getPixYFromLatLon(finalLat, finalLon);
while (Math.abs(mStX) + Math.abs(mStY) > 1200) {
rb.setZoom(rb.getZoom() - 1);
if (rb.getZoom() <= 4) {
skipAnimation = true;
}
mStX = rb.getPixXFromLatLon(startLat, startLon) - rb.getPixXFromLatLon(finalLat, finalLon);
mStY = rb.getPixYFromLatLon(startLat, startLon) - rb.getPixYFromLatLon(finalLat, finalLon);
}
final int moveZoom = rb.getZoom();
// check if animation needed
skipAnimation = skipAnimation || (Math.abs(moveZoom - startZoom) >= 3 || Math.abs(endZoom - moveZoom) > 3);
if (skipAnimation) {
tileView.setLatLonAnimate(finalLat, finalLon, notifyListener);
tileView.setFractionalZoom(endZoom, 0, notifyListener);
return;
}
final float mMoveX = rb.getPixXFromLatLon(startLat, startLon) - rb.getPixXFromLatLon(finalLat, finalLon);
final float mMoveY = rb.getPixYFromLatLon(startLat, startLon) - rb.getPixYFromLatLon(finalLat, finalLon);
final boolean doNotUseAnimations = tileView.getSettings().DO_NOT_USE_ANIMATIONS.get();
final float animationTime = doNotUseAnimations ? 0 : Math.max(450, (Math.abs(mStX) + Math.abs(mStY)) / 1200f * MOVE_MOVE_ANIMATION_TIME);
startThreadAnimating(new Runnable() {
@Override
public void run() {
setTargetValues(endZoom, finalLat, finalLon);
if (moveZoom != startZoom) {
animatingZoomInThread(startZoom, startZoomFP, moveZoom, startZoomFP, doNotUseAnimations ? 0 : ZOOM_MOVE_ANIMATION_TIME, notifyListener);
}
if (!stopped) {
animatingMoveInThread(mMoveX, mMoveY, animationTime, notifyListener, finishAminationCallback);
}
if (!stopped) {
tileView.setLatLonAnimate(finalLat, finalLon, notifyListener);
}
if (!stopped && (moveZoom != endZoom || startZoomFP != 0)) {
animatingZoomInThread(moveZoom, startZoomFP, endZoom, 0, doNotUseAnimations ? 0 : ZOOM_MOVE_ANIMATION_TIME, notifyListener);
}
tileView.setFractionalZoom(endZoom, 0, notifyListener);
pendingRotateAnimation();
}
});
}
use of net.osmand.data.RotatedTileBox in project Osmand by osmandapp.
the class AnimateDraggingMapThread method startMoving.
public void startMoving(final double finalLat, final double finalLon, final Pair<Integer, Double> finalZoom, final Float finalRotation, final boolean notifyListener) {
stopAnimatingSync();
final RotatedTileBox rb = tileView.getCurrentRotatedTileBox().copy();
double startLat = rb.getLatitude();
double startLon = rb.getLongitude();
final int startZoom = rb.getZoom();
final double startZoomFP = rb.getZoomFloatPart();
final float startRotaton = rb.getRotate();
final int zoom;
final double zoomFP;
final float rotation;
if (finalZoom != null) {
zoom = finalZoom.first;
zoomFP = finalZoom.second;
} else {
zoom = startZoom;
zoomFP = startZoomFP;
}
if (finalRotation != null) {
rotation = finalRotation;
} else {
rotation = startRotaton;
}
final float mMoveX = rb.getPixXFromLatLon(startLat, startLon) - rb.getPixXFromLatLon(finalLat, finalLon);
final float mMoveY = rb.getPixYFromLatLon(startLat, startLon) - rb.getPixYFromLatLon(finalLat, finalLon);
boolean skipAnimation = !rb.containsLatLon(finalLat, finalLon);
if (skipAnimation) {
tileView.setLatLonAnimate(finalLat, finalLon, notifyListener);
tileView.setFractionalZoom(zoom, 0, notifyListener);
tileView.rotateToAnimate(rotation);
return;
}
startThreadAnimating(new Runnable() {
@Override
public void run() {
setTargetValues(zoom, finalLat, finalLon);
boolean animateZoom = finalZoom != null && (zoom != startZoom || startZoomFP != 0);
boolean animateRotation = rotation != startRotaton;
if (animateZoom) {
animatingZoomInThread(startZoom, startZoomFP, zoom, zoomFP, NAV_ANIMATION_TIME, notifyListener);
}
if (animateRotation) {
animatingRotateInThread(rotation, 500f, notifyListener);
}
if (!stopped) {
animatingMoveInThread(mMoveX, mMoveY, NAV_ANIMATION_TIME, notifyListener, null);
}
}
});
}
use of net.osmand.data.RotatedTileBox in project Osmand by osmandapp.
the class ContextMenuLayer method applyNewMarkerPosition.
public void applyNewMarkerPosition() {
if (!mInChangeMarkerPositionMode) {
throw new IllegalStateException("Not in change marker position mode");
}
RotatedTileBox tileBox = activity.getMapView().getCurrentRotatedTileBox();
PointF newMarkerPosition = getMovableCenterPoint(tileBox);
final LatLon ll = tileBox.getLatLonFromPixel(newMarkerPosition.x, newMarkerPosition.y);
applyingMarkerLatLon = ll;
Object obj = getMoveableObject();
cancelApplyingNewMarkerPosition = false;
mMoveMarkerBottomSheetHelper.enterApplyPositionMode();
applyMovedObject(obj, ll, new ApplyMovedObjectCallback() {
@Override
public void onApplyMovedObject(boolean success, @Nullable Object newObject) {
mMoveMarkerBottomSheetHelper.exitApplyPositionMode();
if (success && !cancelApplyingNewMarkerPosition) {
mMoveMarkerBottomSheetHelper.hide();
quitMovingMarker();
menu.close();
view.refreshMap();
}
selectedObjectContextMenuProvider = null;
applyingMarkerLatLon = null;
}
@Override
public boolean isCancelled() {
return cancelApplyingNewMarkerPosition;
}
});
}
Aggregations