/
JSONStep.java
122 lines (103 loc) 路 4.81 KB
/
JSONStep.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* This file is part of Openrouteservice.
*
* Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this library;
* if not, see <https://www.gnu.org/licenses/>.
*/
package org.heigit.ors.api.responses.routing.json;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.extensions.Extension;
import io.swagger.v3.oas.annotations.extensions.ExtensionProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import org.heigit.ors.routing.RouteStep;
import org.heigit.ors.util.StringUtility;
import java.util.Arrays;
@Schema(name = "JSONStep", description = "Step of a route segment")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class JSONStep {
@Schema(description = "The distance for the step in metres.", example = "245")
@JsonProperty("distance")
private final Double distance;
@Schema(description = "The duration for the step in seconds.", example = "96.2")
@JsonProperty("duration")
@JsonFormat(shape = JsonFormat.Shape.NUMBER_FLOAT, pattern = "%.1d")
private final Double duration;
@Schema(description = "The [instruction](https://giscience.github.io/openrouteservice/api-reference/endpoints/directions/instruction-types) action for symbolisation purposes.", example = "1")
@JsonProperty("type")
private final Integer type;
@Schema(description = "The routing instruction text for the step.", example = "Turn right onto Berliner Stra脽e")
@JsonProperty("instruction")
private final String instruction;
@Schema(description = "The name of the next street.", example = "Berliner Stra脽e")
@JsonProperty("name")
private String name;
@Schema(description = "Only for roundabouts. Contains the number of the exit to take.", example = "2")
@JsonProperty("exit_number")
private Integer exitNumber;
@Schema(description = "Contains the bearing of the entrance and all passed exits in a roundabout.",
extensions = {@Extension(name = "validWhen", properties = {
@ExtensionProperty(name = "ref", value = "roundabout_exits"),
@ExtensionProperty(name = "value", value = "true", parseValue = true)}
)}, example = "[10,45,60]")
@JsonProperty("exit_bearings")
private int[] exitBearings;
@Schema(description = "List containing the indices of the steps start- and endpoint corresponding to the *geometry*.", example = "[45,48]")
@JsonProperty("way_points")
private int[] waypoints;
@Schema(description = "The maneuver to be performed.",
extensions = {@Extension(name = "validWhen", properties = {
@ExtensionProperty(name = "ref", value = "maneuvers"),
@ExtensionProperty(name = "value", value = "true", parseValue = true)}
)})
@JsonProperty("maneuver")
private JSONStepManeuver maneuver;
public JSONStep(RouteStep step) {
this.distance = step.getDistance();
this.duration = step.getDuration();
this.type = step.getType();
this.instruction = step.getInstruction();
this.name = StringUtility.isEmpty(step.getName()) ? "-" : step.getName();
if (step.getExitNumber() != -1)
this.exitNumber = step.getExitNumber();
if (step.getWayPoints().length > 0)
this.waypoints = Arrays.copyOf(step.getWayPoints(), step.getWayPoints().length);
if (step.getManeuver() != null)
this.maneuver = new JSONStepManeuver(step.getManeuver());
if (step.getRoundaboutExitBearings() != null && step.getRoundaboutExitBearings().length > 0)
this.exitBearings = Arrays.copyOf(step.getRoundaboutExitBearings(), step.getRoundaboutExitBearings().length);
}
public Double getDistance() {
return distance;
}
public Double getDuration() {
return duration;
}
public Integer getType() {
return type;
}
public String getInstruction() {
return instruction;
}
public String getName() {
return name;
}
public Integer getExitNumber() {
return exitNumber;
}
public int[] getWaypoints() {
return waypoints;
}
public JSONStepManeuver getManeuver() {
return maneuver;
}
}