Skip to content

Commit 7df68e4

Browse files
Brian OlsenBrian Olsen
authored andcommitted
Update pom and readme. Make simle compile test.
1 parent 64451ad commit 7df68e4

File tree

3 files changed

+99
-5
lines changed

3 files changed

+99
-5
lines changed

ReadMe.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
1-
# OSRM Text Instructions (Java)
2-
This library was my "take" on converting the useful [OSRM Text Instructions](https://github.com/Project-OSRM/osrm-text-instructions) library that is programmed in javascript into a java project. While a [java version has already been created](https://github.com/Project-OSRM/osrm-text-instructions.java/), it doesn't seem to be maintained currently to keep it up to date with the main project. I had the need and idea to port the node module by running a V8 instance on the JVM using the wonderful [J2V8 library](https://github.com/eclipsesource/J2V8) and allowing direct calls to the main javascript library from Java. This will make keeping up the development simple as new functionality arises.
1+
# OSRM Text Instructions - Java J2V8 Wrapper
2+
This library wraps javascript functions from the [OSRM Text Instructions](https://github.com/Project-OSRM/osrm-text-instructions) library that is programmed in javascript as a java project. The osrm-text-instructions library is uses the [MapBox LegStep](https://www.mapbox.com/android-docs/api/mapbox-java/libjava-services/2.2.9/com/mapbox/services/api/directions/v5/models/LegStep.html) model and compiles human readable instructions on how to follow the next direction on a route. I had the need and idea to port the node module by running a V8 instance on the JVM using the wonderful [J2V8 library](https://github.com/eclipsesource/J2V8) and allowing direct calls to the main javascript library from Java. This will make keeping up the development simple as new functionality arises.
33

4-
I did copy some testing code and idea to use the [MapBox LegStep](https://www.mapbox.com/android-docs/api/mapbox-java/libjava-services/2.2.9/com/mapbox/services/api/directions/v5/models/LegStep.html) model to supplement the [OSRM RouteStep object](https://github.com/Project-OSRM/osrm-backend/blob/master/docs/http.md#routestep-object) required in the compile steps.
4+
##Some example uses
5+
```
6+
try (OSRMTextInstructions textInstructions = new OSRMTextInstructions(VERSION)) {
7+
String wayName = "Route 66";
8+
StepManeuver maneuver = new StepManeuver("turn", "left", 1);
9+
LegStep step = new LegStep();
10+
11+
step.setManeuver(maneuver);
12+
step.setName(wayName);
13+
14+
assertEquals("Turn left onto Route 66", textInstructions.compile("en", step, null));
15+
assertEquals("Gire a la izquierda en Route 66", textInstructions.compile("es", step, null));
16+
assertEquals("Svolta a sinistra in Route 66", textInstructions.compile("it", step, null));
17+
assertEquals("Ga linksaf naar Route 66", textInstructions.compile("nl", step, null));
18+
assertEquals("左转,上Route 66", textInstructions.compile("zh-Hans", step, null));
19+
}
20+
```
21+
## Available on the central maven repository
22+
This library is available on [The Central Repository](http://repo1.maven.apache.org/maven2/com/github/brianolsen87/text-instructions/0.11.0/). My versioning will match the OSRM Text Instruction projects and will have the maven dependency tags for the pom included on [the release page](https://github.com/brianolsen87/text-instructions/releases). I will stay posted when a version has updated and keep up with original library as quickly as I can.
523

6-
I have pre-installed the node modules in the resource folders to avoid the user needing to install node.js or npm themselves just to install the osrm-text-instructions module. If, however, you want the latest version you will need install both of these reqirements yourself and run `node install osrm-text-instructions` in the resource folder. You will also need to pay special attention to the version number specified in the javascript library and make sure it matches whatever version you wish to use.
24+
## Rolling your own version
25+
I have pre-installed the node modules in the resource folders to avoid the user needing to install node.js or npm. If, however, you want the latest version you will need to go to [osrm-text-instruction release page](https://github.com/Project-OSRM/osrm-text-instructions/releases) and download the version you like. At this point you must verify that any new or changed methods in install.js are wrapped correctly in [OSRMTextInstructions.java](https://github.com/brianolsen87/text-instructions/blob/master/src/main/java/us/brianolsen/instructions/OSRMTextInstructions.java).
726

27+
## FYI
28+
The [MapBox LegStep](https://www.mapbox.com/android-docs/api/mapbox-java/libjava-services/2.2.9/com/mapbox/services/api/directions/v5/models/LegStep.html) model supplements the [OSRM RouteStep object](https://github.com/Project-OSRM/osrm-backend/blob/master/docs/http.md#routestep-object) required in the compile steps. While a [java version has already been created](https://github.com/Project-OSRM/osrm-text-instructions.java/), it doesn't seem to be maintained currently to keep it up to date with the main project but I have drawn on some of its setup for my own project.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.github.brianolsen87</groupId>
66
<artifactId>text-instructions</artifactId>
7-
<version>0.11.0-SNAPSHOT</version>
7+
<version>0.11.0</version>
88
<packaging>jar</packaging>
99

1010
<name>OSRM Text Instructions - Java J2V8 Wrapper</name>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package us.brianolsen.instructions;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import java.nio.file.Paths;
6+
7+
import org.junit.Test;
8+
9+
import com.mapbox.services.api.directions.v5.models.LegStep;
10+
import com.mapbox.services.api.directions.v5.models.StepManeuver;
11+
12+
import us.brianolsen.instructions.util.ResourceUtil;
13+
14+
public class OSRMTextInstructionsSimpleCompileTest extends BaseTest {
15+
protected static final String FIXTURES_DIRECTORY = Paths.get( //
16+
ResourceUtil.getNodeModuleDirectory(MODULE_NAME, MODULE_VERSION).getAbsolutePath(), //
17+
"test", "fixtures", VERSION).toString();
18+
19+
@Test
20+
public void testSimpleCompileCommands() {
21+
try (OSRMTextInstructions textInstructions = new OSRMTextInstructions(VERSION)) {
22+
String wayName = "Route 66";
23+
StepManeuver maneuver = new StepManeuver("turn", "left", 1);
24+
25+
LegStep step = new LegStep();
26+
step.setManeuver(maneuver);
27+
step.setName(wayName);
28+
29+
assertEquals("Turn left onto Route 66", textInstructions.compile("en", step, null));
30+
assertEquals("Gire a la izquierda en Route 66", textInstructions.compile("es", step, null));
31+
assertEquals("Svolta a sinistra in Route 66", textInstructions.compile("it", step, null));
32+
assertEquals("Ga linksaf naar Route 66", textInstructions.compile("nl", step, null));
33+
assertEquals("左转,上Route 66", textInstructions.compile("zh-Hans", step, null));
34+
35+
maneuver = new StepManeuver();
36+
maneuver.setBearingAfter(340);
37+
maneuver.setType("depart");
38+
step.setManeuver(maneuver);
39+
40+
assertEquals("Head north on Route 66", textInstructions.compile("en", step, null));
41+
assertEquals("Ve a norte en Route 66", textInstructions.compile("es", step, null));
42+
assertEquals("Continua verso nord in Route 66", textInstructions.compile("it", step, null));
43+
assertEquals("Neem Route 66 in noordelijke richting", textInstructions.compile("nl", step, null));
44+
assertEquals("出发向北,上Route 66", textInstructions.compile("zh-Hans", step, null));
45+
46+
maneuver = new StepManeuver();
47+
maneuver.setBearingAfter(152);
48+
maneuver.setType("depart");
49+
step.setManeuver(maneuver);
50+
51+
assertEquals("Head southeast on Route 66", textInstructions.compile("en", step, null));
52+
assertEquals("Ve a sureste en Route 66", textInstructions.compile("es", step, null));
53+
assertEquals("Continua verso sud-est in Route 66", textInstructions.compile("it", step, null));
54+
assertEquals("Neem Route 66 in zuidoostelijke richting", textInstructions.compile("nl", step, null));
55+
assertEquals("出发向东南,上Route 66", textInstructions.compile("zh-Hans", step, null));
56+
57+
maneuver = new StepManeuver();
58+
maneuver.setType("fork");
59+
maneuver.setModifier("sharp right");
60+
step.setManeuver(maneuver);
61+
62+
assertEquals("Take a sharp right at the fork onto Route 66", textInstructions.compile("en", step, null));
63+
assertEquals("Gire a la derecha en el cruce en Route 66", textInstructions.compile("es", step, null));
64+
assertEquals("Svolta a destra al bivio in Route 66", textInstructions.compile("it", step, null));
65+
assertEquals("Rechtsaf op de splitsing naar Route 66", textInstructions.compile("nl", step, null));
66+
assertEquals("在岔道保持向右,上Route 66", textInstructions.compile("zh-Hans", step, null));
67+
68+
} catch (RuntimeException e) {
69+
System.err.println(e);
70+
}
71+
}
72+
73+
}

0 commit comments

Comments
 (0)