コード例 #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 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;
  }
コード例 #4
0
  private List<GpxRoute> extractRoutes(
      GpxType gpxType, boolean hasSpeedInMeterPerSecondInsteadOfKilometerPerHour) {
    List<GpxRoute> result = new ArrayList<GpxRoute>();

    for (RteType rteType : gpxType.getRte()) {
      String name = rteType.getName();
      String desc = rteType.getDesc();
      List<String> descriptions = asDescription(desc);
      List<GpxPosition> positions =
          extractRoute(rteType, hasSpeedInMeterPerSecondInsteadOfKilometerPerHour);
      result.add(new GpxRoute(this, Route, name, descriptions, positions, gpxType, rteType));

      // Garmin Extensions v3
      if (rteType.getExtensions() != null && rteType.getExtensions().getAny().size() > 0) {
        List<GpxPosition> extendedPositions =
            extractRouteWithGarminExtensions(
                rteType, hasSpeedInMeterPerSecondInsteadOfKilometerPerHour);
        result.add(
            new GpxRoute(this, Track, name, descriptions, extendedPositions, gpxType, rteType));
      }
    }

    return result;
  }