/
BlueDot.kt
88 lines (73 loc) · 3.03 KB
/
BlueDot.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package ca.mappedin.playgroundsamples.examples
import android.os.Bundle
import android.util.Log
import android.widget.ProgressBar
import androidx.appcompat.app.AppCompatActivity
import ca.mappedin.playgroundsamples.R
import com.mappedin.sdk.MPIMapView
import com.mappedin.sdk.listeners.MPIMapViewListener
import com.mappedin.sdk.models.*
import com.mappedin.sdk.web.MPIOptions
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import java.util.*
import kotlin.concurrent.schedule
class BlueDot : AppCompatActivity(), MPIMapViewListener {
private lateinit var mapView: MPIMapView
private lateinit var progressBar: ProgressBar
private val positionsString: String by lazy { readFileContentFromAssets("blue-dot-positions.json").replace("\n", "") }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_example)
this.title = "Blue Dot"
progressBar = findViewById(R.id.loadingIndicator)
progressBar.bringToFront()
mapView = findViewById<MPIMapView>(R.id.mapView)
// See Trial API key Terms and Conditions
// https://developer.mappedin.com/api-keys/
mapView.loadVenue(
MPIOptions.Init(
"5eab30aa91b055001a68e996",
"RJyRXKcryCMy4erZqqCbuB1NbR66QTGNXVE0x3Pg6oCIlUR1",
"mappedin-demo-mall",
),
showVenueOptions = MPIOptions.ShowVenue(labelAllLocationsOnInit = true),
) { Log.e(javaClass.simpleName, "Error loading map view") }
mapView.listener = this
}
override fun onBlueDotPositionUpdate(update: MPIBlueDotPositionUpdate) {
}
override fun onBlueDotStateChange(stateChange: MPIBlueDotStateChange) {
}
override fun onDataLoaded(data: MPIData) {
}
override fun onFirstMapLoaded() {
progressBar.visibility = ProgressBar.INVISIBLE
mapView.blueDotManager.enable(options = MPIOptions.BlueDot(smoothing = false, showBearing = true))
mapView.blueDotManager.setState(MPIState.FOLLOW)
mapView.cameraManager.set(MPIOptions.CameraTransformCoordinate(zoom = 700.0))
// Load positions from blue-dot-positions.json
val positions = Json.decodeFromString<List<MPIPosition>>(positionsString)
val timer = Timer("Position Updater", false)
positions.forEachIndexed { index, position ->
timer.schedule(3000L * index) {
mapView.blueDotManager.updatePosition(position)
}
}
}
override fun onMapChanged(map: MPIMap) {
}
@Deprecated("Use MPIMapClickListener instead")
override fun onNothingClicked() {
}
@Deprecated("Use MPIMapClickListener instead")
override fun onPolygonClicked(polygon: MPINavigatable.MPIPolygon) {
}
override fun onStateChanged(state: MPIState) {
}
private fun readFileContentFromAssets(file: String): String {
return application.assets.open(file).bufferedReader().use {
it.readText()
}
}
}