bcgov / ols-router

BC Advanced Route Planner
https://bcgov.github.io/ols-router/
Apache License 2.0
23 stars 11 forks source link

In a directions request, return a more structured directions object to make custom styling easier in routing applications #197

Closed qqnluaq closed 3 years ago

qqnluaq commented 4 years ago

The entries in the directions list in a typical result of a 'directions' request look like:

       {
            "type": "CONTINUE",
            "text": "Continue onto Swartz Bay Ferry Terminal for 75 m (27 seconds)",
            "point": [
                -123.41091,
                48.68861
            ]
        }

The text contains at least 4 separate pieces of information:

Only one of these is provided as a separate property (type). The other pieces of infomation are formatted in text and hence are made more difficult than it needs to be to format this information in an application-specific way.

Describe the solution you'd like

I want to see the other parts of the text broken out into their own properties:

       {
            "type": "CONTINUE",
            "destination": "Swartz Bay Ferry Terminal",
            "distance": 75 // always in meters
            "time": 27 // always in seconds
            "text": "Continue onto Swartz Bay Ferry Terminal for 75 m (27 seconds)",
            "point": [
                -123.41091,
                48.68861
            ]
        }
mraross commented 4 years ago

Great enhancement suggestion Ben, thanks. Just a couple of comments:

  1. Distance can be in metric (e.g. both km and m) or imperial(e.g., both miles and feet) as specified in the distanceUnit query parameter so I would add a distanceUnit property (e.g., km, m, mi, ft) to each direction object.

  2. Time can also be in hours, minutes or seconds so we might want a timeUnit as well.

cmhodgson commented 4 years ago

I think the intent is whatever code is making use of the time and distance values probably wants to format them (or process them) on it's own so really just one distance unit, meters or feet, based on the query params, and just seconds, always. The type parameter was added to support styling the directions with appropriate icons, right now the app only supports ferry and event icons. When I added it, I kinda expected this request to come along, eventually.

mraross commented 4 years ago

Agreed. As for icons, I can see an app developer using their own turn icons (e.g., left, right, straight).

cmhodgson commented 4 years ago

I have implemented this locally with the following changes:

mraross commented 4 years ago

Verified in dev