Skip to content

Instantly share code, notes, and snippets.

@espritm
Created April 5, 2017 16:06
Show Gist options
  • Save espritm/5b0eec6cdd4bac1704f741d7917dfb25 to your computer and use it in GitHub Desktop.
Save espritm/5b0eec6cdd4bac1704f741d7917dfb25 to your computer and use it in GitHub Desktop.
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