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

Markers are not drawn correctly #10077

Closed
dnapolloteam opened this issue Sep 27, 2017 · 7 comments
Closed

Markers are not drawn correctly #10077

dnapolloteam opened this issue Sep 27, 2017 · 7 comments

Comments

@dnapolloteam
Copy link

dnapolloteam commented Sep 27, 2017

Platform: Android
Mapbox SDK version: 5.1.4

Steps to trigger behavior

  1. Add current location marker on map.
    2.Readd current location when user have change location and heading also
    3.Marker render wrong.

Expected behavior

Can be draw when location and heading update.
2017_09_27_09_41_02

Actual behavior

Black marker happen
2017_09_27_09_40_32

@tobrun
Copy link
Member

tobrun commented Sep 27, 2017

@dnapolloteam could you add some code how you are creating the icon? I'm guessing you create an Icon for each update? You need to optimise your icon management separate from your location updates. This will be faster and will also remove issues as shown above.

@dnapolloteam
Copy link
Author

I'm sorry I still don't understand your mean could you help me explain more detail. We update icon when location and heading will change this is my code :
@OverRide
public void onUserHeadingChanged(float azimuth) {
Log.d(TAG, "Azimuth " + azimuth);

    if (mGpsButton.getState() == GPSStateButton.ACTIVE && mOwnPositionMarkerAdded) {
        Matrix matrix = new Matrix();
        matrix.setRotate(-azimuth);
        Bitmap bmOrg = BitmapFactory.decodeResource(getResources(), R.drawable.ic_location);
        Bitmap bmRot = Bitmap.createBitmap(bmOrg, 0, 0, bmOrg.getWidth(), bmOrg.getHeight(), matrix, false);
        mOwnPositionMarker.setIcon(IconFactory.getInstance(getContext()).fromBitmap(bmRot));
    }

@tobrun
Copy link
Member

tobrun commented Sep 27, 2017

The issue is that you are creating a new bitmap every time the heading changes. This is not performant and should be optimised as mentioned before. You need to create all possible Icon upfront and storing them in a LongSparseArray where the key = azimuth (to not having to create 360 images I would suggest clamping your values to 5 from eachother).

Your code will look something:

    @Override
    public void onUserHeadingChanged(float azimuth) {
        if (mGpsButton.getState() == GPSStateButton.ACTIVE && mOwnPositionMarkerAdded) {
            float clampedAzimuth = SomeUtilClampingFloats.clamp(azimuth);
            Icon icon = longSpareArray.getValue(clampedAzimuth);
            mOwnPositionMarker.setIcon(icon);
        }

While this is a working around for your issue. What you are actually looking for is way to rotate the icon. So you set the icon once and just change rotation. While we do not expose an API for that atm on Marker you can do this with a SymbolLayer. An example of this is shown in the LocationLayer plugin https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer.

Let us know if you have more questions, I'm going ahead and close this issue, this is a known issue for which we have a workaround.

@tobrun tobrun closed this as completed Sep 27, 2017
@ltphuc5594
Copy link

I try this solution but It has same issues. (save all icon each azimuth).
And LocationLayer plugin don't suitable with the business of my project.

@tobrun
Copy link
Member

tobrun commented Sep 27, 2017

I was only mentioning LocationLayer as a reference to look up code on how that UX was achieved.
Let us know if you run into any issues or crashes! Thank you for using Mapbox.

@dnapolloteam
Copy link
Author

This issue still happen when we try with your solution. We try to init all icon in array and then get it respected with heading change and update current location marker. I thinks this issue happen when we call update marker too much. So do you have some another idea for this case.

@tobrun
Copy link
Member

tobrun commented Sep 29, 2017

Would you be able to retest with a 5.2.0-SNASPHOT build?

To use snapshots, add the snapshots repo in the root build.gradle file:

allprojects {
    repositories {
        jcenter()
        maven { url "http://oss.sonatype.org/content/repositories/snapshots/" }
    }
}

In you app build.gradle replace current dependency with:

    compile(com.mapbox.mapboxsdk:mapbox-android-sdk:5.2.0-SNAPSHOT@aar) {
        transitive = true
    }

This PR #9213 should have solved this issue.

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

No branches or pull requests

3 participants