@Override
  public void onAdd() {
    mClusterManager
        .getMarkerCollection()
        .setOnMarkerClickListener(
            new GoogleMap.OnMarkerClickListener() {
              @Override
              public boolean onMarkerClick(Marker marker) {
                return mItemClickListener != null
                    && mItemClickListener.onClusterItemClick(mMarkerCache.get(marker));
              }
            });

    mClusterManager
        .getMarkerCollection()
        .setOnInfoWindowClickListener(
            new GoogleMap.OnInfoWindowClickListener() {
              @Override
              public void onInfoWindowClick(Marker marker) {
                if (mItemInfoWindowClickListener != null) {
                  mItemInfoWindowClickListener.onClusterItemInfoWindowClick(
                      mMarkerCache.get(marker));
                }
              }
            });

    mClusterManager
        .getClusterMarkerCollection()
        .setOnMarkerClickListener(
            new GoogleMap.OnMarkerClickListener() {
              @Override
              public boolean onMarkerClick(Marker marker) {
                return mClickListener != null
                    && mClickListener.onClusterClick(mMarkerToCluster.get(marker));
              }
            });

    mClusterManager
        .getClusterMarkerCollection()
        .setOnInfoWindowClickListener(
            new GoogleMap.OnInfoWindowClickListener() {
              @Override
              public void onInfoWindowClick(Marker marker) {
                if (mInfoWindowClickListener != null) {
                  mInfoWindowClickListener.onClusterInfoWindowClick(mMarkerToCluster.get(marker));
                }
              }
            });
  }
Exemple #2
0
  private void setUpMap() {

    // Rotate gestures probably aren't needed here and can be disorienting for some of our users.
    mMap.getUiSettings().setRotateGesturesEnabled(false);

    mMap.setOnCameraChangeListener(this);

    CameraPosition position = null;

    // If we were launched with an intent asking us to zoom to a member
    Intent receivedIntent = getIntent();
    if (receivedIntent.hasExtra("target_map_latlng")) {
      LatLng targetLatLng = receivedIntent.getParcelableExtra("target_map_latlng");
      position =
          new CameraPosition(
              targetLatLng, getResources().getInteger(R.integer.map_showhost_zoom), 0, 0);
    }

    if (position == null) {
      position = getSavedCameraPosition();
    }
    if (position != null) {
      mMap.moveCamera(CameraUpdateFactory.newCameraPosition(position));
      // The move itself will end up setting the mlastCameraPosition.
    }

    mClusterManager = new ClusterManager<HostBriefInfo>(this, mMap);
    mClusterManager.setAlgorithm(
        new PreCachingAlgorithmDecorator<HostBriefInfo>(
            new WSNonHierarchicalDistanceBasedAlgorithm<HostBriefInfo>(this)));
    mMap.setOnMarkerClickListener(mClusterManager);
    mMap.setOnInfoWindowClickListener(mClusterManager);
    mClusterManager.setOnClusterClickListener(this);
    mClusterManager.setOnClusterInfoWindowClickListener(this);
    mClusterManager.setOnClusterItemClickListener(this);
    mClusterManager.setOnClusterItemInfoWindowClickListener(this);
    mClusterManager.setRenderer(new HostRenderer());
    mMap.setInfoWindowAdapter(mClusterManager.getMarkerManager());
    mClusterManager
        .getClusterMarkerCollection()
        .setOnInfoWindowAdapter(new ClusterInfoWindowAdapter(getLayoutInflater()));
    mClusterManager
        .getMarkerCollection()
        .setOnInfoWindowAdapter(new SingleHostInfoWindowAdapter(getLayoutInflater()));
  }
 @Override
 public void onRemove() {
   mClusterManager.getMarkerCollection().setOnMarkerClickListener(null);
   mClusterManager.getClusterMarkerCollection().setOnMarkerClickListener(null);
 }