Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Updating position of image/icon on map #1521

Closed
richjhart opened this issue Nov 12, 2018 · 10 comments
Closed

Question: Updating position of image/icon on map #1521

richjhart opened this issue Nov 12, 2018 · 10 comments

Comments

@richjhart
Copy link

I need to place several icons on my map, and need to be able to move them around. There seems to be two ways of doing this, but both have a different problem that I can't seem to work around at the moment.

  1. Simply add the points to the map using addMarker(). This has the following problems:
    a) Which image ends up on top seems to be random
    b) I don't think I can rotate the marker, which I may need to be able to do

  2. Use two SymbolLayers. This has the following problem:
    When I update the source with a feature at the new position, the icon generally disappears and appears in the new position. This means I can't seem to animate the movement.

@danesfeder
Copy link
Contributor

Hey @richjhart 👋 - if I'm understanding correctly, addMarker doesn't offer the customization you need here.

I think our new annotations plugin may be helpful here. Documentation is here.

You would be able to create a Manager of your choice after the NavigationView is initialized with NavigationView#retrieveNavigationMapboxMap()#retrieveMap which returns a MapboxMap.

To animate, you can use an ObjectAnimator to set the LatLng of the Symbol each time the animation updates https://github.com/mapbox/mapbox-plugins-android/blob/master/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/Symbol.java#L135-L137.

See also https://github.com/mapbox/mapbox-gl-native/blob/master/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/AnimatedSymbolLayerActivity.java.

I'm going to go ahead and close this as non-actionable on the SDK part. I hope the tips here help out a bit. Thanks!

cc @tobrun @LukasPaczos to double check I'm speaking correctly here.

@richjhart
Copy link
Author

@danesfeder Thanks for the quick reply. From a quick look at the documentation and links, it appears to be exactly what we're after.

@richjhart
Copy link
Author

@danesfeder Unfortunately, I am still having some issues with this.

Note that I am unable to use an ObjectAnimator for the LatLng, because that simply updates the LatLng but a call to SymbolManager.update() is also required - so I'm using a ValueAnimator instead to include that call. (That is fine though).

What I am finding is that even during an animation, the symbol is disappearing for a brief period during the middle of the animation if I move it too far (or if it jumps - i.e. not animating it). As far as I can tell, this is reasonably consistent - and might be deliberate, because it's very smooth if it's moving a short enough distance, so it doesn't seem to be a performance thing. Basically such that if the symbol moves more than a certain distance between calls, it is cleared for a time before appearing in the new position.

This doesn't occur with a Marker, where setting the position using an ObjectAnimator works fine and it never disappears when animating (I'm not actually sure what happens if it jumps).

Is there an option/configuration to allow it to not disappear during the transition?

@LukasPaczos
Copy link

The fade in/out you are seeing is most likely the symbol collision algorithm. Would you mind retesting your setup after calling below?

symbolManager.setIconAllowOverlap(true);
symbolManager.setIconIgnorePlacement(true);

This will disable collision detection but will get rid of the fade as well. You can read more about those properties in the style specification.

@richjhart
Copy link
Author

Thanks @LukasPaczos, that seems to have done the trick. I did notice those properties but I didn't think it would be related because it always seemed to be related to the distance of the jump, not whether any other symbols were present nearby.

I am still finding that occasionally it will disappear briefly, but only when it's very stressed (low spec device, and animating multiple items and moving the map), which we can live with.

But I now have two symbols, animating correctly, in the correct z-order that I need them - so all is good! Thanks @danesfeder @LukasPaczos for the quick replies and the solution!

@danesfeder
Copy link
Contributor

Thanks for the help here @LukasPaczos and glad to hear things are working @richjhart 👍

@richjhart
Copy link
Author

@LukasPaczos @danesfeder I'm now getting a native code crash randomly - I think when using the annotation library. It's difficult to trace exactly where it occurs, but it appears to be related to the annotation (due to referring to a Feature id), and during the animation (due to my most recent debug statements). Any idea what might be causing this?

