mapbox / mapbox-maps-android

Interactive, thoroughly customizable maps in native Android powered by vector tiles and OpenGL.
https://www.mapbox.com/mobile-maps-sdk
Other
464 stars 131 forks source link

Bizarre marker rendering issues after v10 migration #2048

Open Orbyt opened 1 year ago

Orbyt commented 1 year ago

Environment

Observed behavior and steps to reproduce

After migrating an application to v10, rendered markers ("annotations") have very strange behavior. The icons will occasionally turn black or render with a black outline if clicked or after zooming the map. The markers then reset to their original icon after moving the map around.

Expected behavior

Markers ("annotations") render with their appropriate icons.

Notes / preliminary analysis

This issue was not observed in older version of Mapbox. I tested the issue using various marker icons, including the "red_marker.png" icon provided by Mapbox. The issue was observed with every icon that was tested.

The implementation is very basic and primarily uses the code provided by Mapbox in the migration guide.

Regardless, here is some code from the application:

private void setUpMap() {                                                                                             
    mMapView.getMapboxMap().loadStyleUri(Style.MAPBOX_STREETS, new Style.OnStyleLoaded() {                 
        @Override                                                                                          
        public void onStyleLoaded(@NotNull Style style) {                                                                                                         
            mMapboxMap = mMapView.getMapboxMap();                                                          

            // Create an instance of the Annotation API and get the PointAnnotationManager.                
            AnnotationPlugin annotationApi = AnnotationPluginImplKt.getAnnotations(mMapView);              
            mPointAnnotationManager =                                                                      
                    PointAnnotationManagerKt.createPointAnnotationManager(annotationApi, mMapView);        
            mPointAnnotationManager.addClickListener(TaskMapActivity.this);                                

            setMapSettings();                                                                              
            populateTasksFromCache();                                                                      
            getTasks();                                                                                                     
        }                                                                                                  
    });                                                                                                    
}                                                                                                          

private Bitmap convertDrawableToBitmap(Context context, @DrawableRes int resourceId) {       
    Drawable sourceDrawable = AppCompatResources.getDrawable(context, resourceId);
    if (sourceDrawable == null) {                                                            
        return null;                                                                         
    }                                                                                        
    if (sourceDrawable instanceof BitmapDrawable) {                                          
        return ((BitmapDrawable) sourceDrawable).getBitmap();                                
    } else {                                                                                 
        // copying drawable object to not manipulate on the same reference                   
        Drawable.ConstantState constantState = sourceDrawable.getConstantState();            
        if (constantState == null) return null;                                              
        Drawable drawable = constantState.newDrawable().mutate();                            
        Bitmap bitmap = Bitmap.createBitmap(                                                 
                drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),                 
                Bitmap.Config.ARGB_8888);                                                    
        Canvas canvas = new Canvas(bitmap);                                                  
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());                     
        drawable.draw(canvas);                                                               
        return bitmap;                                                                       
    }                                                                                        
} 

@Override                                                                                                              
public boolean onAnnotationClick(@NotNull PointAnnotation marker) {                                                    
    // If the clicked marker is already selected,                                                                      
    // do nothing.                                                                                                     
    if (mSelectedAnnotation == marker) {                                                                               
        return true;                                                                                                   
    }                                                                                                                  
    final String id = marker.getData().getAsString();                                                                  
    Task task = null;                                                                                                  
    for (Task t : mTasks) {                                                                                            
        if (t.getId().equals(id)) {                                                                                    
            task = t;                                                                                                  
            break;                                                                                                     
        }                                                                                                              
    }                                                                                                                  

    if (task != null) {                                                                                                
        if (mSelectedAnnotation != null) {                                                                             
            // Reset the previously selected marker.                                                                   
            mSelectedAnnotation.setIconImageBitmap(convertDrawableToBitmap(TaskMapActivity.this, R.drawable.marker));  
            mPointAnnotationManager.update(mSelectedAnnotation);                                                       
        }                                                                                                              

        mSelectedAnnotation = marker;                                                                                  
        marker.setIconImageBitmap(convertDrawableToBitmap(TaskMapActivity.this, R.drawable.marker_selected));          
        mPointAnnotationManager.update(marker);                                                                        

        if (mTaskDetail.getVisibility() == View.GONE) animateIn();                                                     
        populateTask(id);                                                                                              
    }                                                                                                                  
    return true;                                                                                                       
}                                                                                                                                                                                                                 

Please let me know if any other code if required.

Additional links and references

See attached videos. buggy_recording_3.webm buggy_renders_red_marker.webm

baleboy commented 1 year ago

Hi @Orbyt, could you confirm whether you see the same behaviour on device? We have had emulator-specific issues such as this and would like to understand if this is one of those.

yunikkk commented 1 year ago

Seems related to https://github.com/mapbox/mapbox-maps-android/issues/1031

Orbyt commented 1 year ago

Hi @Orbyt, could you confirm whether you see the same behaviour on device? We have had emulator-specific issues such as this and would like to understand if this is one of those.

@baleboy Unfortunately, I do not have a physical device to test with at the moment, so I can not immediately verify whether or not the issue is also present on a physical device.

Seems related to #1031

@yunikkk That does seem related. Are there any indicators as to what the issue may be? That issue seems to be over a year old with a lot of supporting reports.