Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class ClusterRenderer : DefaultClusterRenderer
{
private IconGenerator m_iconGeneratorForMarkerGroup;
private ImageView m_imageviewForMarkerGroup;
public ClusterRenderer(Activity context, GoogleMap map, ClusterManager clusterManager)
: base(context, map, clusterManager)
{
InitViewForMarkerGroup(context);
}
private void InitViewForMarkerGroup(Activity context)
{
//Retrieve views from AXML to display groups of markers (clustering)
View viewMarkerClusterGrouped = context.LayoutInflater.Inflate(Resource.Layout.marker_cluster_grouped, null);
m_imageviewForMarkerGroup = viewMarkerClusterGrouped.FindViewById<ImageView>(Resource.Id.marker_cluster_grouped_imageview);
//Configure the groups of markers icon generator with the view. The icon generator will be used to display the marker's picture with a text
m_iconGeneratorForMarkerGroup = new IconGenerator(context);
m_iconGeneratorForMarkerGroup.SetContentView(viewMarkerClusterGrouped);
m_iconGeneratorForMarkerGroup.SetBackground(null);
}
//Draw a single marker
protected override void OnBeforeClusterItemRendered(Java.Lang.Object p0, MarkerOptions markerOptions)
{
//Icon for single marker
markerOptions.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.marker));
//Text for Info Window
markerOptions.SetTitle(markerOptions.Position.Latitude.ToString() + ", " + markerOptions.Position.Longitude.ToString());
}
//Draw a grouped marker
protected override void OnBeforeClusterRendered(ICluster p0, MarkerOptions markerOptions)
{
//Retrieve the number we have to display inside the group marker
string sNumberOfMarkersGrouped = p0.Size.ToString();
//Icon of a group marker :
// First, set the imageview's source with the right picture
// Then, use the icon generator to set the icon of the marker with the text containing the number of markers grouped
m_imageviewForMarkerGroup.SetImageResource(Resource.Drawable.marker_cluster_grouped);
Bitmap icon = m_iconGeneratorForMarkerGroup.MakeIcon(sNumberOfMarkersGrouped);
markerOptions.SetIcon(BitmapDescriptorFactory.FromBitmap(icon));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment