Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

onCameraChange calls during camera animation (by touch) #4746

Closed

Description

@programmerr47

This is copy of my comment: #3745 (comment)

Hello. Sorry for inconvenience but could you please help me with my porblem.
I'm writing android app with help of Android Studio. I'm using gradle and targetSdk 23. Also I'm using mapbox sdk 4.0.0-beta.2.

In my fragment I initialize mapbox maps something like this:

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        ...
        mapView.onCreate(null);
        setupMapView(getActivity());
        ...
    }

    private void setupMapView(Context context) {
        ...
        mapView.getMapAsync(this);
        ...
    }

    @Override
    public void onMapReady(@NonNull MapboxMap mapboxMap) {
        this.mapboxMap = mapboxMap;
        ...
        this.mapboxMap.setOnCameraChangeListener(this);
        ...
    }

    @Override
    public void onCameraChange(CameraPosition cameraPosition) {
        Log.v("TestLog", "OnCameraChange: " + cameraPosition);
    }

When I run my project and try to use scroll or fling gestures on the map (without stopping it), I see in logs that onCameraChange calls every 400 ms (average). But for me expected result that it called only one time: when camera will be stopped.

Maybe described situation is correct, but as I understood MapBox's OnCameraChangeListener is analog of GoogleMaps's OnCameraChangeListener and last works in the way that I described (onCameraChange calls only when camera will be in "idle" state). At least in mapbox documentation said same thing as in google maps documentation:

Called after the camera position has changed. During an animation, this listener may not be notified of intermediate camera positions. It is always called for the final position in the animation.

