Skip to content

Commit

Permalink
Merge pull request #23 from Project-OSRM/destinations
Browse files Browse the repository at this point in the history
Support destinations
  • Loading branch information
freenerd authored Sep 21, 2016
2 parents f7629b7 + 69e2da4 commit ab5c339
Show file tree
Hide file tree
Showing 69 changed files with 596 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
}
],
"comma-style": "error",
"complexity": "error",
"complexity": "off",
"computed-property-spacing": [
"error",
"never"
Expand Down
13 changes: 11 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,22 @@ module.exports = function(_version) {
break;
}

// Handle instructions with names
if (step.name && step.name !== '') {
// Handle instructions with destinations and names
if (step.destinations && step.destinations !== '') {
// only use the first destination for text instruction
var d = step.destinations.split(',')[0];
var t = instructions[version].templates.destination;

instruction = instruction
.replace(/\[.+\]/, t.replace('{destination}', d));
} else if (step.name && step.name !== '') {
// if no destination found, try name
instruction = instruction
.replace('[', '')
.replace(']', '')
.replace('{way_name}', step.name);
} else {
// do not use name information if not included in step
instruction = instruction.replace(/\[.+\]/, '');
}

Expand Down
30 changes: 17 additions & 13 deletions instructions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"v5": {
"templates": {
"destination": " towards {destination}"
},
"arrive": {
"defaultInstruction": "You have arrived at your {nth} destination",
"left": "You have arrived at your {nth} destination, on the left",
Expand Down Expand Up @@ -53,21 +56,22 @@
"defaultInstruction": "Continue {modifier}[ onto {way_name}]"
},
"off ramp": {
"defaultInstruction": "Take the ramp",
"left": "Take the ramp on the left",
"right": "Take the ramp on the right",
"slight left": "Take the ramp on the left",
"slight right": "Take the ramp on the right"
"defaultInstruction": "Take the ramp[ onto {way_name}]",
"left": "Take the ramp on the left[ onto {way_name}]",
"right": "Take the ramp on the right[ onto {way_name}]",
"sharp left": "Take the ramp on the left[ onto {way_name}]",
"sharp right": "Take the ramp on the right[ onto {way_name}]",
"slight left": "Take the ramp on the left[ onto {way_name}]",
"slight right": "Take the ramp on the right[ onto {way_name}]"
},
"on ramp": {
"defaultInstruction": "Take the ramp on the {modifier}",
"left": "Take the ramp on the left",
"right": "Take the ramp on the right",
"sharp left": "Take the ramp on the left",
"sharp right": "Take the ramp on the right",
"slight left": "Take the ramp on the left",
"slight right": "Take the ramp on the right",
"straight": "Take the ramp"
"defaultInstruction": "Take the ramp[ onto {way_name}]",
"left": "Take the ramp on the left[ onto {way_name}]",
"right": "Take the ramp on the right[ onto {way_name}]",
"sharp left": "Take the ramp on the left[ onto {way_name}]",
"sharp right": "Take the ramp on the right[ onto {way_name}]",
"slight left": "Take the ramp on the left[ onto {way_name}]",
"slight right": "Take the ramp on the right[ onto {way_name}]"
},
"pushing bike": {
"defaultInstruction": "Get off the bike and push[ onto {way_name}]"
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/v5/continue/straight_destinations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"step": {
"maneuver": {
"modifier": "straight",
"type": "continue"
},
"name": "Street Name",
"destinations": "City 1,City 2"
},
"instruction": "Continue straight towards City 1"
}
2 changes: 1 addition & 1 deletion test/fixtures/v5/end_of_road/right.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
"name": "Street Name"
},
"instruction": "Turn right onto Street Name at the end of the road"
}
}
11 changes: 11 additions & 0 deletions test/fixtures/v5/end_of_road/right_destinations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"step": {
"maneuver": {
"modifier": "right",
"type": "end of road"
},
"name": "Street Name",
"destinations": "City 1,City 2"
},
"instruction": "Turn right towards City 1 at the end of the road"
}
11 changes: 11 additions & 0 deletions test/fixtures/v5/fork/right_destinations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"step": {
"maneuver": {
"modifier": "right",
"type": "fork"
},
"name": "Street Name",
"destinations": "City 1,City 2"
},
"instruction": "Keep right at the fork towards City 1"
}
11 changes: 11 additions & 0 deletions test/fixtures/v5/merge/right_destinations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"step": {
"maneuver": {
"modifier": "right",
"type": "merge"
},
"name": "Street Name",
"destinations": "City 1,City 2"
},
"instruction": "Merge right towards City 1"
}
11 changes: 11 additions & 0 deletions test/fixtures/v5/new_name/right_destinations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"step": {
"maneuver": {
"modifier": "right",
"type": "new name"
},
"name": "Street Name",
"destinations": "City 1,City 2"
},
"instruction": "Continue right towards City 1"
}
4 changes: 2 additions & 2 deletions test/fixtures/v5/off_ramp/left.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
},
"name": "Street Name"
},
"instruction": "Take the ramp on the left"
}
"instruction": "Take the ramp on the left onto Street Name"
}
11 changes: 11 additions & 0 deletions test/fixtures/v5/off_ramp/left_destinations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"step": {
"maneuver": {
"modifier": "left",
"type": "off ramp"
},
"name": "Street Name",
"destinations": "City 1,City 2"
},
"instruction": "Take the ramp on the left towards City 1"
}
10 changes: 10 additions & 0 deletions test/fixtures/v5/off_ramp/left_no_name.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"step": {
"maneuver": {
"modifier": "left",
"type": "off ramp"
},
"name": ""
},
"instruction": "Take the ramp on the left"
}
4 changes: 2 additions & 2 deletions test/fixtures/v5/off_ramp/right.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
},
"name": "Street Name"
},
"instruction": "Take the ramp on the right"
}
"instruction": "Take the ramp on the right onto Street Name"
}
11 changes: 11 additions & 0 deletions test/fixtures/v5/off_ramp/right_destinations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"step": {
"maneuver": {
"modifier": "right",
"type": "off ramp"
},
"name": "Street Name",
"destinations": "City 1,City 2"
},
"instruction": "Take the ramp on the right towards City 1"
}
10 changes: 10 additions & 0 deletions test/fixtures/v5/off_ramp/right_no_name.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"step": {
"maneuver": {
"modifier": "right",
"type": "off ramp"
},
"name": ""
},
"instruction": "Take the ramp on the right"
}
4 changes: 2 additions & 2 deletions test/fixtures/v5/off_ramp/sharp_left.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
},
"name": "Street Name"
},
"instruction": "Take the ramp"
}
"instruction": "Take the ramp on the left onto Street Name"
}
11 changes: 11 additions & 0 deletions test/fixtures/v5/off_ramp/sharp_left_destinations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"step": {
"maneuver": {
"modifier": "sharp left",
"type": "off ramp"
},
"name": "Street Name",
"destinations": "City 1,City 2"
},
"instruction": "Take the ramp on the left towards City 1"
}
10 changes: 10 additions & 0 deletions test/fixtures/v5/off_ramp/sharp_left_no_name.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"step": {
"maneuver": {
"modifier": "sharp left",
"type": "off ramp"
},
"name": ""
},
"instruction": "Take the ramp on the left"
}
4 changes: 2 additions & 2 deletions test/fixtures/v5/off_ramp/sharp_right.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
},
"name": "Street Name"
},
"instruction": "Take the ramp"
}
"instruction": "Take the ramp on the right onto Street Name"
}
11 changes: 11 additions & 0 deletions test/fixtures/v5/off_ramp/sharp_right_destinations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"step": {
"maneuver": {
"modifier": "sharp right",
"type": "off ramp"
},
"name": "Street Name",
"destinations": "City 1,City 2"
},
"instruction": "Take the ramp on the right towards City 1"
}
10 changes: 10 additions & 0 deletions test/fixtures/v5/off_ramp/sharp_right_no_name.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"step": {
"maneuver": {
"modifier": "sharp right",
"type": "off ramp"
},
"name": ""
},
"instruction": "Take the ramp on the right"
}
4 changes: 2 additions & 2 deletions test/fixtures/v5/off_ramp/slight_left.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
},
"name": "Street Name"
},
"instruction": "Take the ramp on the left"
}
"instruction": "Take the ramp on the left onto Street Name"
}
11 changes: 11 additions & 0 deletions test/fixtures/v5/off_ramp/slight_left_destinations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"step": {
"maneuver": {
"modifier": "slight left",
"type": "off ramp"
},
"name": "Street Name",
"destinations": "City 1,City 2"
},
"instruction": "Take the ramp on the left towards City 1"
}
10 changes: 10 additions & 0 deletions test/fixtures/v5/off_ramp/slight_left_no_name.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"step": {
"maneuver": {
"modifier": "slight left",
"type": "off ramp"
},
"name": ""
},
"instruction": "Take the ramp on the left"
}
4 changes: 2 additions & 2 deletions test/fixtures/v5/off_ramp/slight_right.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
},
"name": "Street Name"
},
"instruction": "Take the ramp on the right"
}
"instruction": "Take the ramp on the right onto Street Name"
}
11 changes: 11 additions & 0 deletions test/fixtures/v5/off_ramp/slight_right_destinations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"step": {
"maneuver": {
"modifier": "slight right",
"type": "off ramp"
},
"name": "Street Name",
"destinations": "City 1,City 2"
},
"instruction": "Take the ramp on the right towards City 1"
}
10 changes: 10 additions & 0 deletions test/fixtures/v5/off_ramp/slight_right_no_name.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"step": {
"maneuver": {
"modifier": "slight right",
"type": "off ramp"
},
"name": ""
},
"instruction": "Take the ramp on the right"
}
4 changes: 2 additions & 2 deletions test/fixtures/v5/off_ramp/straight.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
},
"name": "Street Name"
},
"instruction": "Take the ramp"
}
"instruction": "Take the ramp onto Street Name"
}
11 changes: 11 additions & 0 deletions test/fixtures/v5/off_ramp/straight_destinations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"step": {
"maneuver": {
"modifier": "straight",
"type": "off ramp"
},
"name": "Street Name",
"destinations": "City 1,City 2"
},
"instruction": "Take the ramp towards City 1"
}
11 changes: 11 additions & 0 deletions test/fixtures/v5/off_ramp/straight_no_name.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"step": {
"maneuver": {
"modifier": "straight",
"type": "off ramp"
},
"name": "Street Name",
"destinations": "City 1,City 2"
},
"instruction": "Take the ramp towards City 1"
}
4 changes: 2 additions & 2 deletions test/fixtures/v5/off_ramp/uturn.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
},
"name": "Street Name"
},
"instruction": "Take the ramp"
}
"instruction": "Take the ramp onto Street Name"
}
11 changes: 11 additions & 0 deletions test/fixtures/v5/off_ramp/uturn_destinations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"step": {
"maneuver": {
"modifier": "uturn",
"type": "off ramp"
},
"name": "Street Name",
"destinations": "City 1,City 2"
},
"instruction": "Take the ramp towards City 1"
}
Loading

0 comments on commit ab5c339

Please sign in to comment.