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

Fix bug with MapRoute onClick #703

Merged
merged 5 commits into from
Feb 15, 2018
Merged

Fix bug with MapRoute onClick #703

merged 5 commits into from
Feb 15, 2018

Conversation

danesfeder
Copy link
Contributor

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:
ezgif com-video-to-gif 1

This PR:
ezgif com-video-to-gif

cc @cammace

Copy link
Contributor

@Guardiola31337 Guardiola31337 left a 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) {

Copy link
Contributor

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) {
Copy link
Contributor

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,
Copy link
Contributor

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Long method.

@danesfeder
Copy link
Contributor Author

@Guardiola31337 Added some refactoring to address your comments

Copy link
Contributor

@Guardiola31337 Guardiola31337 left a 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 👏

@danesfeder danesfeder merged commit 27227c3 into master Feb 15, 2018
@danesfeder danesfeder deleted the dan-map-route-fix branch February 15, 2018 20:10
This was referenced Feb 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Defect to be fixed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

On map click, route line gets placed on top of markers
2 participants