Beispiel #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;
  }
Beispiel #2
0
  private MetadataType createMetaData(GpxRoute route, GpxType gpxType) {
    ObjectFactory objectFactory = new ObjectFactory();

    MetadataType metadataType = gpxType.getMetadata();
    if (metadataType == null) metadataType = objectFactory.createMetadataType();

    if (isWriteName()) {
      metadataType.setName(asRouteName(route.getName()));
      metadataType.setDesc(asDescription(route.getDescription()));
    }
    return metadataType;
  }
Beispiel #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;
  }
Beispiel #4
0
 private List<RteType> createRoute(GpxRoute route, int startIndex, int endIndex) {
   ObjectFactory objectFactory = new ObjectFactory();
   List<RteType> rteTypes = new ArrayList<RteType>();
   RteType rteType = route.getOrigin(RteType.class);
   if (rteType != null) rteType.getRtept().clear();
   else rteType = objectFactory.createRteType();
   if (isWriteName()) {
     rteType.setName(asRouteName(route.getName()));
     rteType.setDesc(asDescription(route.getDescription()));
   }
   rteTypes.add(rteType);
   List<GpxPosition> positions = route.getPositions();
   for (int i = startIndex; i < endIndex; i++) {
     GpxPosition position = positions.get(i);
     WptType wptType = createWptType(position);
     if (wptType != null) rteType.getRtept().add(wptType);
   }
   return rteTypes;
 }
Beispiel #5
0
 private List<TrkType> createTrack(GpxRoute route, int startIndex, int endIndex) {
   ObjectFactory objectFactory = new ObjectFactory();
   List<TrkType> trkTypes = new ArrayList<TrkType>();
   TrkType trkType = route.getOrigin(TrkType.class);
   if (trkType != null) trkType.getTrkseg().clear();
   else trkType = objectFactory.createTrkType();
   if (isWriteName()) {
     trkType.setName(asRouteName(route.getName()));
     trkType.setDesc(asDescription(route.getDescription()));
   }
   trkTypes.add(trkType);
   TrksegType trksegType = objectFactory.createTrksegType();
   List<GpxPosition> positions = route.getPositions();
   for (int i = startIndex; i < endIndex; i++) {
     GpxPosition position = positions.get(i);
     WptType wptType = createWptType(position);
     if (wptType != null) trksegType.getTrkpt().add(wptType);
   }
   trkType.getTrkseg().add(trksegType);
   return trkTypes;
 }