Search in sources :

Example 46 with RotatedTileBox

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();
        }
    });
}
Also used : RotatedTileBox(net.osmand.data.RotatedTileBox)

Example 47 with RotatedTileBox

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);
            }
        }
    });
}
Also used : RotatedTileBox(net.osmand.data.RotatedTileBox)

Example 48 with RotatedTileBox

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;
        }
    });
}
Also used : LatLon(net.osmand.data.LatLon) RotatedTileBox(net.osmand.data.RotatedTileBox) PointF(android.graphics.PointF) CallbackWithObject(net.osmand.CallbackWithObject) RenderedObject(net.osmand.NativeLibrary.RenderedObject)

Aggregations

RotatedTileBox (net.osmand.data.RotatedTileBox)48 LatLon (net.osmand.data.LatLon)20 QuadPoint (net.osmand.data.QuadPoint)15 Paint (android.graphics.Paint)11 QuadRect (net.osmand.data.QuadRect)8 SuppressLint (android.annotation.SuppressLint)7 View (android.view.View)6 ImageView (android.widget.ImageView)5 ArrayList (java.util.ArrayList)4 Location (net.osmand.Location)4 ITileSource (net.osmand.map.ITileSource)4 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)4 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)4 PointF (android.graphics.PointF)3 TextView (android.widget.TextView)3 List (java.util.List)3 QuadPointDouble (net.osmand.data.QuadPointDouble)3 WptPt (net.osmand.plus.GPXUtilities.WptPt)3 DialogInterface (android.content.DialogInterface)2 Bitmap (android.graphics.Bitmap)2