private List<KmlPosition> extractPositionsFromGeometry( JAXBElement<? extends AbstractGeometryType> geometryType) { List<KmlPosition> positions = new ArrayList<>(); AbstractGeometryType geometryTypeValue = geometryType.getValue(); if (geometryTypeValue instanceof PointType) { PointType point = (PointType) geometryTypeValue; positions.addAll(asKmlPositions(point.getCoordinates())); } if (geometryTypeValue instanceof LineStringType) { LineStringType lineString = (LineStringType) geometryTypeValue; positions.addAll(asKmlPositions(lineString.getCoordinates())); } if (geometryTypeValue instanceof MultiGeometryType) { MultiGeometryType multiGeometryType = (MultiGeometryType) geometryTypeValue; List<JAXBElement<? extends AbstractGeometryType>> geometryTypes = multiGeometryType.getAbstractGeometryGroup(); for (JAXBElement<? extends AbstractGeometryType> geometryType2 : geometryTypes) { positions.addAll(extractPositionsFromGeometry(geometryType2)); } } if (geometryTypeValue instanceof MultiTrackType) { MultiTrackType multiTrackType = (MultiTrackType) geometryTypeValue; List<TrackType> tracks = multiTrackType.getTrack(); for (TrackType track : tracks) { positions.addAll(extractPositions(track)); } } if (geometryTypeValue instanceof TrackType) { TrackType trackType = (TrackType) geometryTypeValue; positions.addAll(extractPositions(trackType)); } return positions; }
private PlacemarkType createRoute(KmlRoute route) { ObjectFactory objectFactory = new ObjectFactory(); PlacemarkType placemarkType = objectFactory.createPlacemarkType(); placemarkType.setName(ROUTE); placemarkType.setDescription(asDescription(route.getDescription())); placemarkType.setStyleUrl("#" + ROUTE_LINE_STYLE); MultiGeometryType multiGeometryType = objectFactory.createMultiGeometryType(); placemarkType.setAbstractGeometryGroup(objectFactory.createMultiGeometry(multiGeometryType)); LineStringType lineStringType = objectFactory.createLineStringType(); multiGeometryType .getAbstractGeometryGroup() .add(objectFactory.createLineString(lineStringType)); List<String> coordinates = lineStringType.getCoordinates(); for (KmlPosition position : route.getPositions()) { coordinates.add(createCoordinates(position, false)); } return placemarkType; }