Added new feature to draw points on the map #10
@ -6,6 +6,7 @@ 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.Offset
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.graphics.PointMode
|
||||||
import androidx.compose.ui.window.Window
|
import androidx.compose.ui.window.Window
|
||||||
import androidx.compose.ui.window.application
|
import androidx.compose.ui.window.application
|
||||||
import center.sciprog.maps.compose.*
|
import center.sciprog.maps.compose.*
|
||||||
@ -62,6 +63,18 @@ fun App() {
|
|||||||
|
|
||||||
image(pointOne, Icons.Filled.Home)
|
image(pointOne, Icons.Filled.Home)
|
||||||
|
|
||||||
|
points(
|
||||||
|
points = listOf(
|
||||||
|
55.742465 to 37.615812,
|
||||||
|
55.742713 to 37.616370,
|
||||||
|
55.742815 to 37.616659,
|
||||||
|
55.742320 to 37.617132,
|
||||||
|
55.742086 to 37.616566,
|
||||||
|
55.741715 to 37.616716
|
||||||
|
),
|
||||||
|
pointMode = PointMode.Polygon
|
||||||
|
)
|
||||||
|
|
||||||
//remember feature Id
|
//remember feature Id
|
||||||
val circleId: FeatureId = circle(
|
val circleId: FeatureId = circle(
|
||||||
centerCoordinates = pointTwo,
|
centerCoordinates = pointTwo,
|
||||||
|
@ -3,6 +3,7 @@ package center.sciprog.maps.compose
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.ImageBitmap
|
import androidx.compose.ui.graphics.ImageBitmap
|
||||||
|
import androidx.compose.ui.graphics.PointMode
|
||||||
import androidx.compose.ui.graphics.drawscope.DrawScope
|
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
|
||||||
@ -48,6 +49,18 @@ public class MapDrawFeature(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class MapPointsFeature(
|
||||||
|
public val points: List<GeodeticMapCoordinates>,
|
||||||
|
override val zoomRange: IntRange = defaultZoomRange,
|
||||||
|
public val stroke: Float = 2f,
|
||||||
|
public val color: Color = Color.Red,
|
||||||
|
public val pointMode: PointMode = PointMode.Points
|
||||||
|
) : MapFeature {
|
||||||
|
override fun getBoundingBox(zoom: Int): GmcBox {
|
||||||
|
return GmcBox(points.first(), points.last())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class MapCircleFeature(
|
public class MapCircleFeature(
|
||||||
public val center: GeodeticMapCoordinates,
|
public val center: GeodeticMapCoordinates,
|
||||||
override val zoomRange: IntRange = defaultZoomRange,
|
override val zoomRange: IntRange = defaultZoomRange,
|
||||||
|
@ -4,6 +4,7 @@ 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.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.graphics.PointMode
|
||||||
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.DpSize
|
||||||
@ -116,6 +117,15 @@ public fun MapFeatureBuilder.arc(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
public fun MapFeatureBuilder.points(
|
||||||
|
points: List<Pair<Double, Double>>,
|
||||||
|
zoomRange: IntRange = defaultZoomRange,
|
||||||
|
stroke: Float = 2f,
|
||||||
|
color: Color = Color.Red,
|
||||||
|
pointMode: PointMode = PointMode.Points,
|
||||||
|
id: FeatureId? = null
|
||||||
|
): FeatureId = addFeature(id, MapPointsFeature(points.map { it.toCoordinates() }, zoomRange, stroke, color, pointMode))
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
public fun MapFeatureBuilder.image(
|
public fun MapFeatureBuilder.image(
|
||||||
position: Pair<Double, Double>,
|
position: Pair<Double, Double>,
|
||||||
|
@ -275,6 +275,15 @@ public actual fun MapView(
|
|||||||
drawFeature(zoom, it)
|
drawFeature(zoom, it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
is MapPointsFeature -> {
|
||||||
|
val points = feature.points.map { it.toOffset() }
|
||||||
|
drawPoints(
|
||||||
|
points = points,
|
||||||
|
color = feature.color,
|
||||||
|
strokeWidth = feature.stroke,
|
||||||
|
pointMode = feature.pointMode
|
||||||
|
)
|
||||||
|
}
|
||||||
else -> {
|
else -> {
|
||||||
logger.error { "Unrecognized feature type: ${feature::class}" }
|
logger.error { "Unrecognized feature type: ${feature::class}" }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user