@@ -3,6 +3,7 @@ package com.mapbox.navigation.examples.core
3
3
import android.annotation.SuppressLint
4
4
import android.content.res.Configuration
5
5
import android.content.res.Resources
6
+ import android.graphics.Color
6
7
import android.location.Location
7
8
import android.os.Bundle
8
9
import android.view.View.INVISIBLE
@@ -12,14 +13,22 @@ import androidx.appcompat.app.AppCompatActivity
12
13
import androidx.core.content.ContextCompat
13
14
import com.mapbox.api.directions.v5.models.RouteOptions
14
15
import com.mapbox.bindgen.Expected
16
+ import com.mapbox.geojson.Feature
17
+ import com.mapbox.geojson.FeatureCollection
15
18
import com.mapbox.geojson.Point
16
19
import com.mapbox.maps.CameraOptions
17
20
import com.mapbox.maps.EdgeInsets
18
21
import com.mapbox.maps.MapboxMap
22
+ import com.mapbox.maps.Style
19
23
import com.mapbox.maps.Style.Companion.MAPBOX_STREETS
24
+ import com.mapbox.maps.extension.style.layers.generated.CircleLayer
25
+ import com.mapbox.maps.extension.style.sources.generated.GeoJsonSource
26
+ import com.mapbox.maps.extension.style.sources.generated.geoJsonSource
27
+ import com.mapbox.maps.extension.style.sources.getSource
20
28
import com.mapbox.maps.plugin.LocationPuck2D
21
29
import com.mapbox.maps.plugin.animation.camera
22
30
import com.mapbox.maps.plugin.gestures.gestures
31
+ import com.mapbox.maps.plugin.locationcomponent.OnIndicatorPositionChangedListener
23
32
import com.mapbox.maps.plugin.locationcomponent.location
24
33
import com.mapbox.navigation.base.TimeFormat
25
34
import com.mapbox.navigation.base.extensions.applyDefaultNavigationOptions
@@ -226,6 +235,8 @@ class MapboxNavigationActivity : AppCompatActivity() {
226
235
227
236
// update bottom trip progress summary
228
237
binding.tripProgressView.render(tripProgressApi.getTripProgress(routeProgress))
238
+
239
+ // addPointToPixelMapPoints(routeLineAPI.getFillerPointsInTree())
229
240
}
230
241
231
242
private val routesObserver = RoutesObserver { result ->
@@ -268,6 +279,21 @@ class MapboxNavigationActivity : AppCompatActivity() {
268
279
logD(" sessionId=${mapboxNavigation.getNavigationSessionState().sessionId} " , LOG_CATEGORY )
269
280
}
270
281
282
+ private val locationComponent by lazy {
283
+ binding.mapView.location.apply {
284
+ setLocationProvider(navigationLocationProvider)
285
+ enabled = true
286
+ }
287
+ }
288
+
289
+ private val onPositionChangedListener = OnIndicatorPositionChangedListener { point ->
290
+ val result = routeLineAPI.updateTraveledRouteLine(point)
291
+ mapboxMap.getStyle()?.apply {
292
+ // Render the result to update the map.
293
+ routeLineView.renderRouteLineUpdate(this , result)
294
+ }
295
+ }
296
+
271
297
@SuppressLint(" MissingPermission" )
272
298
override fun onCreate (savedInstanceState : Bundle ? ) {
273
299
super .onCreate(savedInstanceState)
@@ -280,7 +306,7 @@ class MapboxNavigationActivity : AppCompatActivity() {
280
306
this .locationPuck = LocationPuck2D (
281
307
bearingImage = ContextCompat .getDrawable(
282
308
this @MapboxNavigationActivity,
283
- R .drawable.mapbox_navigation_puck_icon
309
+ R .drawable.custom_user_puck_icon
284
310
)
285
311
)
286
312
setLocationProvider(navigationLocationProvider)
@@ -317,7 +343,7 @@ class MapboxNavigationActivity : AppCompatActivity() {
317
343
// not handled
318
344
}
319
345
})
320
-
346
+ mapboxNavigation.setRerouteController( null )
321
347
// initialize Navigation Camera
322
348
viewportDataSource = MapboxNavigationViewportDataSource (
323
349
binding.mapView.getMapboxMap()
@@ -388,6 +414,7 @@ class MapboxNavigationActivity : AppCompatActivity() {
388
414
// initialize route line
389
415
val mapboxRouteLineOptions = MapboxRouteLineOptions .Builder (this )
390
416
.withRouteLineBelowLayerId(" road-label" )
417
+ .withVanishingRouteLineEnabled(true )
391
418
.build()
392
419
routeLineAPI = MapboxRouteLineApi (mapboxRouteLineOptions)
393
420
routeLineView = MapboxRouteLineView (mapboxRouteLineOptions)
@@ -402,6 +429,10 @@ class MapboxNavigationActivity : AppCompatActivity() {
402
429
findRoute(point)
403
430
true
404
431
}
432
+
433
+ // fixme remove this
434
+ initPointLayer(style)
435
+ locationComponent.addOnIndicatorPositionChangedListener(onPositionChangedListener)
405
436
}
406
437
407
438
// initialize view interactions
@@ -527,4 +558,29 @@ class MapboxNavigationActivity : AppCompatActivity() {
527
558
private companion object {
528
559
private const val LOG_CATEGORY = " MapboxNavigationActivity"
529
560
}
561
+
562
+ private val LINE_END_LAYER_ID = " DRAW_UTIL_LINE_END_LAYER_ID"
563
+ private val LINE_END_SOURCE_ID = " DRAW_UTIL_LINE_END_SOURCE_ID"
564
+ private fun initPointLayer (style : Style ) {
565
+ if (! style.styleSourceExists(LINE_END_SOURCE_ID )) {
566
+ geoJsonSource(LINE_END_SOURCE_ID ) {}.bindTo(style)
567
+ }
568
+
569
+ if (! style.styleLayerExists(LINE_END_LAYER_ID )) {
570
+ CircleLayer (LINE_END_LAYER_ID , LINE_END_SOURCE_ID )
571
+ .circleRadius(2.0 )
572
+ .circleOpacity(1.0 )
573
+ .circleColor(Color .BLACK )
574
+ .bindTo(style)
575
+ }
576
+ }
577
+
578
+ // todo remove this
579
+ private fun addPointToPixelMapPoints (points : List <Point >) {
580
+ val features = points.map { Feature .fromGeometry(it) }
581
+
582
+ (mapboxMap.getStyle()!! .getSource(LINE_END_SOURCE_ID ) as GeoJsonSource ).apply {
583
+ this .featureCollection(FeatureCollection .fromFeatures(features))
584
+ }
585
+ }
530
586
}
0 commit comments