private void setUpClusterer() {

    // Position the map.
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(40.7136487, -74.0087126), 10));

    // Initialize the manager with the context and the map.
    // (Activity extends context, so we can pass 'this' in the constructor.)
    mClusterManager = new ClusterManager<MarkerCluster>(getApplicationContext(), mMap);

    // Point the map's listeners at the listeners implemented by the cluster
    // manager.
    mMap.setOnCameraChangeListener(mClusterManager);

    mClusterManager.setRenderer(
        new ClusterRendring(getApplicationContext(), mMap, mClusterManager));

    mClusterManager.setOnClusterItemClickListener(
        new ClusterManager.OnClusterItemClickListener<MarkerCluster>() {
          @Override
          public boolean onClusterItemClick(MarkerCluster markerCluster) {

            String a = markerCluster.getTitle();
            Toast.makeText(getApplicationContext(), a, Toast.LENGTH_SHORT).show();
            return false;
          }
        });
  }
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()));
  }
  /**
   * This is where we can add markers or lines, add listeners or move the camera. In this case, we
   * just add a marker near Africa.
   *
   * <p>This should only be called once and when we are sure that {@link #mMap} is not null.
   *
   * @param latitude
   * @param longitude
   */
  private void setUpMap(double latitude, double longitude) {
    LatLng latLng = new LatLng(latitude, longitude);
    Log.e("latLng", "lat:" + String.valueOf(latitude) + " lng:" + String.valueOf(longitude));
    mMap.addMarker(new MarkerOptions().position(latLng).title("Marker"));
    mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 14));

    clusterManager = new ClusterManager<MarkerData>(this, mMap);
    clusterManager.setRenderer(new MarkerRender());

    mMap.setOnCameraChangeListener(clusterManager);
    mMap.setOnMarkerClickListener(clusterManager);
    mMap.setOnInfoWindowClickListener(clusterManager);

    clusterManager.setOnClusterClickListener(this);
    clusterManager.setOnClusterInfoWindowClickListener(this);
    clusterManager.setOnClusterItemClickListener(this);
    clusterManager.setOnClusterItemInfoWindowClickListener(this);

    addItems();
    clusterManager.cluster();
  }
  @Override
  public void onConnected(Bundle bundle) {

    worldMap.clear();

    filePaths = new HashMap<Marker, String>();
    tempFilePaths = new HashMap<MyItem, String>();
    icons = new HashMap<MyItem, Bitmap>();

    manager =
        new ClusterManager<MyItem>(this, worldMap) {

          @Override
          public void onInfoWindowClick(Marker marker) {
            super.onInfoWindowClick(marker);

            marker.hideInfoWindow();

            currentLat = marker.getPosition().latitude;
            currentLng = marker.getPosition().longitude;

            startEditActivity(filePaths.get(marker));
          }
        };

    manager.setRenderer(new MyClusterRenderer(this, worldMap, manager));

    if (!loaded) {
      PictureLoader loader = new PictureLoader(this);
      loader.execute();
    } else {
      // an Async task actually slows the loading! The loading is almost instantaneous.
      // Reloader reloader = new Reloader();
      // reloader.execute();
      ArrayList<String> files = dataRestorer.getFiles();
      ArrayList<Bitmap> bits = dataRestorer.getBitmaps();
      ArrayList<Float> lats = dataRestorer.getLats();
      ArrayList<Float> lngs = dataRestorer.getLngs();

      for (int i = 0; i < files.size(); i++) {
        Bitmap bitmap = bits.get(i);
        if (fileToReload != null && files.get(i).equals(fileToReload)) {
          Bitmap bmp = BitmapFactory.decodeFile(fileToReload);
          bitmap =
              Bitmap.createScaledBitmap(
                  bmp, (int) (((float) bmp.getWidth() / bmp.getHeight()) * 50), 50, false);

          dataRestorer.replaceBitmap(i, bitmap);
        }
        MyItem item = new MyItem(lats.get(i), lngs.get(i));
        tempFilePaths.put(item, files.get(i));
        icons.put(item, bitmap);

        manager.addItem(item);
      }
    }

    worldMap.setOnCameraChangeListener(manager);
    worldMap.setOnMarkerClickListener(manager);
    worldMap.setOnInfoWindowClickListener(manager);

    manager.setOnClusterClickListener(this);
    manager.setOnClusterItemClickListener(this);

    /* enable MyLocation layer to show the current location as a blue dot */
    worldMap.setMyLocationEnabled(true);
    zoomToCurrentLocation();

    worldMap.setInfoWindowAdapter(new CustomInfoWindowAdapter());
  }