@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));
                }
              }
            });
  }
Ejemplo n.º 2
0
 private void loadOfflineHosts() {
   mClusterManager.clearItems();
   mClusterManager.getMarkerCollection().clear();
   mHosts.clear();
   mClusterManager.addItems(starredHosts);
   mClusterManager.cluster();
 }
Ejemplo n.º 3
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()));
  }
Ejemplo n.º 4
0
  @Override
  public void onCameraChange(CameraPosition position) {
    mLastCameraPosition = position;

    // If not connected, we'll switch to offline/starred hosts mode
    if (!Tools.isNetworkConnected(this)) {
      sendMessage(R.string.map_network_not_connected, false);
      // If we already knew we were offline, return
      if (mIsOffline) {
        return;
      }
      // Otherwise, set state to offline and load only offline hosts
      mIsOffline = true;
      loadOfflineHosts();
      return;
    }

    // If we were offline, switch back on, but remove the offline markers
    if (mIsOffline) {
      mIsOffline = false;
      mClusterManager.clearItems();
      mClusterManager.getMarkerCollection().clear();
      mHosts.clear();
    }

    // And get standard host list for region from server
    LatLngBounds curScreen = mMap.getProjection().getVisibleRegion().latLngBounds;
    Search search = new RestMapSearch(curScreen.northeast, curScreen.southwest);

    if (position.zoom < getResources().getInteger(R.integer.map_zoom_min_load)) {
      sendMessage(R.string.hosts_dont_load, false);
    } else {
      sendMessage(getResources().getString(R.string.loading_hosts), false);
      doMapSearch(search);
    }
  }
 @Override
 public void onRemove() {
   mClusterManager.getMarkerCollection().setOnMarkerClickListener(null);
   mClusterManager.getClusterMarkerCollection().setOnMarkerClickListener(null);
 }