private static Response.ResponseBuilder gpxSuccessResponseBuilder(GHResponse ghRsp, String timeString, String trackName, boolean enableElevation, boolean withRoute, boolean withTrack, boolean withWayPoints, String version) { if (ghRsp.getAll().size() > 1) { throw new IllegalArgumentException("Alternatives are currently not yet supported for GPX"); } long time = timeString != null ? Long.parseLong(timeString) : System.currentTimeMillis(); return Response.ok(ghRsp.getBest().getInstructions().createGPX(trackName, time, enableElevation, withRoute, withTrack, withWayPoints, version), "application/gpx+xml"). header("Content-Disposition", "attachment;filename=" + "GraphHopper.gpx"); }
private void parseSolutionsAndAddToResponse(List<List<Label.Transition>> solutions, PointList waypoints) { for (List<Label.Transition> solution : solutions) { final List<Trip.Leg> legs = tripFromLabel.getTrip(translation, graphExplorer, accessEgressWeighting, solution); final PathWrapper pathWrapper = tripFromLabel.createPathWrapper(translation, waypoints, legs); pathWrapper.setImpossible(solution.stream().anyMatch(t -> t.label.impossible)); pathWrapper.setTime((solution.get(solution.size()-1).label.currentTime - solution.get(0).label.currentTime)); response.add(pathWrapper); } Comparator<PathWrapper> c = Comparator.comparingInt(p -> (p.isImpossible() ? 1 : 0)); Comparator<PathWrapper> d = Comparator.comparingDouble(PathWrapper::getTime); response.getAll().sort(c.thenComparing(d)); }
throw new MultiException(ghResponse.getErrors()); } else { logger.info(logStr + ", alternatives: " + ghResponse.getAll().size() + ", distance0: " + ghResponse.getBest().getDistance() + ", weight0: " + ghResponse.getBest().getRouteWeight()
info.put("took", Math.round(took * 1000)); ArrayNode jsonPathList = json.putArray("paths"); for (PathWrapper ar : ghRsp.getAll()) { ObjectNode jsonPath = jsonPathList.addObject(); jsonPath.put("distance", Helper.round(ar.getDistance(), 3));
info.put("took", Math.round(took * 1000)); ArrayNode jsonPathList = json.putArray("paths"); for (PathWrapper ar : ghRsp.getAll()) { ObjectNode jsonPath = jsonPathList.addObject(); jsonPath.put("distance", Helper.round(ar.getDistance(), 3));