my IconGenerator.makeIcon() doesn't work

483 views Asked by At

I want to use a custom cluster icon so I looked at the android-maps-util demo and adapted it to my needs. First I have a layout for the cluster icon on the model of the multi_profile.xml one. In parenthesis, I didn't understand what is the textView utility... if you have the answer...

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageCluster"
        android:src="@drawable/icon_guide_144_tr" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:id="@+id/textView"
        android:layout_gravity="center" />
</FrameLayout>

And here is my custom cluster renderer:

private class SiteMarkerRenderer extends DefaultClusterRenderer<SiteMarker> {
    private final IconGenerator mClusterIconGenerator = new IconGenerator(getActivity());

    public SiteMarkerRenderer() {
        super(getActivity(), mMap, mClusterManager);

        View multiProfile = getActivity().getLayoutInflater().inflate(R.layout.cluster_icon, null);
        mClusterIconGenerator.setContentView(multiProfile);
    }

    @Override
    protected boolean shouldRenderAsCluster(Cluster cluster) {
        return cluster.getSize() > 5; // if markers <=5 then not clustering
    }

    @Override
    protected void onBeforeClusterItemRendered(SiteMarker item, MarkerOptions markerOptions) {
        markerOptions.icon(item.getMarker().getIcon()).title(item.getMarker().getTitle());
        markerOptions.icon(item.getMarker().getIcon()).snippet(item.getMarker().getSnippet());
    }

    @Override
    protected void onBeforeClusterRendered(Cluster<SiteMarker> cluster, MarkerOptions markerOptions) {

        Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize()));
        markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
    }
}

So Can you tell me why markerOptions.icon() seems to not display anything?

1

There are 1 answers

0
fralbo On

In fact GMaps API V3 cannot mix custom cluster's icon and default cluster's icon made to display the number of markers clustered.