map improvements and GTFS vehicle tracking bases
This commit is contained in:
@@ -4,10 +4,15 @@ import android.app.Activity
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.widget.Toast
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.unit.dp
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
import okhttp3.OkHttpClient
|
||||
import ovh.plrapps.mapcompose.api.addPath
|
||||
import ovh.plrapps.mapcompose.api.moveMarker
|
||||
import ovh.plrapps.mapcompose.api.removePath
|
||||
import ovh.plrapps.mapcompose.api.updatePath
|
||||
import java.net.URL
|
||||
|
||||
@Serializable
|
||||
@@ -28,8 +33,9 @@ val haukhttpClient = OkHttpClient.Builder()
|
||||
|
||||
private val HaukMainHandler = Handler(Looper.getMainLooper())
|
||||
private var HaukTrackingThread: Thread? = null
|
||||
private var HaukIsTracking = false
|
||||
var HaukIsTracking = false
|
||||
|
||||
private var PathCreated = false
|
||||
private fun fetchHaukPosition(haukUrl: String, callee: Activity) {
|
||||
try {
|
||||
val url = URL(haukUrl)
|
||||
@@ -76,6 +82,18 @@ private fun fetchHaukPosition(haukUrl: String, callee: Activity) {
|
||||
} catch (e: Exception) {
|
||||
// Marker might not exist yet, ignore
|
||||
}
|
||||
|
||||
pathDataBuilder.addPoint(longitudeToXNormalized(lon), latitudeToYNormalized(lat));
|
||||
if (!PathCreated) {
|
||||
mapState.addPath(
|
||||
"target_path", color = Color(0xFF0000FF),
|
||||
pathData = pathDataBuilder.build()?: return@post,
|
||||
width = 1.dp
|
||||
);
|
||||
PathCreated = true
|
||||
}
|
||||
mapState.updatePath("target_path", pathData = pathDataBuilder.build())
|
||||
|
||||
}
|
||||
} else {
|
||||
HaukMainHandler.post {
|
||||
@@ -95,6 +113,10 @@ fun startHaukTracking(url: String, callee: Activity) {
|
||||
if (HaukIsTracking) return
|
||||
|
||||
HaukIsTracking = true
|
||||
|
||||
|
||||
|
||||
|
||||
HaukTrackingThread = Thread {
|
||||
while (HaukIsTracking) {
|
||||
fetchHaukPosition(url, callee)
|
||||
@@ -111,4 +133,6 @@ fun stopHaukTracking() {
|
||||
HaukIsTracking = false
|
||||
HaukTrackingThread?.interrupt()
|
||||
HaukTrackingThread = null
|
||||
mapState.removePath("target_path");
|
||||
PathCreated = false;
|
||||
}
|
||||
Reference in New Issue
Block a user