@@ -12,39 +12,27 @@ import com.mapconductor.core.map.MapViewState
1212import com.mapconductor.core.marker.DefaultIcon
1313import com.mapconductor.core.marker.MarkerState
1414import com.mapconductor.core.polyline.PolylineState
15- import com.mapconductor.example.toast.ToastMessage
1615import kotlinx.coroutines.flow.MutableStateFlow
1716import kotlinx.coroutines.flow.StateFlow
1817import kotlinx.coroutines.flow.asStateFlow
1918
2019interface PolylinePageViewModel {
2120 val initCameraPosition: MapCameraPosition
2221 val mapViewState: StateFlow <MapViewState <* >? >
23- val messages: StateFlow <List <ToastMessage >>
2422
2523 val wayPointMarkers: List <MarkerState >
2624 val polylineState: PolylineState
2725
2826 fun onMapViewChanged (state : MapViewState <* >)
2927
30- fun onMarkerClick (clicked : MarkerState )
31-
32- fun onMapClick (clicked : GeoPoint )
33-
3428 fun onPolylineClick (state : PolylineState )
3529
3630 fun onMarkerDrag (dragged : MarkerState )
37-
38- fun showToast (text : String )
39-
40- fun removeToast (toastMessage : ToastMessage )
4131}
4232
43- class PolylinePageViewModelImpl :
33+ class PolylinePageViewModelImpl () :
4434 ViewModel (),
4535 PolylinePageViewModel {
46- private val _messages : MutableStateFlow <List <ToastMessage >> = MutableStateFlow (emptyList())
47- override val messages: StateFlow <List <ToastMessage >> = _messages .asStateFlow()
4836
4937 override val initCameraPosition =
5038 MapCameraPosition (
@@ -71,30 +59,24 @@ class PolylinePageViewModelImpl :
7159 private val _wayPointMarkers : MutableState <List <MarkerState >> =
7260 mutableStateOf(
7361 polylinePoints.mapIndexed { index, point ->
62+ val markerColor = when {
63+ index == 0 -> Color .Green
64+ index == polylinePoints.size - 1 -> Color .Green
65+ else -> Color .Yellow
66+ }
67+ val label = when {
68+ index == 0 -> " S"
69+ index == polylinePoints.size - 1 -> " E"
70+ else -> " $index "
71+ }
7472 MarkerState (
7573 id = " waypoint_$index " ,
7674 position = point,
7775 icon =
7876 DefaultIcon (
79- fillColor =
80- if (index == 0 ||
81- index == polylinePoints.size - 1
82- ) {
83- Color .Green
84- } else {
85- Color .Blue
86- },
87- strokeColor = Color .White ,
88- label =
89- if (index ==
90- 0
91- ) {
92- " S"
93- } else if (index == polylinePoints.size - 1 ) {
94- " E"
95- } else {
96- " $index "
97- },
77+ fillColor = markerColor,
78+ strokeColor = Color .Black ,
79+ label = label,
9880 ),
9981 draggable = true ,
10082 )
@@ -125,18 +107,8 @@ class PolylinePageViewModelImpl :
125107 this ._mapViewState .value = state
126108 }
127109
128- override fun onMarkerClick (clicked : MarkerState ) {
129- val markerLabel = (clicked.icon as ? DefaultIcon )?.label ? : " Marker"
130- showToast(" Waypoint $markerLabel clicked" )
131- }
132-
133- override fun onMapClick (clicked : GeoPoint ) {
134- showToast(" Map clicked at: ${clicked.toUrlValue()} " )
135- }
136-
137110 override fun onPolylineClick (state : PolylineState ) {
138111 _polylineState .value.strokeColor = Color .Magenta
139- showToast(" Polyline clicked - ${state.points.size} points" )
140112 }
141113
142114 override fun onMarkerDrag (dragged : MarkerState ) {
@@ -148,14 +120,6 @@ class PolylinePageViewModelImpl :
148120 polylinePoints[markerIndex].longitude = dragged.position.longitude
149121 }
150122
151- override fun showToast (text : String ) {
152- this ._messages .value = this ._messages .value + ToastMessage (text = text)
153- }
154-
155- override fun removeToast (toastMessage : ToastMessage ) {
156- this ._messages .value = this ._messages .value.filter { it != toastMessage }
157- }
158-
159123 override fun onCleared () {
160124 super .onCleared()
161125 }
0 commit comments