You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
onCameraChange calls during camera animation (by touch) #4746
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:
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.
@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.
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?
@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 */publicstaticfinalintREGION_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 */publicstaticfinalintREGION_WILL_CHANGE_ANIMATED = 1;
/** * <p> * This {@link MapChange} is triggered whenever the currently displayed map region is changing. * </p> * * @see MapView.OnMapChangedListener */publicstaticfinalintREGION_IS_CHANGING = 2;
/** * <p> * This {@link MapChange} is triggered whenever the currently displayed map region finished changing * without an animation. * </p> * * @see MapView.OnMapChangedListener */publicstaticfinalintREGION_DID_CHANGE = 3;
/** * <p> * This {@link MapChange} is triggered whenever the currently displayed map region finished changing * with an animation. * </p> * * @see MapView.OnMapChangedListener */publicstaticfinalintREGION_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 */publicstaticfinalintWILL_START_LOADING_MAP = 5;
/** * <p> * This {@link MapChange} is triggered when the map has successfully loaded a new map style. * </p> * * @see MapView.OnMapChangedListener */publicstaticfinalintDID_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 */publicstaticfinalintDID_FAIL_LOADING_MAP = 7;
/** * <p> * This {@link MapChange} is currently not implemented. * </p> * * @see MapView.OnMapChangedListener */publicstaticfinalintWILL_START_RENDERING_FRAME = 8;
/** * <p> * This {@link MapChange} is currently not implemented. * </p> * * @see MapView.OnMapChangedListener */publicstaticfinalintDID_FINISH_RENDERING_FRAME = 9;
/** * <p> * This {@link MapChange} is currently not implemented. * </p> * * @see MapView.OnMapChangedListener */publicstaticfinalintDID_FINISH_RENDERING_FRAME_FULLY_RENDERED = 10;
/** * <p> * This {@link MapChange} is currently not implemented. * </p> * * @see MapView.OnMapChangedListener */publicstaticfinalintWILL_START_RENDERING_MAP = 11;
/** * <p> * This {@link MapChange} is currently not implemented. * </p> * * @see MapView.OnMapChangedListener */publicstaticfinalintDID_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.
@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.
@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:
Open map.
Put finger on screen and dont move
Wait 1,2,3,4... seconds
Not releasing touch, try to move finger
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?
@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.
@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.
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.
Activity
tobrun commentedon Apr 19, 2016
@programmerr47
Thank you for reaching out and reporting your issue.
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.
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
programmerr47 commentedon Apr 20, 2016
@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.
tobrun commentedon Apr 20, 2016
@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:You can than add a idle timeout construct to check if your map has been idle for a couple of seconds.
programmerr47 commentedon Apr 28, 2016
@tobrun Hello. Sorry for disturbing, but do you have any updates regarding this issue?
tobrun commentedon May 24, 2016
@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.
programmerr47 commentedon May 24, 2016
@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:
Maybe I missed some setting, may be I not enabled some setting. Do you know what can it be?
Thank you.
tobrun commentedon May 24, 2016
@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.
programmerr47 commentedon May 24, 2016
@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.
tobrun commentedon Nov 7, 2016
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.
maxmiranda commentedon Jun 3, 2022
Is there anything like this for iOS? @tobrun