change logic of drawFeature to draw relative to offset

This commit is contained in:
Alexander Nozik 2022-07-19 10:16:53 +03:00
parent 307e42eac2
commit 5e548fcc65
No known key found for this signature in database
GPG Key ID: F7FCF2DD25C71357
4 changed files with 7 additions and 4 deletions

View File

@ -6,6 +6,7 @@ import androidx.compose.material.Text
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Home import androidx.compose.material.icons.filled.Home
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.window.Window import androidx.compose.ui.window.Window
@ -66,7 +67,7 @@ fun App() {
custom(position = pointThree) { custom(position = pointThree) {
drawRect( drawRect(
color = Color.Red, color = Color.Red,
topLeft = it, topLeft = Offset(-10f, -10f),
size = Size(20f, 20f) size = Size(20f, 20f)
) )
} }

View File

@ -48,7 +48,7 @@ fun FeatureBuilder.custom(
position: Pair<Double, Double>, position: Pair<Double, Double>,
zoomRange: IntRange = defaultZoomRange, zoomRange: IntRange = defaultZoomRange,
id: FeatureId? = null, id: FeatureId? = null,
drawFeature: DrawScope.(Offset) -> Unit, drawFeature: DrawScope.() -> Unit,
) = addFeature(id, MapDrawFeature(position.toCoordinates(), zoomRange, drawFeature)) ) = addFeature(id, MapDrawFeature(position.toCoordinates(), zoomRange, drawFeature))
fun FeatureBuilder.line( fun FeatureBuilder.line(

View File

@ -36,7 +36,7 @@ class MapFeatureSelector(val selector: (zoom: Int) -> MapFeature) : MapFeature(d
class MapDrawFeature( class MapDrawFeature(
val position: GeodeticMapCoordinates, val position: GeodeticMapCoordinates,
zoomRange: IntRange = defaultZoomRange, zoomRange: IntRange = defaultZoomRange,
val drawFeature: DrawScope.(Offset) -> Unit, val drawFeature: DrawScope.() -> Unit,
) : MapFeature(zoomRange) { ) : MapFeature(zoomRange) {
override fun getBoundingBox(zoom: Int): GmcBox { override fun getBoundingBox(zoom: Int): GmcBox {
//TODO add box computation //TODO add box computation

View File

@ -239,7 +239,9 @@ actual fun MapView(
} }
is MapDrawFeature -> { is MapDrawFeature -> {
val offset = feature.position.toOffset() val offset = feature.position.toOffset()
feature.drawFeature(this, offset) translate (offset.x, offset.y) {
feature.drawFeature(this)
}
} }
is MapFeatureGroup -> { is MapFeatureGroup -> {
feature.children.values.forEach { feature.children.values.forEach {