add stops
This commit is contained in:
@@ -10,24 +10,28 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import kotlinx.serialization.Serializable
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import ovh.plrapps.mapcompose.api.addClusterer
|
||||
import ovh.plrapps.mapcompose.api.addLazyLoader
|
||||
import ovh.plrapps.mapcompose.api.addMarker
|
||||
import ovh.plrapps.mapcompose.ui.state.markers.model.RenderingStrategy
|
||||
import java.net.URL
|
||||
|
||||
@Serializable
|
||||
data class GTFSRoute(
|
||||
val agency_id: String,
|
||||
val agency_id: String?,
|
||||
val is_night: Boolean,
|
||||
val route_color: String,
|
||||
val route_color: String?,
|
||||
val route_desc: String? = null,
|
||||
val route_id: String,
|
||||
val route_long_name: String,
|
||||
val route_short_name: String,
|
||||
val route_text_color: String,
|
||||
val route_id: String?,
|
||||
val route_long_name: String?,
|
||||
val route_short_name: String?,
|
||||
val route_text_color: String?,
|
||||
val route_type: Int,
|
||||
val route_url: String,
|
||||
val route_url: String?,
|
||||
val is_regional: Boolean,
|
||||
val is_substitute_transport: Boolean
|
||||
)
|
||||
@@ -40,7 +44,7 @@ var gtfsRoutes: GTFSRoutes? = null
|
||||
@Serializable
|
||||
data class GTFSStopGeometry(
|
||||
val coordinates: List<Double>,
|
||||
val type: String
|
||||
val type: String?
|
||||
)
|
||||
|
||||
@Serializable
|
||||
@@ -49,7 +53,7 @@ data class GTFSStopProperties(
|
||||
val parent_station: String? = null,
|
||||
val platform_code: String? = null,
|
||||
val stop_id: String,
|
||||
val stop_name: String,
|
||||
val stop_name: String?,
|
||||
val wheelchair_boarding: Int,
|
||||
val zone_id: String? = null,
|
||||
val level_id: String? = null
|
||||
@@ -59,13 +63,13 @@ data class GTFSStopProperties(
|
||||
data class GTFSStop(
|
||||
val geometry: GTFSStopGeometry,
|
||||
val properties: GTFSStopProperties,
|
||||
val type: String
|
||||
val type: String?
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class GTFSStops(
|
||||
val features: List<GTFSStop>,
|
||||
val type: String
|
||||
val type: String?
|
||||
)
|
||||
|
||||
var gtfsStops: GTFSStops? = null
|
||||
@@ -113,6 +117,8 @@ fun startGTFSTracking(url: String, api_key: String, callee: Activity) {
|
||||
var gtfsUrl = URL(url);
|
||||
try {
|
||||
if(gtfsRoutes == null) {
|
||||
GTFSMainHandler.post {
|
||||
Toast.makeText(callee, "Fetching routes...", Toast.LENGTH_SHORT).show()}
|
||||
val request = Request.Builder()
|
||||
.url("${gtfsUrl.protocol}://${gtfsUrl.host}${callee.getString(R.string.routes_path)}")
|
||||
.header(
|
||||
@@ -130,6 +136,8 @@ fun startGTFSTracking(url: String, api_key: String, callee: Activity) {
|
||||
gtfsRoutes = json.decodeFromString<GTFSRoutes>(message)
|
||||
}}
|
||||
if(gtfsStops == null) {
|
||||
GTFSMainHandler.post {
|
||||
Toast.makeText(callee, "Fetching stops...", Toast.LENGTH_SHORT).show()}
|
||||
val request = Request.Builder()
|
||||
.url("${gtfsUrl.protocol}://${gtfsUrl.host}${callee.getString(R.string.stops_path)}")
|
||||
.header(
|
||||
@@ -147,22 +155,30 @@ fun startGTFSTracking(url: String, api_key: String, callee: Activity) {
|
||||
gtfsStops = json.decodeFromString<GTFSStops>(message)
|
||||
|
||||
// put all stops on the map
|
||||
GTFSMainHandler.post {
|
||||
Toast.makeText(callee, "Drawing stops...", Toast.LENGTH_SHORT).show()}
|
||||
for (stop in gtfsStops!!.features) {
|
||||
GTFSMainHandler.post {
|
||||
mapState.addMarker(stop.properties.stop_id, x = longitudeToXNormalized(stop.geometry.coordinates[0]), y = latitudeToYNormalized(stop.geometry.coordinates[0])) {
|
||||
|
||||
if (stop.properties.parent_station == null) {
|
||||
mapState.addMarker(stop.properties.stop_id, x = longitudeToXNormalized(stop.geometry.coordinates[0]), y = latitudeToYNormalized(stop.geometry.coordinates[1]), renderingStrategy = RenderingStrategy.LazyLoading("default")) {
|
||||
Icon(
|
||||
painter = painterResource(id = R.drawable.outline_directions_bus_24),
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(17.dp),
|
||||
modifier = Modifier.size(12.dp),
|
||||
tint = Color(0xFF0000FF)
|
||||
)
|
||||
}
|
||||
}}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
GTFSMainHandler.post {
|
||||
Toast.makeText(callee, "Done drawing stops", Toast.LENGTH_SHORT).show()}
|
||||
}}
|
||||
} catch(e: Exception) {
|
||||
GTFSMainHandler.post {
|
||||
Toast.makeText(callee, e.message ?: "Unknown error", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
GTFSMainHandler.post { stopGTFSTracking() }
|
||||
return@Thread
|
||||
}
|
||||
@@ -179,6 +195,7 @@ fun startGTFSTracking(url: String, api_key: String, callee: Activity) {
|
||||
|
||||
fun stopGTFSTracking() {
|
||||
GTFSIsTracking = false
|
||||
|
||||
GTFSTrackingThread?.interrupt()
|
||||
GTFSTrackingThread = null
|
||||
}
|
||||
Reference in New Issue
Block a user