Use Dp in features
This commit is contained in:
parent
5e548fcc65
commit
2fdec494fb
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
@ -3,11 +3,11 @@ package centre.sciprog.maps.compose
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.mutableStateMapOf
|
import androidx.compose.runtime.mutableStateMapOf
|
||||||
import androidx.compose.runtime.snapshots.SnapshotStateMap
|
import androidx.compose.runtime.snapshots.SnapshotStateMap
|
||||||
import androidx.compose.ui.geometry.Offset
|
|
||||||
import androidx.compose.ui.geometry.Size
|
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.drawscope.DrawScope
|
import androidx.compose.ui.graphics.drawscope.DrawScope
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
|
import androidx.compose.ui.unit.DpSize
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
typealias FeatureId = String
|
typealias FeatureId = String
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ fun FeatureBuilder.text(
|
|||||||
fun FeatureBuilder.image(
|
fun FeatureBuilder.image(
|
||||||
position: Pair<Double, Double>,
|
position: Pair<Double, Double>,
|
||||||
image: ImageVector,
|
image: ImageVector,
|
||||||
size: Size = Size(20f, 20f),
|
size: DpSize = DpSize(20.dp, 20.dp),
|
||||||
zoomRange: IntRange = defaultZoomRange,
|
zoomRange: IntRange = defaultZoomRange,
|
||||||
id: FeatureId? = null,
|
id: FeatureId? = null,
|
||||||
) = addFeature(id, MapVectorImageFeature(position.toCoordinates(), image, size, zoomRange))
|
) = addFeature(id, MapVectorImageFeature(position.toCoordinates(), image, size, zoomRange))
|
||||||
|
@ -9,7 +9,9 @@ import androidx.compose.ui.graphics.drawscope.DrawScope
|
|||||||
import androidx.compose.ui.graphics.painter.Painter
|
import androidx.compose.ui.graphics.painter.Painter
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
import androidx.compose.ui.graphics.vector.rememberVectorPainter
|
import androidx.compose.ui.graphics.vector.rememberVectorPainter
|
||||||
|
import androidx.compose.ui.unit.DpSize
|
||||||
import androidx.compose.ui.unit.IntSize
|
import androidx.compose.ui.unit.IntSize
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
import centre.sciprog.maps.GeodeticMapCoordinates
|
import centre.sciprog.maps.GeodeticMapCoordinates
|
||||||
import centre.sciprog.maps.GmcBox
|
import centre.sciprog.maps.GmcBox
|
||||||
import centre.sciprog.maps.wrapAll
|
import centre.sciprog.maps.wrapAll
|
||||||
@ -83,7 +85,7 @@ class MapBitmapImageFeature(
|
|||||||
class MapVectorImageFeature(
|
class MapVectorImageFeature(
|
||||||
val position: GeodeticMapCoordinates,
|
val position: GeodeticMapCoordinates,
|
||||||
val painter: Painter,
|
val painter: Painter,
|
||||||
val size: Size,
|
val size: DpSize,
|
||||||
zoomRange: IntRange = defaultZoomRange,
|
zoomRange: IntRange = defaultZoomRange,
|
||||||
) : MapFeature(zoomRange) {
|
) : MapFeature(zoomRange) {
|
||||||
override fun getBoundingBox(zoom: Int): GmcBox = GmcBox(position, position)
|
override fun getBoundingBox(zoom: Int): GmcBox = GmcBox(position, position)
|
||||||
@ -93,7 +95,7 @@ class MapVectorImageFeature(
|
|||||||
fun MapVectorImageFeature(
|
fun MapVectorImageFeature(
|
||||||
position: GeodeticMapCoordinates,
|
position: GeodeticMapCoordinates,
|
||||||
image: ImageVector,
|
image: ImageVector,
|
||||||
size: Size = Size(20f, 20f),
|
size: DpSize = DpSize(20.dp, 20.dp),
|
||||||
zoomRange: IntRange = defaultZoomRange,
|
zoomRange: IntRange = defaultZoomRange,
|
||||||
): MapVectorImageFeature = MapVectorImageFeature(position, rememberVectorPainter(image), size, zoomRange)
|
): MapVectorImageFeature = MapVectorImageFeature(position, rememberVectorPainter(image), size, zoomRange)
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ import androidx.compose.ui.ExperimentalComposeUiApi
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.geometry.Offset
|
import androidx.compose.ui.geometry.Offset
|
||||||
import androidx.compose.ui.geometry.Rect
|
import androidx.compose.ui.geometry.Rect
|
||||||
|
import androidx.compose.ui.geometry.Size
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.PathEffect
|
import androidx.compose.ui.graphics.PathEffect
|
||||||
import androidx.compose.ui.graphics.drawscope.*
|
import androidx.compose.ui.graphics.drawscope.*
|
||||||
@ -221,9 +222,10 @@ actual fun MapView(
|
|||||||
is MapBitmapImageFeature -> drawImage(feature.image, feature.position.toOffset())
|
is MapBitmapImageFeature -> drawImage(feature.image, feature.position.toOffset())
|
||||||
is MapVectorImageFeature -> {
|
is MapVectorImageFeature -> {
|
||||||
val offset = feature.position.toOffset()
|
val offset = feature.position.toOffset()
|
||||||
translate(offset.x - feature.size.width / 2, offset.y - feature.size.height / 2) {
|
val size = feature.size.toSize()
|
||||||
|
translate(offset.x - size.width / 2, offset.y - size.height / 2) {
|
||||||
with(feature.painter) {
|
with(feature.painter) {
|
||||||
draw(feature.size)
|
draw(size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user