feat: basic stop markers on route

This commit is contained in:
LavaDesu 2025-04-29 22:58:26 +10:00
parent 6a5a9b4974
commit 67f18afc01
Signed by: cilly
GPG key ID: 6500251E087653C9
5 changed files with 108 additions and 6 deletions

View file

@ -37,9 +37,12 @@ import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.launch
import moe.lava.banksia.api.ptv.PtvService
import moe.lava.banksia.api.ptv.structures.PtvRoute
import moe.lava.banksia.api.ptv.structures.PtvStop
import moe.lava.banksia.api.ptv.structures.getProperties
import moe.lava.banksia.native.BanksiaTheme
import moe.lava.banksia.native.maps.Maps
import moe.lava.banksia.native.maps.Marker
import moe.lava.banksia.native.maps.MarkerType
import moe.lava.banksia.native.maps.Point
import moe.lava.banksia.native.maps.Polyline
import moe.lava.banksia.native.maps.getScreenHeight
@ -147,6 +150,9 @@ fun App() {
var peekHeight by remember { mutableStateOf(128.dp) }
var peekHeightMultiplier by remember { mutableFloatStateOf(1F) }
var markers by remember { mutableStateOf(listOf<Marker>()) }
LaunchedEffect(route) { route?.let { markers = buildStops(ptvService, it) {} } }
BanksiaTheme {
BottomSheetScaffold(
scaffoldState = scaffoldState,
@ -160,6 +166,7 @@ fun App() {
newCameraPosition = newCameraPosition,
cameraPositionUpdated = { newCameraPosition = null },
extInsets = WindowInsets(top = with(LocalDensity.current) { 56.dp.roundToPx() }, bottom = extInsets),
markers = markers,
polylines = polylines,
)
Searcher(
@ -208,3 +215,37 @@ fun App() {
}
}
}
suspend fun buildStops(
ptvService: PtvService,
route: PtvRoute,
launchInfoPanel: (PtvStop) -> Unit,
): List<Marker> {
var stops = ptvService.stopsByRoute(route.routeId, route.routeType)
var res = mutableListOf<Marker>()
val colour = route.routeType.getProperties().colour
for (stop in stops) {
if (stop.stopLatitude != null && stop.stopLongitude != null) {
val pos = Point(stop.stopLatitude!!, stop.stopLongitude!!)
var name = stop.stopName;
if (name.endsWith(" Station"))
name = name.replace(" Station", "")
val marker = Marker(
name = name,
point = pos,
type = MarkerType.GENERIC_STOP,
colour = colour,
onClick = {
launchInfoPanel(stop)
false
}
)
res.add(marker)
}
}
return res
}

View file

@ -6,7 +6,16 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
data class Marker(val name: String, val onClick: () -> Boolean)
enum class MarkerType {
GENERIC_STOP,
}
data class Marker(
val point: Point,
val name: String,
val type: MarkerType,
val colour: Color,
val onClick: () -> Boolean
)
data class Point(val lat: Double, val lng: Double)
data class Polyline(val points: List<Point>, val colour: Color)