Ejemplo n.º 1
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();
      }
    }
  }
Ejemplo n.º 2
0
  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));
  }
  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;
  }
Ejemplo n.º 4
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());
  }