@@ -5,12 +5,10 @@ import android.os.Bundle
55import android.view.ViewGroup
66import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
77import android.widget.Button
8+ import android.widget.LinearLayout
89import androidx.appcompat.app.AppCompatActivity
910import com.mapbox.geojson.Point
10- import com.mapbox.maps.CameraOptions
11- import com.mapbox.maps.MapView
12- import com.mapbox.maps.MapboxExperimental
13- import com.mapbox.maps.Style
11+ import com.mapbox.maps.*
1412import com.mapbox.maps.plugin.LocationPuck2D
1513import com.mapbox.maps.plugin.LocationPuck3D
1614import com.mapbox.maps.plugin.annotation.annotations
@@ -19,10 +17,18 @@ import com.mapbox.maps.plugin.gestures.OnMapClickListener
1917import com.mapbox.maps.plugin.gestures.gestures
2018import com.mapbox.maps.plugin.locationcomponent.CustomJourneyLocationProvider
2119import com.mapbox.maps.plugin.locationcomponent.Journey
20+ import com.mapbox.maps.plugin.locationcomponent.LocationComponentInitOptions
2221import com.mapbox.maps.plugin.locationcomponent.LocationComponentPlugin2
22+ import com.mapbox.maps.plugin.viewport.data.FollowPuckViewportStateBearing
23+ import com.mapbox.maps.plugin.viewport.data.FollowPuckViewportStateOptions
24+ import com.mapbox.maps.plugin.viewport.data.MultiPuckViewportStateBearing
25+ import com.mapbox.maps.plugin.viewport.data.MultiPuckViewportStateOptions
26+ import com.mapbox.maps.plugin.viewport.state.MultiPuckViewportState
27+ import com.mapbox.maps.plugin.viewport.viewport
2328import com.mapbox.maps.testapp.R
29+ import com.mapbox.maps.testapp.databinding.ActivityMultiDisplayBinding
30+ import com.mapbox.maps.testapp.databinding.ActivityMultiLocationcomponentBinding
2431import com.mapbox.maps.testapp.utils.BitmapUtils
25- import com.mapbox.maps.testapp.utils.LocationComponentUtils
2632import com.mapbox.maps.testapp.utils.createLocationComponent
2733import java.util.*
2834
@@ -32,7 +38,7 @@ import java.util.*
3238@OptIn(MapboxExperimental ::class )
3339class MultipleLocationComponentActivity : AppCompatActivity (), OnMapClickListener {
3440 private lateinit var mapView: MapView
35- private val journeys = mutableListOf (Journey (speed = 150.0 ), Journey (speed = 100.0 ))
41+ private val journeys = mutableListOf (Journey (speed = 150.0 , angularSpeed = 150.0 ), Journey (speed = 100.0 , angularSpeed = 150 .0 ))
3642 private val customJourneyLocationProviders = mutableListOf (
3743 CustomJourneyLocationProvider ().apply { loadJourney(journeys.first()) },
3844 CustomJourneyLocationProvider ().apply { loadJourney(journeys.last()) }
@@ -41,24 +47,26 @@ class MultipleLocationComponentActivity : AppCompatActivity(), OnMapClickListene
4147 mutableListOf (LinkedList <PointAnnotation >(), LinkedList <PointAnnotation >())
4248 private val locationComponents = mutableListOf<LocationComponentPlugin2 >()
4349 private lateinit var pointAnnotationManager: PointAnnotationManager
50+ private lateinit var multiPuckViewportState: MultiPuckViewportState
4451
4552 var selectedPuck = 0
4653
4754 @SuppressLint(" SetTextI18n" )
4855 override fun onCreate (savedInstanceState : Bundle ? ) {
4956 super .onCreate(savedInstanceState)
50- mapView = MapView (this )
51- setContentView(mapView)
52- mapView.addView(
53- Button (this ).apply {
54- layoutParams = ViewGroup .LayoutParams (WRAP_CONTENT , WRAP_CONTENT )
57+ val binding = ActivityMultiLocationcomponentBinding .inflate(layoutInflater)
58+ setContentView(binding.root)
59+ mapView = binding.mapView
60+ binding.toggleControlBtn.apply {
61+ text = " Controlling ${if (selectedPuck == 0 ) " Car" else " Duck" } "
62+ setOnClickListener {
63+ toggleControl()
5564 text = " Controlling ${if (selectedPuck == 0 ) " Car" else " Duck" } "
56- setOnClickListener {
57- toggleControl()
58- text = " Controlling ${if (selectedPuck == 0 ) " Car" else " Duck" } "
59- }
6065 }
61- )
66+ }
67+ binding.followPucksButton.setOnClickListener {
68+ mapView.viewport.transitionTo(multiPuckViewportState)
69+ }
6270 pointAnnotationManager = mapView.annotations.createPointAnnotationManager()
6371 mapView.getMapboxMap()
6472 .apply {
@@ -97,7 +105,7 @@ class MultipleLocationComponentActivity : AppCompatActivity(), OnMapClickListene
97105 private fun initLocationComponents () {
98106 // Puck with pulsing car
99107 locationComponents.add(
100- mapView.createLocationComponent(LocationComponentUtils .getNextLocationComponentOptions ())
108+ mapView.createLocationComponent(LocationComponentInitOptions .getNextUniqueLocationComponentOptions ())
101109 .apply {
102110 setLocationProvider(customJourneyLocationProviders.first())
103111 enabled = true
@@ -110,7 +118,7 @@ class MultipleLocationComponentActivity : AppCompatActivity(), OnMapClickListene
110118 }
111119 )
112120 locationComponents.add(
113- mapView.createLocationComponent(LocationComponentUtils .getNextLocationComponentOptions ())
121+ mapView.createLocationComponent(LocationComponentInitOptions .getNextUniqueLocationComponentOptions ())
114122 .apply {
115123 setLocationProvider(customJourneyLocationProviders.first())
116124 enabled = true
@@ -125,7 +133,7 @@ class MultipleLocationComponentActivity : AppCompatActivity(), OnMapClickListene
125133 )
126134 // Puck with pulsing duck
127135 locationComponents.add(
128- mapView.createLocationComponent(LocationComponentUtils .getNextLocationComponentOptions ())
136+ mapView.createLocationComponent(LocationComponentInitOptions .getNextUniqueLocationComponentOptions ())
129137 .apply {
130138 setLocationProvider(customJourneyLocationProviders.last())
131139 enabled = true
@@ -138,7 +146,7 @@ class MultipleLocationComponentActivity : AppCompatActivity(), OnMapClickListene
138146 }
139147 )
140148 locationComponents.add(
141- mapView.createLocationComponent(LocationComponentUtils .getNextLocationComponentOptions ())
149+ mapView.createLocationComponent(LocationComponentInitOptions .getNextUniqueLocationComponentOptions ())
142150 .apply {
143151 setLocationProvider(customJourneyLocationProviders.last())
144152 enabled = true
@@ -151,6 +159,14 @@ class MultipleLocationComponentActivity : AppCompatActivity(), OnMapClickListene
151159 puckBearingEnabled = true
152160 }
153161 )
162+ multiPuckViewportState = mapView.viewport.makeMultiPuckViewportState(
163+ MultiPuckViewportStateOptions
164+ .Builder ()
165+ .bearing(MultiPuckViewportStateBearing .SyncWithLocationPuck (locationComponents.first()))
166+ .padding(EdgeInsets (100.0 , 100.0 , 100.0 , 100.0 ))
167+ .build(),
168+ locationComponents = locationComponents
169+ )
154170 }
155171
156172 override fun onMapClick (point : Point ): Boolean {
0 commit comments