Exemplo n.º 1
0
  public static void writeRecordsToKML(
      String contextPath,
      String placemarkColorHex,
      List<Record> recordList,
      OutputStream outputStream)
      throws JAXBException {
    JsonService jsonService = AppContext.getBean(JsonService.class);

    KMLWriter writer = new KMLWriter();
    String placemark = contextPath + GET_RECORD_PLACEMARK_PNG_URL + "?color=";

    placemarkColorHex = placemarkColorHex == null ? "EE9900" : placemarkColorHex;
    placemark = placemark + placemarkColorHex;

    writer.createStyleIcon(KML_POINT_ICON_ID, placemark, 16, 16);
    writer.createFolder(KML_RECORD_FOLDER);
    String label;
    String description;

    for (Record record : recordList) {

      label = String.format("Record #%d", record.getId());
      description = jsonService.toJson(record).toString();

      if (record.getPoint() != null) {
        writer.createPlacemark(
            KML_RECORD_FOLDER, label, description, record.getPoint(), KML_POINT_ICON_ID);
      } else if (record.getLocation() != null && record.getLocation().getLocation() != null) {
        writer.createPlacemark(
            KML_RECORD_FOLDER,
            label,
            description,
            record.getLocation().getLocation(),
            KML_POINT_ICON_ID);
      } else {
        log.info("Cannot find coordinate for record");
      }
    }

    writer.write(false, outputStream);
  }