-
Notifications
You must be signed in to change notification settings - Fork 319
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
Fix bug with MapRoute onClick #703
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although changes to fix the bug seem legit, I think now is a good opportunity to work on improving NavigationMapRoute
class which is getting large and apply The Boy Scout Rule.
@@ -601,50 +607,66 @@ public void removeRoute() { | |||
|
|||
@Override | |||
public void onMapClick(@NonNull LatLng point) { | |||
if (directionsRoutes == null || directionsRoutes.isEmpty() || !alternativesVisible) { | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT blank line
@@ -601,50 +607,66 @@ public void removeRoute() { | |||
|
|||
@Override | |||
public void onMapClick(@NonNull LatLng point) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO onMapClick
is getting too long.
What about extracting blocks of code into well-named (based on the comments) private
methods and simplifying conditional expressions?
List<com.mapbox.geojson.Point> linePoints = new ArrayList<>(); | ||
for (Feature feature : featureCollection.getFeatures()) { | ||
List<Position> positions = (List<Position>) feature.getGeometry().getCoordinates(); | ||
private boolean calculateClickDistancesFromRoutes(HashMap<Double, DirectionsRoute> routeDistancesAwayFromClick, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Long method.
@@ -703,7 +725,7 @@ public void onProgressChange(Location location, RouteProgress routeProgress) { | |||
* the source into pieces so data-driven styling can be used to change the route colors | |||
* accordingly. | |||
*/ | |||
private static FeatureCollection addTrafficToSource(DirectionsRoute route, int index) { | |||
private FeatureCollection addTrafficToSource(DirectionsRoute route, int index) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Long method.
19327e0
to
1b98f4a
Compare
@Guardiola31337 Added some refactoring to address your comments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although NavigationMapRoute
could be heavily refactored (there are some methods pretty long, a bunch magic numbers, among other things) this is definitely a good start 🚀
Good job @danesfeder 👏
Closes #701
Also fixed up some of the logic in regard to how we handle clicking on alternatives. Previously, if both routes were within the
250m
padding, the logic would sometimes still choose the index for the already clicked route even if we clicked on the alternative.Current
master
:This PR:
cc @cammace