KasparTr KasparTr - 3 months ago 42
Android Question

Android- attaching InfoWindowAdapter to GoogleMap with multiple ClusterManagers

I have a Google Maps V2 and in my setUpMap() method I am attaching the GoogleMap an infoWindowAdapter like so:

ClusterManager<OffersMarker> rentClusterManager = new ClusterManager<OffersMarker>(this, gmap);
gmap.setInfoWindowAdapter(rentClusterManager.getMarkerManager());


There is more code but the point is that this works and I can see the infoWindow when I click on the marker.

Since I have two ClusterManagers thou I have a problem:

ClusterManager<OffersMarker> rentClusterManager = new ClusterManager<OffersMarker>(this, gmap);
ClusterManager<OffersMarker> saleClusterManager = new ClusterManager<OffersMarker>(this, gmap);

gmap.setInfoWindowAdapter(rentClusterManager.getMarkerManager()); //<-- THIS DOESN'T WORK
gmap.setInfoWindowAdapter(saleClusterManager.getMarkerManager()); //<-- ONLY THIS WORKS


My question, how do I attach multiple ClusterManager.getMarkerManager() to infoWindowAdapter setup?

With listeners I used MultiListener but I haven't found a MultiAdapter or anything like that.

Thanks!

Answer

You can only set a single InfoWindowAdapter to GoogleMap object. In your case it is being overwritten by saleClusterManager.getMarkerManager()

But as a workaround you can forward calls to respective cluster managers.

gmap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter()
{
    @Override
    public View getInfoWindow(Marker marker)
    {
        View view = rentClusterManager.getMarkerManager().getInfoWindow(marker);
        if( view == null )
            view = saleClusterManager.getMarkerManager().getInfoWindow(marker);
        return view;
    }

    @Override
    public View getInfoContents(Marker marker)
    {
        View view = rentClusterManager.getMarkerManager().getInfoContents(marker);
        if( view == null )
            view = saleClusterManager.getMarkerManager().getInfoContents(marker);
        return view;
    }
});