1+ package com.mapbox.maps.testapp.examples.location
2+
3+ import android.annotation.SuppressLint
4+ import android.os.Bundle
5+ import android.view.ViewGroup
6+ import android.widget.Button
7+ import androidx.appcompat.app.AppCompatActivity
8+ import com.mapbox.geojson.Point
9+ import com.mapbox.maps.CameraOptions
10+ import com.mapbox.maps.MapView
11+ import com.mapbox.maps.Style
12+ import com.mapbox.maps.extension.style.expressions.dsl.generated.literal
13+ import com.mapbox.maps.plugin.LocationPuck2D
14+ import com.mapbox.maps.plugin.LocationPuck3D
15+ import com.mapbox.maps.plugin.gestures.OnMapClickListener
16+ import com.mapbox.maps.plugin.gestures.gestures
17+ import com.mapbox.maps.plugin.locationcomponent.CustomJourneyLocationProvider
18+ import com.mapbox.maps.plugin.locationcomponent.Journey
19+ import com.mapbox.maps.plugin.locationcomponent.LocationComponentPlugin2
20+ import com.mapbox.maps.plugin.locationcomponent.location2
21+ import com.mapbox.maps.testapp.utils.LocationComponentUtils
22+ import com.mapbox.maps.testapp.utils.createLocationComponent
23+ import java.util.concurrent.CopyOnWriteArraySet
24+
25+ /* *
26+ * Example of using multiple location component.
27+ */
28+ class MultipleLocationComponentActivity : AppCompatActivity (), OnMapClickListener {
29+
30+ private val journey = Journey ()
31+ private val customJourneyLocationProvider = CustomJourneyLocationProvider ().apply { loadJourney(journey) }
32+ private lateinit var mapView: MapView
33+ private val locationComponents = CopyOnWriteArraySet <LocationComponentPlugin2 >()
34+
35+ @SuppressLint(" SetTextI18n" )
36+ override fun onCreate (savedInstanceState : Bundle ? ) {
37+ super .onCreate(savedInstanceState)
38+ mapView = MapView (this )
39+ setContentView(mapView)
40+ mapView.addView(
41+ Button (this ).apply {
42+ layoutParams = ViewGroup .LayoutParams (
43+ ViewGroup .LayoutParams .WRAP_CONTENT ,
44+ ViewGroup .LayoutParams .WRAP_CONTENT
45+ )
46+ text = " Cancel"
47+ setOnClickListener {
48+ journey.pause()
49+ }
50+ }
51+ )
52+ mapView.getMapboxMap()
53+ .apply {
54+ setCamera(
55+ CameraOptions .Builder ()
56+ .center(HELSINKI )
57+ .pitch(40.0 )
58+ .zoom(14.0 )
59+ .build()
60+ )
61+ loadStyleUri(Style .MAPBOX_STREETS ) {
62+ initLocationComponents()
63+ initClickListeners()
64+ journey.start()
65+ }
66+ }
67+ }
68+
69+ private fun initClickListeners () {
70+ mapView.gestures.addOnMapClickListener(this )
71+ }
72+
73+ private fun initLocationComponents () {
74+ locationComponents.add(
75+ mapView.createLocationComponent(LocationComponentUtils .getNextLocationComponentOptions()).apply {
76+ setLocationProvider(customJourneyLocationProvider)
77+ enabled = true
78+ locationPuck = LocationPuck2D (
79+ topImage = null ,
80+ bearingImage = null ,
81+ )
82+ puckBearingEnabled = true
83+ pulsingEnabled = true
84+ }
85+ )
86+ locationComponents.add(
87+ mapView.createLocationComponent(LocationComponentUtils .getNextLocationComponentOptions()).apply {
88+ setLocationProvider(customJourneyLocationProvider)
89+ enabled = true
90+ locationPuck = LocationPuck3D (
91+ modelUri = " asset://sportcar.glb" ,
92+ modelScale = listOf (0.2f , 0.2f , 0.2f ),
93+ modelTranslation = listOf (0.1f , 0.1f , 0.1f ),
94+ modelRotation = listOf (0.0f , 0.0f , 180.0f )
95+ )
96+ puckBearingEnabled = true
97+ }
98+ )
99+ locationComponents.add(
100+ mapView.createLocationComponent(LocationComponentUtils .getNextLocationComponentOptions()).apply {
101+ setLocationProvider(customJourneyLocationProvider)
102+ enabled = true
103+ locationPuck = LocationPuck3D (
104+ modelUri = " https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/Duck/glTF-Embedded/Duck.gltf" ,
105+ modelScale = listOf (0.2f , 0.2f , 0.2f ),
106+ modelRotation = listOf (0f , 0f , - 90f ),
107+ modelTranslation = listOf (0f , 0.0f , 0.0f )
108+ )
109+ puckBearingEnabled = true
110+ }
111+ )
112+
113+ }
114+
115+ override fun onMapClick (point : Point ): Boolean {
116+ journey.queueLocationUpdate(point)
117+ return true
118+ }
119+
120+ companion object {
121+ private val HELSINKI = Point .fromLngLat(24.9384 , 60.1699 )
122+ }
123+ }
0 commit comments