/**
   * Manipulates the map once available. This callback is triggered when the map is ready to be
   * used. This is where we can add markers or lines, add listeners or move the camera. In this
   * case, we just add a marker near Sydney, Australia. If Google Play services is not installed on
   * the device, the user will be prompted to install it inside the SupportMapFragment. This method
   * will only be triggered once the user has installed Google Play services and returned to the
   * app.
   */
  @Override
  public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    mClusterManager = new ClusterManager<>(this, mMap);
    mClusterManager.setRenderer(new CaseRenderer());
    mClusterManager.setOnClusterClickListener(this);
    mClusterManager.setOnClusterItemInfoWindowClickListener(this);

    //        mClusterManager.getClusterMarkerCollection().setOnInfoWindowAdapter(new
    // MyCustomAdapterForClusters());
    //        mMap.setInfoWindowAdapter(mClusterManager.getMarkerManager());

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

    try {
      cases = readMapData();
      Log.d("Heath", "cases size:" + cases.size());
      float average_unit_price = getAverageUnitPrice(cases);
      average_unit_price_90p = average_unit_price * 0.9f;
      average_unit_price_110p = average_unit_price * 1.1f;
    } catch (JSONException e) {
      e.printStackTrace();
    }
    Log.d("CAC", "cases count:" + cases.size());
    mClusterManager.addItems(cases);
    LatLngBounds.Builder builder = new LatLngBounds.Builder();
    for (Case _case : cases) {
      builder.include(_case.getPosition());
    }
    LatLngBounds bounds = builder.build();
    mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 480, 800, 50));
  }
Пример #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()));
  }
Пример #3
0
  // set the clusters for map
  public void setUpClusterer() {
    // define clustermanager
    mClusterManager = new ClusterManager<>(getActivity().getApplicationContext(), getMap());
    // set a custom renderer for the cluster manager
    mClusterManager.setRenderer(
        new MyClusterRenderer(getActivity().getApplicationContext(), getMap(), mClusterManager));

    mMap.setOnCameraChangeListener(mClusterManager);
    mMap.setOnMarkerClickListener(mClusterManager);

    // when clicking the item clusters we get a list of items
    mClusterManager.setOnClusterClickListener(
        new ClusterManager.OnClusterClickListener<MyItem>() {
          @Override
          public boolean onClusterClick(final Cluster<MyItem> cluster) {
            list_values.clear();
            clickedcluster = cluster;
            // add each item in clusters to the list
            for (MyItem item : cluster.getItems()) {
              List<String> news_item = new ArrayList<>();

              news_item.add(item.getSnippet());
              news_item.add(item.getText());
              news_item.add(item.getDate());
              news_item.add(item.getPlace());
              news_item.add(item.getCategory());
              news_item.add(String.valueOf(item.getLat()));
              news_item.add(String.valueOf(item.getLon()));

              news_item.add(item.getUrl());
              list_values.add(news_item);
            }
            // remove the fab button
            FloatingActionButton fab = (FloatingActionButton) getActivity().findViewById(R.id.fab);
            fab.hide();
            // replace the fragment with the main view
            FragmentManager fm = getFragmentManager();
            Fragment a = fm.findFragmentByTag("FragmentLoc");
            ((SideBar) getActivity()).replacefragment(new NewsListView(), "list");

            return true;
          }
        });
  }
Пример #4
0
  /**
   * 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();
  }
Пример #5
0
  @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());
  }