Permalink
Browse files

change to add the geometry for each instruction step

  • Loading branch information...
1 parent 3a993bc commit 3d33e947e4287324fe9be210bb6bcc26e5fe2182 @moiarcsan moiarcsan committed Jul 31, 2012
Showing with 43 additions and 8 deletions.
  1. +7 −3 osrm-connector/pom.xml
  2. +36 −5 osrm-connector/src/main/java/org/emergya/osrm/OSRM.java
View
10 osrm-connector/pom.xml
@@ -4,7 +4,7 @@
<groupId>org.emergya</groupId>
<artifactId>osrm-connector</artifactId>
<version>0.1.0</version>
- <name>osrm-connector</name>
+ <name>osrm-connectordfssd</name>
<description>Connector to OSRM routing</description>
@@ -18,8 +18,12 @@
<url>http://nexus.emergya.es/nexus/content/repositories/gofleet-snapshots</url>
</snapshotRepository>
</distributionManagement>
-
-
+ <repositories>
+ <repository>
+ <id>public</id>
+ <url>http://nexus.emergya.es/nexus/content/repositories/GoFleet</url>
+ </repository>
+ </repositories>
<build>
<plugins>
<plugin>
View
41 osrm-connector/src/main/java/org/emergya/osrm/OSRM.java
@@ -33,6 +33,7 @@
import java.math.BigDecimal;
import java.net.UnknownHostException;
import java.text.ParseException;
+import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
@@ -94,6 +95,11 @@
protected static final String EPSG_4326 = "EPSG:4326";
private static Log LOG = LogFactory.getLog(OSRM.class);
private GeometryFactory gf = new GeometryFactory();
+ /*
+ * Atribute to save tha last coordinate form a point in the line string
+ * request
+ */
+ private Integer lastNode = null;
private DatatypeFactory dataTypeFactory = new com.sun.org.apache.xerces.internal.jaxp.datatype.DatatypeFactoryImpl();
@Autowired
@@ -164,7 +170,7 @@ public AbstractResponseParametersType routePlan(
// instruction with a map.
try {
-
+ lastNode = null;
RouteGeometryType routeGeometry = new RouteGeometryType();
WayPointListType wayPointList = param.getRoutePlan()
.getWayPointList();
@@ -216,7 +222,7 @@ else if (jp.getCurrentName().equals("total_distance")) {
targetCRS, sourceCRS, jp);
} else if (jp.getCurrentName().equals("route_instructions")) {
processInstructions(locale, routeSummary,
- routeInstructionsList, jp);
+ routeInstructionsList, jp, lst);
}
jp.nextToken();
}
@@ -261,8 +267,8 @@ private BufferedReader getOSRMStream(String host_port, String url)
*/
public void processInstructions(Locale locale,
RouteSummaryType routeSummary,
- RouteInstructionsListType routeInstructionsList, JsonParser jp)
- throws IOException, JsonParseException {
+ RouteInstructionsListType routeInstructionsList, JsonParser jp,
+ LineStringType lineString) throws IOException, JsonParseException {
while (jp.nextToken() == JsonToken.START_ARRAY
&& jp.getCurrentToken() != null) {
RouteInstructionType e = new RouteInstructionType();
@@ -285,15 +291,40 @@ public void processInstructions(Locale locale,
distance.setUom(DistanceUnitType.M);
distance.setValue(new BigDecimal(jp.getText()));
e.setDistance(distance);
+
+ // Get position
+ jp.nextToken();
+ Integer currentNode = null;
+ if (routeInstructionsList.getRouteInstruction().size() > 0) {
+ List<RouteInstructionType> lri = routeInstructionsList
+ .getRouteInstruction();
+ currentNode = jp.getIntValue();
+ List<JAXBElement<?>> pointList = lineString.getPosOrPointPropertyOrPointRep();
+ LineStringType lineToRoute = new LineStringType();
+ if(currentNode > lastNode){
+ List<JAXBElement<?>> pointListToRoute = new LinkedList<JAXBElement<?>>();
+ RouteGeometryType rgt = new RouteGeometryType();
+ for(int i=lastNode; i<=currentNode; i++){
+ pointListToRoute.add(pointList.get(i));
+ }
+ lineToRoute.setPosOrPointPropertyOrPointRep(pointListToRoute);
+ rgt.setLineString(lineToRoute);
+ lri.get(lri.size()-1).setRouteInstructionGeometry(rgt);
+ }
+ }
+ lastNode = jp.getIntValue();
jp.nextToken();
Duration duration = dataTypeFactory.newDuration(true, 0, 0, 0, 0,
0, jp.getIntValue());
e.setDuration(duration);
+
+
while (jp.nextToken() != JsonToken.END_ARRAY
- && jp.getCurrentToken() != null);
+ && jp.getCurrentToken() != null)
+ ;
routeInstructionsList.getRouteInstruction().add(e);
}
}

0 comments on commit 3d33e94

Please sign in to comment.