Quick fix for feature builder

This commit is contained in:
Alexander Nozik 2022-07-11 18:43:05 +03:00
parent ed4b603077
commit 792a755682
No known key found for this signature in database
GPG Key ID: F7FCF2DD25C71357
3 changed files with 9 additions and 16 deletions

View File

@ -2,8 +2,6 @@ package centre.sciprog.maps.compose
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateMapOf
import androidx.compose.runtime.snapshots.SnapshotStateMap
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import centre.sciprog.maps.GeodeticMapCoordinates import centre.sciprog.maps.GeodeticMapCoordinates
import centre.sciprog.maps.MapViewPoint import centre.sciprog.maps.MapViewPoint
@ -12,7 +10,7 @@ import centre.sciprog.maps.MapViewPoint
expect fun MapView( expect fun MapView(
initialViewPoint: MapViewPoint, initialViewPoint: MapViewPoint,
mapTileProvider: MapTileProvider, mapTileProvider: MapTileProvider,
features: SnapshotStateMap<FeatureId, MapFeature> = mutableStateMapOf(), features: Map<FeatureId, MapFeature>,
onClick: (GeodeticMapCoordinates) -> Unit = {}, onClick: (GeodeticMapCoordinates) -> Unit = {},
modifier: Modifier = Modifier.fillMaxSize(), modifier: Modifier = Modifier.fillMaxSize(),
) )
@ -21,9 +19,9 @@ expect fun MapView(
fun MapView( fun MapView(
initialViewPoint: MapViewPoint, initialViewPoint: MapViewPoint,
mapTileProvider: MapTileProvider, mapTileProvider: MapTileProvider,
modifier: Modifier = Modifier.fillMaxSize(),
onClick: (GeodeticMapCoordinates) -> Unit = {}, onClick: (GeodeticMapCoordinates) -> Unit = {},
addFeatures: @Composable FeatureBuilder.() -> Unit, modifier: Modifier = Modifier.fillMaxSize(),
addFeatures: @Composable() (FeatureBuilder.() -> Unit) = {},
) { ) {
val featuresBuilder = MapFeatureBuilder() val featuresBuilder = MapFeatureBuilder()
featuresBuilder.addFeatures() featuresBuilder.addFeatures()

View File

@ -43,27 +43,22 @@ fun App() {
MapView(viewPoint, mapTileProvider, onClick = { gmc: GeodeticMapCoordinates -> coordinates = gmc }) { MapView(viewPoint, mapTileProvider, onClick = { gmc: GeodeticMapCoordinates -> coordinates = gmc }) {
val pointOne = 55.568548 to 37.568604 val pointOne = 55.568548 to 37.568604
val pointTwo = 55.929444 to 37.518434 val pointTwo = 55.929444 to 37.518434
image(pointOne, Icons.Filled.Home) image(pointOne, Icons.Filled.Home)
//remember feature Id
val circleId: FeatureId = circle(pointTwo) val circleId: FeatureId = circle(pointTwo)
line(pointOne, pointTwo) line(pointOne, pointTwo)
text(pointOne, "Home") text(pointOne, "Home")
scope.launch { scope.launch {
while (isActive){ while (isActive){
delay(200) delay(200)
//Overwrite a feature with new color
circle(pointTwo, id = circleId, color = Color(Random.nextFloat(), Random.nextFloat(), Random.nextFloat())) circle(pointTwo, id = circleId, color = Color(Random.nextFloat(), Random.nextFloat(), Random.nextFloat()))
} }
} }
// // test dynamic rendering
// scope.launch{
// repeat(10000) {
// delay(10)
// val randomPoint =
// Random.nextDouble(55.568548, 55.929444) to Random.nextDouble(37.518434, 37.568604)
// circle(randomPoint)
// }
// }
} }
} }
} }

View File

@ -42,7 +42,7 @@ private val logger = KotlinLogging.logger("MapView")
actual fun MapView( actual fun MapView(
initialViewPoint: MapViewPoint, initialViewPoint: MapViewPoint,
mapTileProvider: MapTileProvider, mapTileProvider: MapTileProvider,
features: SnapshotStateMap<FeatureId, MapFeature>, features: Map<FeatureId, MapFeature>,
onClick: (GeodeticMapCoordinates) -> Unit, onClick: (GeodeticMapCoordinates) -> Unit,
modifier: Modifier, modifier: Modifier,
) { ) {