2018-11-14 11:16:29.110 2802-2802/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2018-11-14 11:16:29.110 2802-2802/? A/DEBUG: Build fingerprint: 'mobvoi/catfish/catfish:8.0.0/OWDM.180807.005/4958364:user/release-keys'
2018-11-14 11:16:29.110 2802-2802/? A/DEBUG: Revision: '0'
2018-11-14 11:16:29.110 2802-2802/? A/DEBUG: ABI: 'arm'
2018-11-14 11:16:29.111 2802-2802/? A/DEBUG: pid: 1809, tid: 1905, name: Thread-2408 >>> com.bynd.looper <<<
2018-11-14 11:16:29.111 2802-2802/? A/DEBUG: signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
2018-11-14 11:16:29.121 2802-2802/? A/DEBUG: Abort message: 'java_vm_ext.cc:504] JNI DETECTED ERROR IN APPLICATION: can't call java.lang.String com.mapbox.geojson.Feature.id() on null object'
2018-11-14 11:16:29.122 2802-2802/? A/DEBUG: r0 00000000 r1 00000771 r2 00000006 r3 00000008
2018-11-14 11:16:29.122 2802-2802/? A/DEBUG: r4 00000711 r5 00000771 r6 94e1b370 r7 0000010c
2018-11-14 11:16:29.122 2802-2802/? A/DEBUG: r8 00000000 r9 94e1b3d1 sl 0000000a fp 94e1b3d0
2018-11-14 11:16:29.122 2802-2802/? A/DEBUG: ip 00000000 sp 94e1b360 lr b2172407 pc b21a296c cpsr 200f0010
2018-11-14 11:16:29.157 2802-2802/? A/DEBUG: backtrace:
2018-11-14 11:16:29.158 2802-2802/? A/DEBUG: #00 pc 0004a96c /system/lib/libc.so (tgkill+12)
2018-11-14 11:16:29.158 2802-2802/? A/DEBUG: #1 pc 0001a403 /system/lib/libc.so (abort+54)
2018-11-14 11:16:29.158 2802-2802/? A/DEBUG: #2 pc 003375ff /system/lib/libart.so (_ZN3art7Runtime5AbortEPKc+230)
2018-11-14 11:16:29.158 2802-2802/? A/DEBUG: #3 pc 00337c8f /system/lib/libart.so (_ZN3art7Runtime7AborterEPKc+10)
2018-11-14 11:16:29.158 2802-2802/? A/DEBUG: #4 pc 003eeb2d /system/lib/libart.so (_ZN7android4base10LogMessageD1Ev+456)
2018-11-14 11:16:29.158 2802-2802/? A/DEBUG: #5 pc 0022fa2b /system/lib/libart.so (ZN3art9JavaVMExt8JniAbortEPKcS2+1262)
2018-11-14 11:16:29.158 2802-2802/? A/DEBUG: #6 pc 0022fc13 /system/lib/libart.so (_ZN3art9JavaVMExt9JniAbortVEPKcS2_St9__va_list+58)
2018-11-14 11:16:29.159 2802-2802/? A/DEBUG: #7 pc 000d24fb /system/lib/libart.so (_ZN3art11ScopedCheck6AbortFEPKcz+46)
2018-11-14 11:16:29.159 2802-2802/? A/DEBUG: #8 pc 000d5399 /system/lib/libart.so (_ZN3art11ScopedCheck17CheckMethodAndSigERNS_18ScopedObjectAccessEP8_jobjectP7_jclassP10_jmethodIDNS_9Primitive4TypeENS_10InvokeTypeE+1228)
2018-11-14 11:16:29.159 2802-2802/? A/DEBUG: #9 pc 000d4117 /system/lib/libart.so (_ZN3art8CheckJNI11CallMethodVEPKcP7_JNIEnvP8_jobjectP7_jclassP10_jmethodIDSt9__va_listNS_9Primitive4TypeENS_10InvokeTypeE+514)
2018-11-14 11:16:29.159 2802-2802/? A/DEBUG: #10 pc 000c517b /system/lib/libart.so (_ZN3art8CheckJNI17CallObjectMethodVEP7_JNIEnvP8_jobjectP10_jmethodIDSt9__va_list+38)
2018-11-14 11:16:29.159 2802-2802/? A/DEBUG: #11 pc 0001f297 /data/app/com.bynd.looper-sOS_1vJElc1ZY-urqOIeCg==/lib/arm/libmapbox-gl.so
2018-11-14 11:16:29.159 2802-2802/? A/DEBUG: #12 pc 00058ac9 /data/app/com.bynd.looper-sOS_1vJElc1ZY-urqOIeCg==/lib/arm/libmapbox-gl.so
2018-11-14 11:16:29.159 2802-2802/? A/DEBUG: #13 pc 000598a5 /data/app/com.bynd.looper-sOS_1vJElc1ZY-urqOIeCg==/lib/arm/libmapbox-gl.so
2018-11-14 11:16:29.160 2802-2802/? A/DEBUG: #14 pc 0010563b /data/app/com.bynd.looper-sOS_1vJElc1ZY-urqOIeCg==/lib/arm/libmapbox-gl.so
2018-11-14 11:16:29.160 2802-2802/? A/DEBUG: #15 pc 001050c3 /data/app/com.bynd.looper-sOS_1vJElc1ZY-urqOIeCg==/lib/arm/libmapbox-gl.so
2018-11-14 11:16:29.160 2802-2802/? A/DEBUG: #16 pc 000687e7 /data/app/com.bynd.looper-sOS_1vJElc1ZY-urqOIeCg==/lib/arm/libmapbox-gl.so
2018-11-14 11:16:29.160 2802-2802/? A/DEBUG: #17 pc 000f20fd /data/app/com.bynd.looper-sOS_1vJElc1ZY-urqOIeCg==/lib/arm/libmapbox-gl.so
2018-11-14 11:16:29.160 2802-2802/? A/DEBUG: #18 pc 00047c8f /system/lib/libc.so (_ZL15__pthread_startPv+22)
2018-11-14 11:16:29.160 2802-2802/? A/DEBUG: #19 pc 0001afad /system/lib/libc.so (__start_thread+32)

@LukasPaczos
Copy link

At first glance, it looks like we are somehow passing a null feature to the core, which shouldn't be possible. @richjhart would you mind opening a new issue in the https://github.com/mapbox/mapbox-plugins-android? Any repro steps/code would be extremely helpful. Thanks!

@richjhart
Copy link
Author

@LukasPaczos I have raised mapbox/mapbox-plugins-android#770

It's quite likely we're doing something wrong - maybe we're passing invalid coordinates or something at some point, which might be setting up an invalid state. But obviously I'd expect an IllegalArgumentException or IllegalStateException if that was the case.

@LukasPaczos
Copy link

Thank you for all the info in mapbox/mapbox-plugins-android#770, we'll investigate this one further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants