示例#1
0
  private GpxType createGpxType(List<GpxRoute> routes) {
    ObjectFactory objectFactory = new ObjectFactory();

    GpxType gpxType = null;
    for (GpxRoute route : routes) {
      gpxType = recycleGpxType(route);
      if (gpxType != null) break;
    }
    if (gpxType == null) gpxType = objectFactory.createGpxType();
    gpxType.setCreator(GENERATED_BY);
    gpxType.setVersion(VERSION);

    for (GpxRoute route : routes) {
      switch (route.getCharacteristics()) {
        case Waypoints:
          gpxType.setMetadata(createMetaData(route, gpxType));
          gpxType.getWpt().addAll(createWayPoints(route, 0, route.getPositionCount()));
          break;
        case Route:
          gpxType.getRte().addAll(createRoute(route, 0, route.getPositionCount()));
          break;
        case Track:
          gpxType.getTrk().addAll(createTrack(route, 0, route.getPositionCount()));
          break;
        default:
          throw new IllegalArgumentException(
              "Unknown RouteCharacteristics " + route.getCharacteristics());
      }
    }
    return gpxType;
  }
示例#2
0
 private GpxType recycleGpxType(GpxRoute route) {
   GpxType gpxType = route.getOrigin(GpxType.class);
   if (gpxType != null) {
     gpxType.getRte().clear();
     gpxType.getTrk().clear();
     gpxType.getWpt().clear();
   }
   return gpxType;
 }
示例#3
0
  private List<GpxRoute> extractTracks(
      GpxType gpxType, boolean hasSpeedInMeterPerSecondInsteadOfKilometerPerHour) {
    List<GpxRoute> result = new ArrayList<GpxRoute>();

    for (TrkType trkType : gpxType.getTrk()) {
      String name = trkType.getName();
      String desc = trkType.getDesc();
      List<String> descriptions = asDescription(desc);
      List<GpxPosition> positions =
          extractTrack(trkType, hasSpeedInMeterPerSecondInsteadOfKilometerPerHour);
      result.add(new GpxRoute(this, Track, name, descriptions, positions, gpxType, trkType));
    }

    return result;
  }
示例#4
0
  private GpxType createGpxType(GpxRoute route, int startIndex, int endIndex) {
    ObjectFactory objectFactory = new ObjectFactory();

    GpxType gpxType = recycleGpxType(route);
    if (gpxType == null) gpxType = objectFactory.createGpxType();
    gpxType.setCreator(GENERATED_BY);
    gpxType.setVersion(VERSION);

    if (route.getCharacteristics().equals(Waypoints))
      gpxType.setMetadata(createMetaData(route, gpxType));

    gpxType.getWpt().addAll(createWayPoints(route, startIndex, endIndex));
    gpxType.getRte().addAll(createRoute(route, startIndex, endIndex));
    gpxType.getTrk().addAll(createTrack(route, startIndex, endIndex));
    return gpxType;
  }