I came to this problem, because earlier I used google maps and used onCameraChange callback as indicator that map is in idle state (because I hide controls when work with map and want to show them, when camera is idle and I don't touch to map), and now I need to migrate to mapbox (because you have more and more better detalization of maps for some countries, like Russia), and I stunned with this problem.

So if it is not hard to you, could you please help me? Is calling onCameraChange during camera animation a bug or not? If not, does mapbox provide callbacks to know when camera is in the idle state?

Thank you.

BTW:
I'm testing on Nexus 5, v.6.0.1. And the previous example worked on Google maps.

Activity

  1. added
    Android
    on Apr 19, 2016
  2. tobrun commented on Apr 19, 2016

    @tobrun
    Member

    @programmerr47
    Thank you for reaching out and reporting your issue.

    Is calling onCameraChange during camera animation a bug or not?

    I consider this not a bug since the listener may be notified during animation (in some cases it will not). This is in my opinion compliant to the javadoc.

    Called after the camera position has changed. During an animation, this listener may not be notified of intermediate camera positions. It is always called for the final position in the animation.

    That said, we try to aim to be on par with Google and I feel this request makes sense for your use-case. I need to look into the details and see if this change wouldn't impact other parts. FWIW it would reduce the amount of roundtrips made through JNI which would be better for performance.

    👀 @bleege @zugaldia @cammace

  3. programmerr47 commented on Apr 20, 2016

    @programmerr47
    Author

    @tobrun

    Thank you for your answer. I appreciate that you interested in my usecase. If it turns out that the behavior is normal and does not require any changes, could you please provide some callback for finishing changing camera position, or may be promt some workaround, how I can acheive something similar with using mapbox sdk?

    Anyway, thank you for your attention.

  4. tobrun commented on Apr 20, 2016

    @tobrun
    Member

    @programmerr47 the workaround for now could be to listen to MapChange event by calling mapView.addOnMapChangedListener. You will receive back an int value reflecting these states:

    /**
         * <p>
         * This {@link MapChange} is triggered whenever the currently displayed map region is about to changing
         * without an animation.
         * </p>
         * <p>
         * This event is followed by a series of {@link MapView#REGION_IS_CHANGING} and ends
         * with {@link MapView#REGION_DID_CHANGE}.
         * </p>
         *
         * @see MapView.OnMapChangedListener
         */
        public static final int REGION_WILL_CHANGE = 0;
    
        /**
         * <p>
         * This {@link MapChange} is triggered whenever the currently displayed map region is about to changing
         * with an animation.
         * </p>
         * <p>
         * This event is followed by a series of {@link MapView#REGION_IS_CHANGING} and ends
         * with {@link MapView#REGION_DID_CHANGE_ANIMATED}.
         * </p>
         *
         * @see MapView.OnMapChangedListener
         */
        public static final int REGION_WILL_CHANGE_ANIMATED = 1;
    
        /**
         * <p>
         * This {@link MapChange} is triggered whenever the currently displayed map region is changing.
         * </p>
         *
         * @see MapView.OnMapChangedListener
         */
        public static final int REGION_IS_CHANGING = 2;
    
        /**
         * <p>
         * This {@link MapChange} is triggered whenever the currently displayed map region finished changing
         * without an animation.
         * </p>
         *
         * @see MapView.OnMapChangedListener
         */
        public static final int REGION_DID_CHANGE = 3;
    
        /**
         * <p>
         * This {@link MapChange} is triggered whenever the currently displayed map region finished changing
         * with an animation.
         * </p>
         *
         * @see MapView.OnMapChangedListener
         */
        public static final int REGION_DID_CHANGE_ANIMATED = 4;
    
        /**
         * <p>
         * This {@link MapChange} is triggered when the map is about to start loading a new map style.
         * </p>
         * <p>
         * This event is followed by {@link MapView#DID_FINISH_LOADING_MAP} or
         * {@link MapView#DID_FAIL_LOADING_MAP}.
         * </p>
         *
         * @see MapView.OnMapChangedListener
         */
        public static final int WILL_START_LOADING_MAP = 5;
    
        /**
         * <p>
         * This {@link MapChange} is triggered when the map has successfully loaded a new map style.
         * </p>
         *
         * @see MapView.OnMapChangedListener
         */
        public static final int DID_FINISH_LOADING_MAP = 6;
    
        /**
         * <p>
         * This {@link MapChange} is currently not implemented.
         * </p>
         * <p>
         * This event is triggered when the map has failed to load a new map style.
         * </p>
         *
         * @see MapView.OnMapChangedListener
         */
        public static final int DID_FAIL_LOADING_MAP = 7;
    
        /**
         * <p>
         * This {@link MapChange} is currently not implemented.
         * </p>
         *
         * @see MapView.OnMapChangedListener
         */
        public static final int WILL_START_RENDERING_FRAME = 8;
    
        /**
         * <p>
         * This {@link MapChange} is currently not implemented.
         * </p>
         *
         * @see MapView.OnMapChangedListener
         */
        public static final int DID_FINISH_RENDERING_FRAME = 9;
    
        /**
         * <p>
         * This {@link MapChange} is currently not implemented.
         * </p>
         *
         * @see MapView.OnMapChangedListener
         */
        public static final int DID_FINISH_RENDERING_FRAME_FULLY_RENDERED = 10;
    
        /**
         * <p>
         * This {@link MapChange} is currently not implemented.
         * </p>
         *
         * @see MapView.OnMapChangedListener
         */
        public static final int WILL_START_RENDERING_MAP = 11;
    
        /**
         * <p>
         * This {@link MapChange} is currently not implemented.
         * </p>
         *
         * @see MapView.OnMapChangedListener
         */
        public static final int DID_FINISH_RENDERING_MAP = 12;

    You can than add a idle timeout construct to check if your map has been idle for a couple of seconds.

  5. programmerr47 commented on Apr 28, 2016

    @programmerr47
    Author

    @tobrun Hello. Sorry for disturbing, but do you have any updates regarding this issue?

  6. tobrun commented on May 24, 2016

    @tobrun
    Member

    @programmerr47 this is currently not a high priority to take up. I'm trying to prioritise this feature in one of the following releases. Have you tried creating a timeout construct mentioned above? Let me know if you need help with that.

  7. programmerr47 commented on May 24, 2016

    @programmerr47
    Author

    @tobrun I found another workaround. I hung up touch listener to map and OnMapChangedListener. Then I try to determine, whether touch was finished with fling gesture or not. If it was then I wait "REGION_DID_CHANGE_ANIMATED" callback, else I wait first onCameraChanged callback after that event.

    But with this approach I had one problem. When I started to write to you, it seems for me, that I found solution in my mind, but anyway...The problem is when I starting to touch to the map and then hold my finger on screen unmoved about 2-3 seconds and then try to move map, the map is not moving. Here is my steps:

    1. Open map.
    2. Put finger on screen and dont move
    3. Wait 1,2,3,4... seconds
    4. Not releasing touch, try to move finger
    5. In this step I see, that map not moving, only after "retouching"

    Maybe I missed some setting, may be I not enabled some setting. Do you know what can it be?

    Thank you.

  8. tobrun commented on May 24, 2016

    @tobrun
    Member

    @programmerr47 I'm not seeing this with the default implementation. I'm guessing you returning true in onTouch at some point where you should have returned false. True indicates the touch has been handled and that the parent viewgroup should not look into handling the touch event. False indicates the touch event has not been handled and should be handled by the parent.

  9. programmerr47 commented on May 24, 2016

    @programmerr47
    Author

    @tobrun I return result of super. And I see on logs, that my touches works, but map not moving. Anyway thank you for paying attention and trying to help me. I will try to erase some blocks of code to determine place of the problem. Thank you.

  10. added
    SEMVER-MAJOR
    on Aug 10, 2016
  11. tobrun commented on Nov 7, 2016

    @tobrun
    Member

    Fixed with solution proposed in #6919. In that PR i'm making the implementation more simplistic by solely relying on MapChange events and thus complying to the use case set by the OP here. Closing.

  12. self-assigned this
    on Nov 7, 2016
  13. maxmiranda commented on Jun 3, 2022

    @maxmiranda

    Is there anything like this for iOS? @tobrun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

AndroidSEMVER-MAJOR

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions