Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add waypoint arrival instruction #111

Merged
merged 13 commits into from
Jun 19, 2017
Merged

Add waypoint arrival instruction #111

merged 13 commits into from
Jun 19, 2017

Conversation

bsudekum
Copy link

@bsudekum bsudekum commented Jun 9, 2017

This adds instructions for arriving at waypoints and also fixes an issue with updating fixtures.

Necessary for mapbox/mapbox-navigation-ios#270

/cc @freenerd @patjouk @1ec5

@bsudekum bsudekum requested a review from freenerd June 9, 2017 21:52
@bsudekum
Copy link
Author

bsudekum commented Jun 9, 2017

Note, I had to add a metadata field to the fixture files to configure each compile test to allow for unique legIndex values in d0f94ad

index.js Outdated
@@ -68,7 +68,7 @@ module.exports = function(version, _options) {

return config.join('');
},
compile: function(language, step) {
compile: function(language, step, legIndex) {
Copy link
Author

@bsudekum bsudekum Jun 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New optional third argument, legIndex.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you indicate “final”? −1? (We would also need to add a string for “final” to the translations.)

index.js Outdated
@@ -173,7 +172,7 @@ module.exports = function(version, _options) {
.replace('{lane_instruction}', laneInstruction)
.replace('{modifier}', instructions[language][version].constants.modifier[modifier])
.replace('{direction}', this.directionFromDegree(language, step.maneuver.bearing_after))
.replace('{nth}', nthWaypoint)
.replace('{nth}', legIndex && legIndex > 0 ? this.ordinalize(language, legIndex) : '')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to this logic, if there are multiple destinations, the first destination is announced as, “You have arrived at your destination.”

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it may be necessary to accept yet another parameter, the leg count. (That way we also don’t need to represent the last step index as −1.)

index.js Outdated
@@ -173,7 +175,7 @@ module.exports = function(version, _options) {
.replace('{lane_instruction}', laneInstruction)
.replace('{modifier}', instructions[language][version].constants.modifier[modifier])
.replace('{direction}', this.directionFromDegree(language, step.maneuver.bearing_after))
.replace('{nth}', nthWaypoint)
.replace('{nth}', waypoint)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nthWaypoint was a more descriptive name. We aren't dealing with the waypoint itself; we're dealing with an ordinal word representing the one-based leg "index".

index.js Outdated
@@ -162,9 +163,10 @@ module.exports = function(version, _options) {
instruction = options.hooks.tokenizedInstruction(instruction);
}

var waypoint = legIndex >= 0 && legIndex !== legCount - 1 ? this.ordinalize(language, legIndex + 1) : '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's the last of several waypoints, should we say "final destination"? The current code says only "destination".

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but we currently do not have a translation for this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This repository must have a source string before translators can provide translations in Transifex. Therefore, assuming that it’s a good idea to say “final destination”, this PR needs to add the “final destination” string to en.json. To avoid breaking the tests, I suppose we’d wait to make use of that string until enough translations are in.

Copy link
Member

@freenerd freenerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Therefore, assuming that it’s a good idea to say “final destination”, this PR needs to add the “final destination” string to en.json.

We used to have final destination and it sounded grim. Would last destination also work? Also we should make sure to not emit that if it's a one-leg route only.

index.js Outdated
@@ -68,10 +68,11 @@ module.exports = function(version, _options) {

return config.join('');
},
compile: function(language, step) {
compile: function(language, step, legIndex, legCount) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this optional? For most cases (read: non-multi waypoint cases) we will not need these properties. I'd be good to put them into an options object.

compile: function(language, step, options) {

fs.writeFileSync(
fileName,
JSON.stringify({
step: step,
instructions: instructionsForLanguages(step)
instructions: instructionsForLanguages(step, legIndex, legCount),
metadata: metadata
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we even need to add metadata if it's just an empty object most of the time?

"name": "Street Name"
},
"instructions": {
"de": "Sie haben Ihr erste Ziel erreicht, es befindet sich links von Ihnen",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need gendering of the adjective here 😢 Maybe we can get around this with some smart same-gender naming, I'll have a look ...

Now: Sie haben Ihr erste Ziel erreicht.
Correct: Sie haben Ihr erstes Ziel erreicht.

@bsudekum
Copy link
Author

@freenerd I think having final makes sense now that we have in between waypoints. Thoughts @1ec5?

Bobby Sudekum added 2 commits June 12, 2017 11:50
@1ec5
Copy link
Member

1ec5 commented Jun 12, 2017

Haha, good point about “final destination”. 🙀 In an ideal world, we’d have a name for each waypoint that we’d say instead of “your destination”, but I suppose “your last destination” is passable.

(The railfan in me would have it say “last scheduled station stop”. 😏)

@freenerd
Copy link
Member

Readme and Changelog still need fixups.

@bsudekum
Copy link
Author

@freenerd will update the changelog when I update the package's version.

@bsudekum
Copy link
Author

@freenerd @1ec5 want to give this another review?

index.js Outdated
@@ -68,7 +68,7 @@ module.exports = function(version, _options) {

return config.join('');
},
compile: function(language, step) {
compile: function(language, step, legOptions) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we keep this with options only? That would be consistent with the options we already have for the module initialization.

"vi": "Đến nơi ",
"zh-Hans": "您已经到达您的个目的地"
},
"metadata": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should become options then as well

@bsudekum
Copy link
Author

@freenerd note, while changing legOptions -> options, I had to change another options variable to opts. Can be seen in cf67806

@bsudekum bsudekum merged commit 2ad8d70 into master Jun 19, 2017
@bsudekum bsudekum deleted the waypoint-arrive branch June 19, 2017 13:09
@1ec5
Copy link
Member

1ec5 commented Jul 6, 2017

Necessary for mapbox/mapbox-navigation-ios#270

The iOS navigation SDK uses the Swift port of this library for logic such as what’s in this PR. Tracking a Swift port in Project-OSRM/osrm-text-instructions.swift#24.

@1ec5 1ec5 mentioned this pull request Jul 27, 2017
@hdaymon hdaymon mentioned this pull request Sep 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants