mapbox-navigation-ios icon indicating copy to clipboard operation
mapbox-navigation-ios copied to clipboard

Route progress should track shape index

Open 1ec5 opened this issue 6 years ago • 1 comments

RouteStep and possibly RouteLeg and Route should have a shapeIndex property that tracks the index of the closest coordinate to the current location in the current step’s shape. This change would keep client code from having to call LineString.closestCoordinate(to:) for the same information.

This property can be updated automatically whenever RouteStepProgress.distanceTraveled changes. There is a cost to performing this calculation, but it turns out that plenty of code is already redundantly performing the same calculation on every location update.

MBNavigationStatus.shapeIndex apparently already tracks the same information, and it would be nice to just use that value instead of recalculating the closest coordinate, potentially inconsistently. However, RouteStep’s public API allows client code to manually set distanceTraveled (as well as intersectionIndex for that matter), so I’m leery of allowing clients to accidentally set just distanceTraveled without also updating shapeIndex and intersectionIndex.

/cc @mapbox/navigation-ios

1ec5 avatar Jan 06 '20 19:01 1ec5

MBNavigationStatus.shapeIndex is an index into the overall route’s coordinate array, which isn’t guaranteed to match the sum of per-step coordinate arrays. (For example, the route shape resolution may be less than full.) Route.shapeIndex could separately track MBNavigationStatus.shapeIndex, which would be handy for some applications that are already extending RouteProgress with a remainingCoordinates property.

1ec5 avatar Jan 06 '20 19:01 1ec5