add multiple ClusterManager to Google map

2019-04-06 10:49发布

问题:

I am trying to use two ClusterManager for Google Map , But I am able to add only one clustermanager and it's item click event,

googleMap.setOnMarkerClickListener(mClusterManager);

and

mClusterManager.setOnClusterItemClickListener(new OnClusterItemClickListener<Person>() {

    @Override
    public boolean onClusterItemClick(Person item) {
        Log.v("Cluster Click", "Item Click:"+item.getName());
        return true;
    }
});

How can I add one more clustermanager to googlemap?

Thanks in advance.

回答1:

yes, delegate the click listener through to both cluster managers.

map.setOnClickListener(new GoogleMap.OnMarkerClickListener() {
  boolean onMarkerClick(Marker m) {
    clusterManager1.onMarkerClick(m)
    clusterManager2.onMarkerClick(m)
  }
});


回答2:

you can use MarketManager like this:

MarkerManager markerManager = new MarkerManager(mMap);

mClusterManager1 = new ClusterManager<>(getContext(), mMap,markerManager);
mClusterManager2 = new ClusterManager<>(getContext(), mMap,markerManager);

mMap.setOnMarkerClickListener(markerManager);

mMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
        @Override
        public void onCameraChange(CameraPosition cameraPosition) {
            mClusterManager1.onCameraChange(cameraPosition);
            mClusterManager2.onCameraChange(cameraPosition);
        }
    });


mClusterManager1.setRenderer(myClusterRenderer1 = new MyClusterRenderer(getContext(), mMap, mClusterManager1));
mClusterManager2.setRenderer(myClusterRenderer2 = new MyClusterRenderer(getContext(), mMap, mClusterManager2));