feat: display route polylines
This commit is contained in:
parent
6372614a4d
commit
1d27013c4d
7 changed files with 112 additions and 11 deletions
|
|
@ -8,6 +8,7 @@ import io.ktor.client.plugins.defaultRequest
|
|||
import io.ktor.client.plugins.plugin
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.client.request.parameter
|
||||
import io.ktor.http.appendPathSegments
|
||||
import io.ktor.serialization.kotlinx.json.json
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
|
|
@ -18,7 +19,9 @@ import okio.ByteString.Companion.encodeUtf8
|
|||
|
||||
object Responses {
|
||||
@Serializable
|
||||
data class Route(val routes: List<moe.lava.banksia.api.ptv.structures.Route>)
|
||||
data class Route(val route: moe.lava.banksia.api.ptv.structures.Route)
|
||||
@Serializable
|
||||
data class Routes(val routes: List<moe.lava.banksia.api.ptv.structures.Route>)
|
||||
}
|
||||
|
||||
class PtvService {
|
||||
|
|
@ -44,8 +47,18 @@ class PtvService {
|
|||
}
|
||||
}
|
||||
|
||||
suspend fun route(id: Int, includeGeopath: Boolean = false): Route {
|
||||
val response: Responses.Route = client.get("routes") {
|
||||
url {
|
||||
appendPathSegments(id.toString())
|
||||
parameters.append("include_geopath", if (includeGeopath) "true" else "false")
|
||||
}
|
||||
}.body()
|
||||
return response.route
|
||||
}
|
||||
|
||||
suspend fun routes(): List<Route> {
|
||||
val response: Responses.Route = client.get("routes").body()
|
||||
val response: Responses.Routes = client.get("routes").body()
|
||||
return response.routes
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,14 @@ enum class GtfsSubType(val value: Int) {
|
|||
Interstate(10),
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class Geopath(
|
||||
@SerialName("direction_id") val directionId: Int,
|
||||
@SerialName("valid_from") val validFrom: String,
|
||||
@SerialName("valid_to") val validTo: String,
|
||||
@SerialName("paths") val paths: List<String>,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Route(
|
||||
@SerialName("route_type") val routeType: RouteType,
|
||||
|
|
@ -22,6 +30,7 @@ data class Route(
|
|||
@SerialName("route_number") val routeNumber: String,
|
||||
@SerialName("route_name") val routeName: String,
|
||||
@SerialName("route_gtfs_id") val routeGtfsId: String,
|
||||
@SerialName("geopath") val geopath: List<Geopath>,
|
||||
) {
|
||||
fun gtfsSubType(): GtfsSubType? {
|
||||
GtfsSubType.entries.forEach {
|
||||
|
|
@ -30,5 +39,13 @@ data class Route(
|
|||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun getShortFullName(): String {
|
||||
var res = ""
|
||||
if (this.routeNumber != "")
|
||||
res += this.routeNumber + " - "
|
||||
res += this.routeName.split(" via")[0]
|
||||
return res
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue