1
I have approximately 1,500 markers on a map that are being shown through clusters so as not to overload the application. these markers are currently shown as BitmapDescriptorFactory.defaultMarker()
However, when I modify the code for each point show a custom bitmap with values over the markers, only a few devices present this error, among them LG K10 LTE and Some Motorolas. In most appliances works normally.
When I use this function, before I finish rendering all 1500 markers, it hangs with the following error:
"Could not allocate dup blob fd."
In researches about this error, it seems to me that this is a memory overflow and that I should store these markers in LRU cache, but I’m not able to do this in conjunction with the clusters.
Has anyone been there or has any idea/suggestion to solve this problem ?
Below is the bitmap rendering code snippet:
public class OwnRendring extends DefaultClusterRenderer<MyItem> {
OwnRendring(Context context, GoogleMap map, ClusterManager<MyItem> clusterManager) {
super(context, map, clusterManager);
}
protected void onBeforeClusterItemRendered(MyItem item, MarkerOptions markerOptions) {
markerOptions.snippet(item.getSnippet());
markerOptions.title(item.getTitle());
markerOptions.anchor(0.33f, 1f);
markerOptions.infoWindowAnchor(0.33f,0f);
int cor = (item.getPublico() ? cfgCorPostoPublico : cfgCorPostoPrivado);
String preço = item.getTitle().substring(item.getTitle().length() - 5);
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(createMarker(preço, cor)));
super.onBeforeClusterItemRendered(item, markerOptions);
}
protected boolean shouldRenderAsCluster(Cluster cluster) {
return cfgCluster && cluster.getSize() >= cfgClusterMin;
}
}
@Override
public void onCameraIdle() {mClusterManager.cluster();}
private Bitmap createMarker(String text, int color) {
View markerLayout = getLayoutInflater().inflate(R.layout.custom_marker, null);
ImageView markerImage = markerLayout.findViewById(R.id.marker_image);
TextView markerRating = markerLayout.findViewById(R.id.marker_text);
markerImage.setImageResource(R.drawable.pin_shadow);
markerImage.clearColorFilter();
markerImage.getDrawable().mutate().setColorFilter(color, PorterDuff.Mode.MULTIPLY );
markerRating.setText(text);
markerLayout.measure(
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
markerLayout.layout(0, 0, markerLayout.getMeasuredWidth(), markerLayout.getMeasuredHeight());
final Bitmap bitmap = Bitmap.createBitmap(
markerLayout.getMeasuredWidth(),
markerLayout.getMeasuredHeight(),
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
markerLayout.draw(canvas);
return bitmap;
}