From d14ab11bf7280d2d7b6ceafdc4a57d452634f094 Mon Sep 17 00:00:00 2001 From: Aaron Brethorst Date: Tue, 27 Feb 2024 21:15:02 -0800 Subject: [PATCH] Enhancement: Added directions to polylines when routing Upgraded gms:play-services-maps to 18.2.0 allows for arrows to be built into polylines which was previously not possible; this makes the directions of the routes easier to differentiate. Fixes #910 Co-authored-by: Adithya-hv --- onebusaway-android/build.gradle | 2 +- .../android/map/googlemapsv2/BaseMapFragment.java | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/onebusaway-android/build.gradle b/onebusaway-android/build.gradle index 5b3b89b7e..bfe09a70f 100644 --- a/onebusaway-android/build.gradle +++ b/onebusaway-android/build.gradle @@ -348,7 +348,7 @@ dependencies { // Pelias for point-of-interest search and geocoding for trip planning origin and destination implementation 'edu.usf.cutr:pelias-client-library:1.1.0' // Google Play Services Maps (only for Google flavor) - googleImplementation 'com.google.android.gms:play-services-maps:18.0.2' + googleImplementation 'com.google.android.gms:play-services-maps:18.2.0' // Google Play Services Places is required by ProprietaryMapHelpV2 (only for Google flavor) googleImplementation 'com.google.android.libraries.places:places-compat:1.1.0' // Autocomplete text views with clear button for trip planning diff --git a/onebusaway-android/src/google/java/org/onebusaway/android/map/googlemapsv2/BaseMapFragment.java b/onebusaway-android/src/google/java/org/onebusaway/android/map/googlemapsv2/BaseMapFragment.java index a6bf1a9b2..5f67c4a0a 100644 --- a/onebusaway-android/src/google/java/org/onebusaway/android/map/googlemapsv2/BaseMapFragment.java +++ b/onebusaway-android/src/google/java/org/onebusaway/android/map/googlemapsv2/BaseMapFragment.java @@ -53,6 +53,7 @@ import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.UiSettings; +import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.LatLngBounds; @@ -60,6 +61,10 @@ import com.google.android.gms.maps.model.Marker; import com.google.android.gms.maps.model.Polyline; import com.google.android.gms.maps.model.PolylineOptions; +import com.google.android.gms.maps.model.StampStyle; +import com.google.android.gms.maps.model.StrokeStyle; +import com.google.android.gms.maps.model.StyleSpan; +import com.google.android.gms.maps.model.TextureStyle; import com.google.android.gms.maps.model.VisibleRegion; import com.google.firebase.analytics.FirebaseAnalytics; @@ -1038,12 +1043,18 @@ public void setRouteOverlay(int lineOverlayColor, ObaShape[] shapes, boolean cle mLineOverlay.clear(); } PolylineOptions lineOptions; + StampStyle polylineArrow = TextureStyle.newBuilder( + BitmapDescriptorFactory.fromResource(R.drawable.ic_navigation_expand_more) + ).build(); + StyleSpan polylineArrowSpan = new StyleSpan( + StrokeStyle.colorBuilder(lineOverlayColor).stamp(polylineArrow).build() + ); int totalPoints = 0; for (ObaShape s : shapes) { lineOptions = new PolylineOptions(); - lineOptions.color(lineOverlayColor); + lineOptions.addSpan(polylineArrowSpan); for (Location l : s.getPoints()) { lineOptions.add(MapHelpV2.makeLatLng(l));