Example #1
0
 private void loadOfflineHosts() {
   mClusterManager.clearItems();
   mClusterManager.getMarkerCollection().clear();
   mHosts.clear();
   mClusterManager.addItems(starredHosts);
   mClusterManager.cluster();
 }
  /**
   * 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));
  }
  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;
          }
        });
  }
  @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));
                }
              }
            });
  }
Example #5
0
  // run the query and add the elements to cluster
  private void setUpquery(String qu) {

    try {
      // get database
      database = dbHelper.getDataBase();
      dbCursor = database.rawQuery(qu, SideBar.MenuFilter);
      dbCursor.moveToFirst();

      // get items for each cluster on map from db
      while (!dbCursor.isAfterLast()) {
        MyItem m =
            new MyItem(
                Double.valueOf(this.dbCursor.getString(3)),
                Double.valueOf(this.dbCursor.getString(4)),
                (this.dbCursor.getString(1)),
                (this.dbCursor.getString(2)),
                this.dbCursor.getString(5),
                this.dbCursor.getString(6),
                this.dbCursor.getString(7),
                this.dbCursor.getString(8),
                this.dbCursor.getString(9));

        // add items to database
        mClusterManager.addItem(m);

        dbCursor.moveToNext();
      }

    } finally {
      // close database
      if (database != null) {
        dbHelper.close();
      }
    }
  }
Example #6
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;
          }
        });
  }
Example #7
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()));
  }
  public void addCluster(List<GridPoint> complaintDtos) {
    clearMap();
    GoogleMapCluster googleMapCluster;
    LatLngBounds.Builder builder = new LatLngBounds.Builder();
    ClusterManager<GoogleMapCluster> mClusterManager;
    mClusterManager = new ClusterManager<GoogleMapCluster>(getActivity(), googleMap);
    googleMap.setOnCameraChangeListener(mClusterManager);
    googleMap.setOnMarkerClickListener(mClusterManager);
    for (GridPoint complaintDto : complaintDtos) {
      googleMapCluster =
          new GoogleMapCluster(
              complaintDto.getLocation().getLatitude().doubleValue(),
              complaintDto.getLocation().getLongitude().doubleValue());
      mClusterManager.addItem(googleMapCluster);
      builder.include(googleMapCluster.getPosition());
    }

    if (complaintDtos.size() > 1) {
      LatLngBounds bounds = builder.build();
      CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 0);
      googleMap.animateCamera(cu);
    } else if (complaintDtos.size() > 0) {
      CameraPosition cameraPosition =
          new CameraPosition.Builder()
              .target(
                  new LatLng(
                      complaintDtos.get(0).getLocation().getLatitude().doubleValue(),
                      complaintDtos.get(0).getLocation().getLongitude().doubleValue()))
              .zoom(zoomLevel)
              .bearing(0)
              .tilt(45)
              .build();
      googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
    }
    markersDisplayed = false;
    heatmapDisplayed = false;
    clusterDisplayed = true;
  }
  private void addItems() {
    clusterManager.addItem(new MarkerData(position(), "doge", R.mipmap.doge));

    clusterManager.addItem(new MarkerData(position(), "bike", R.mipmap.bike));

    clusterManager.addItem(new MarkerData(position(), "bird", R.mipmap.bird));

    clusterManager.addItem(new MarkerData(position(), "cat", R.mipmap.cat));

    clusterManager.addItem(new MarkerData(position(), "lizard", R.mipmap.lizzard));

    clusterManager.addItem(new MarkerData(position(), "motorcycle", R.mipmap.motocycle));

    clusterManager.addItem(new MarkerData(position(), "mountain", R.mipmap.mountain));

    clusterManager.addItem(new MarkerData(position(), "waterfall", R.mipmap.waterfall));
  }
Example #10
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);
    }
  }
  /**
   * 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 onRemove() {
   mClusterManager.getMarkerCollection().setOnMarkerClickListener(null);
   mClusterManager.getClusterMarkerCollection().setOnMarkerClickListener(null);
 }
Example #13
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());
  }