Пример #1
0
  public void drawInterest(Interest interest, List<Tag> tags) {

    // System.out.println(interest.getId());

    List<GeoPt> locations = interest.getLocations();

    if (locations.isEmpty()) return;

    if (locations.size() == 1) {

      // draw a marker
      String markerText = "";

      // coordinates
      double latitude = locations.get(0).getLatitude();
      double longitude = locations.get(0).getLongitude();

      // tags name
      ArrayList<String> listTagsName = new ArrayList<>();
      for (Long tagID : interest.getTagIds()) {
        for (Tag tag : tags) {
          if (tag.getId().equals(tagID)) {
            listTagsName.add(tag.getName());
          }
        }
      }

      if (!listTagsName.isEmpty()) {
        markerText += Joiner.on(", ").join(listTagsName);
      }

      // submitter
      UserAccount submitter = interest.getSubmitter();
      if (submitter != null) {
        markerText += "\n" + submitter.getUsername();
      }

      mMap.addMarker(
          new MarkerOptions().position(new LatLng(latitude, longitude)).title(markerText));

    } else {

      PolygonOptions options = new PolygonOptions();
      for (GeoPt geoPt : locations) {

        double latitude = geoPt.getLatitude();
        double longitude = geoPt.getLongitude();

        options.add(new LatLng(latitude, longitude));
      }
      int color = Color.parseColor(getColorOfInterest(interest, tags));
      options.fillColor(color);
      options.strokeColor(color);

      mMap.addPolygon(options);
    }
  }
Пример #2
0
  private String getColorOfInterest(Interest interest, List<Tag> tags) {

    List<Long> tagIds = interest.getTagIds();
    if (tagIds != null && !tagIds.isEmpty()) {
      final Long firstTagId = tagIds.get(0);

      Tag myTag =
          Iterables.tryFind(
                  tags,
                  new Predicate<Tag>() {
                    @Override
                    public boolean apply(Tag input) {
                      return input.getId().equals(firstTagId);
                    }
                  })
              .orNull();

      if (myTag != null) {
        return myTag.getColor();
      }
    }
    return "#000000"; // Couleur par défaut si on a rien trouvé. Là c'est du noir
  }