@@ -5,12 +5,10 @@ import android.os.Bundle
5
5
import android.view.ViewGroup
6
6
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
7
7
import android.widget.Button
8
+ import android.widget.LinearLayout
8
9
import androidx.appcompat.app.AppCompatActivity
9
10
import 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.*
14
12
import com.mapbox.maps.plugin.LocationPuck2D
15
13
import com.mapbox.maps.plugin.LocationPuck3D
16
14
import com.mapbox.maps.plugin.annotation.annotations
@@ -19,10 +17,18 @@ import com.mapbox.maps.plugin.gestures.OnMapClickListener
19
17
import com.mapbox.maps.plugin.gestures.gestures
20
18
import com.mapbox.maps.plugin.locationcomponent.CustomJourneyLocationProvider
21
19
import com.mapbox.maps.plugin.locationcomponent.Journey
20
+ import com.mapbox.maps.plugin.locationcomponent.LocationComponentInitOptions
22
21
import 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
23
28
import com.mapbox.maps.testapp.R
29
+ import com.mapbox.maps.testapp.databinding.ActivityMultiDisplayBinding
30
+ import com.mapbox.maps.testapp.databinding.ActivityMultiLocationcomponentBinding
24
31
import com.mapbox.maps.testapp.utils.BitmapUtils
25
- import com.mapbox.maps.testapp.utils.LocationComponentUtils
26
32
import com.mapbox.maps.testapp.utils.createLocationComponent
27
33
import java.util.*
28
34
@@ -32,7 +38,7 @@ import java.util.*
32
38
@OptIn(MapboxExperimental ::class )
33
39
class MultipleLocationComponentActivity : AppCompatActivity (), OnMapClickListener {
34
40
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 ))
36
42
private val customJourneyLocationProviders = mutableListOf (
37
43
CustomJourneyLocationProvider ().apply { loadJourney(journeys.first()) },
38
44
CustomJourneyLocationProvider ().apply { loadJourney(journeys.last()) }
@@ -41,24 +47,26 @@ class MultipleLocationComponentActivity : AppCompatActivity(), OnMapClickListene
41
47
mutableListOf (LinkedList <PointAnnotation >(), LinkedList <PointAnnotation >())
42
48
private val locationComponents = mutableListOf<LocationComponentPlugin2 >()
43
49
private lateinit var pointAnnotationManager: PointAnnotationManager
50
+ private lateinit var multiPuckViewportState: MultiPuckViewportState
44
51
45
52
var selectedPuck = 0
46
53
47
54
@SuppressLint(" SetTextI18n" )
48
55
override fun onCreate (savedInstanceState : Bundle ? ) {
49
56
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()
55
64
text = " Controlling ${if (selectedPuck == 0 ) " Car" else " Duck" } "
56
- setOnClickListener {
57
- toggleControl()
58
- text = " Controlling ${if (selectedPuck == 0 ) " Car" else " Duck" } "
59
- }
60
65
}
61
- )
66
+ }
67
+ binding.followPucksButton.setOnClickListener {
68
+ mapView.viewport.transitionTo(multiPuckViewportState)
69
+ }
62
70
pointAnnotationManager = mapView.annotations.createPointAnnotationManager()
63
71
mapView.getMapboxMap()
64
72
.apply {
@@ -97,7 +105,7 @@ class MultipleLocationComponentActivity : AppCompatActivity(), OnMapClickListene
97
105
private fun initLocationComponents () {
98
106
// Puck with pulsing car
99
107
locationComponents.add(
100
- mapView.createLocationComponent(LocationComponentUtils .getNextLocationComponentOptions ())
108
+ mapView.createLocationComponent(LocationComponentInitOptions .getNextUniqueLocationComponentOptions ())
101
109
.apply {
102
110
setLocationProvider(customJourneyLocationProviders.first())
103
111
enabled = true
@@ -110,7 +118,7 @@ class MultipleLocationComponentActivity : AppCompatActivity(), OnMapClickListene
110
118
}
111
119
)
112
120
locationComponents.add(
113
- mapView.createLocationComponent(LocationComponentUtils .getNextLocationComponentOptions ())
121
+ mapView.createLocationComponent(LocationComponentInitOptions .getNextUniqueLocationComponentOptions ())
114
122
.apply {
115
123
setLocationProvider(customJourneyLocationProviders.first())
116
124
enabled = true
@@ -125,7 +133,7 @@ class MultipleLocationComponentActivity : AppCompatActivity(), OnMapClickListene
125
133
)
126
134
// Puck with pulsing duck
127
135
locationComponents.add(
128
- mapView.createLocationComponent(LocationComponentUtils .getNextLocationComponentOptions ())
136
+ mapView.createLocationComponent(LocationComponentInitOptions .getNextUniqueLocationComponentOptions ())
129
137
.apply {
130
138
setLocationProvider(customJourneyLocationProviders.last())
131
139
enabled = true
@@ -138,7 +146,7 @@ class MultipleLocationComponentActivity : AppCompatActivity(), OnMapClickListene
138
146
}
139
147
)
140
148
locationComponents.add(
141
- mapView.createLocationComponent(LocationComponentUtils .getNextLocationComponentOptions ())
149
+ mapView.createLocationComponent(LocationComponentInitOptions .getNextUniqueLocationComponentOptions ())
142
150
.apply {
143
151
setLocationProvider(customJourneyLocationProviders.last())
144
152
enabled = true
@@ -151,6 +159,14 @@ class MultipleLocationComponentActivity : AppCompatActivity(), OnMapClickListene
151
159
puckBearingEnabled = true
152
160
}
153
161
)
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
+ )
154
170
}
155
171
156
172
override fun onMapClick (point : Point ): Boolean {
0 commit comments