Fix scheme
This commit is contained in:
parent
70fe9cf97a
commit
69e7b058d2
@ -31,10 +31,10 @@ fun App() {
|
|||||||
|
|
||||||
val schemeFeaturesState = FeatureGroup.remember(XYCoordinateSpace) {
|
val schemeFeaturesState = FeatureGroup.remember(XYCoordinateSpace) {
|
||||||
background(1600f, 1200f) { painterResource("middle-earth.jpg") }
|
background(1600f, 1200f) { painterResource("middle-earth.jpg") }
|
||||||
circle(410.52737 to 868.7676, color = Color.Blue)
|
circle(410.52737 to 868.7676).color(Color.Blue)
|
||||||
text(410.52737 to 868.7676, "Shire", color = Color.Blue)
|
text(410.52737 to 868.7676, "Shire").color(Color.Blue)
|
||||||
circle(1132.0881 to 394.99127, color = Color.Red)
|
circle(1132.0881 to 394.99127).color(Color.Red)
|
||||||
text(1132.0881 to 394.99127, "Ordruin", color = Color.Red)
|
text(1132.0881 to 394.99127, "Ordruin").color(Color.Red)
|
||||||
arc(center = 1132.0881 to 394.99127, radius = 20f, startAngle = 0f, 2 * PI.toFloat())
|
arc(center = 1132.0881 to 394.99127, radius = 20f, startAngle = 0f, 2 * PI.toFloat())
|
||||||
|
|
||||||
circle(410.52737 to 868.7676, id = "hobbit")
|
circle(410.52737 to 868.7676, id = "hobbit")
|
||||||
@ -44,7 +44,7 @@ fun App() {
|
|||||||
while (isActive) {
|
while (isActive) {
|
||||||
val x = 410.52737 + t * (1132.0881 - 410.52737)
|
val x = 410.52737 + t * (1132.0881 - 410.52737)
|
||||||
val y = 868.7676 + t * (394.99127 - 868.7676)
|
val y = 868.7676 + t * (394.99127 - 868.7676)
|
||||||
circle(x to y, color = Color.Green, id = "hobbit")
|
circle(x to y, id = "hobbit").color(Color.Green)
|
||||||
delay(100)
|
delay(100)
|
||||||
t += 0.005
|
t += 0.005
|
||||||
if (t >= 1.0) t = 0.0
|
if (t >= 1.0) t = 0.0
|
||||||
|
@ -14,6 +14,7 @@ import androidx.compose.ui.graphics.toComposeImageBitmap
|
|||||||
import androidx.compose.ui.unit.IntOffset
|
import androidx.compose.ui.unit.IntOffset
|
||||||
import androidx.compose.ui.unit.IntSize
|
import androidx.compose.ui.unit.IntSize
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import center.sciprog.attributes.z
|
||||||
import center.sciprog.maps.coordinates.Gmc
|
import center.sciprog.maps.coordinates.Gmc
|
||||||
import center.sciprog.maps.features.FeatureGroup
|
import center.sciprog.maps.features.FeatureGroup
|
||||||
import center.sciprog.maps.features.PainterFeature
|
import center.sciprog.maps.features.PainterFeature
|
||||||
@ -120,7 +121,7 @@ public actual fun MapView(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
featuresState.features
|
featuresState.featureMap.values.sortedBy { it.z }
|
||||||
.filter { viewPoint.zoom in it.zoomRange }
|
.filter { viewPoint.zoom in it.zoomRange }
|
||||||
.forEach { feature ->
|
.forEach { feature ->
|
||||||
drawFeature(mapState, painterCache, feature)
|
drawFeature(mapState, painterCache, feature)
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package center.sciprog.maps.scheme
|
package center.sciprog.maps.scheme
|
||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
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.painter.Painter
|
import androidx.compose.ui.graphics.painter.Painter
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
@ -30,7 +29,6 @@ fun FeatureGroup<XY>.background(
|
|||||||
ScalableImageFeature(
|
ScalableImageFeature(
|
||||||
space,
|
space,
|
||||||
box,
|
box,
|
||||||
zoomRange = defaultZoomRange,
|
|
||||||
painter = painter,
|
painter = painter,
|
||||||
attributes = Attributes(ZAttribute, -100f)
|
attributes = Attributes(ZAttribute, -100f)
|
||||||
)
|
)
|
||||||
@ -39,26 +37,21 @@ fun FeatureGroup<XY>.background(
|
|||||||
|
|
||||||
fun FeatureGroup<XY>.circle(
|
fun FeatureGroup<XY>.circle(
|
||||||
centerCoordinates: Pair<Number, Number>,
|
centerCoordinates: Pair<Number, Number>,
|
||||||
zoomRange: FloatRange = defaultZoomRange,
|
|
||||||
size: Dp = 5.dp,
|
size: Dp = 5.dp,
|
||||||
color: Color = Color.Red,
|
|
||||||
id: String? = null,
|
id: String? = null,
|
||||||
): FeatureId<CircleFeature<XY>> = circle(centerCoordinates.toCoordinates(), zoomRange, size, color, id = id)
|
): FeatureId<CircleFeature<XY>> = circle(centerCoordinates.toCoordinates(), size, id = id)
|
||||||
|
|
||||||
fun FeatureGroup<XY>.draw(
|
fun FeatureGroup<XY>.draw(
|
||||||
position: Pair<Number, Number>,
|
position: Pair<Number, Number>,
|
||||||
zoomRange: FloatRange = defaultZoomRange,
|
|
||||||
id: String? = null,
|
id: String? = null,
|
||||||
draw: DrawScope.() -> Unit,
|
draw: DrawScope.() -> Unit,
|
||||||
): FeatureId<DrawFeature<XY>> = draw(position.toCoordinates(), zoomRange = zoomRange, id = id, draw = draw)
|
): FeatureId<DrawFeature<XY>> = draw(position.toCoordinates(), id = id, draw = draw)
|
||||||
|
|
||||||
fun FeatureGroup<XY>.line(
|
fun FeatureGroup<XY>.line(
|
||||||
aCoordinates: Pair<Number, Number>,
|
aCoordinates: Pair<Number, Number>,
|
||||||
bCoordinates: Pair<Number, Number>,
|
bCoordinates: Pair<Number, Number>,
|
||||||
scaleRange: FloatRange = defaultZoomRange,
|
|
||||||
color: Color = Color.Red,
|
|
||||||
id: String? = null,
|
id: String? = null,
|
||||||
): FeatureId<LineFeature<XY>> = line(aCoordinates.toCoordinates(), bCoordinates.toCoordinates(), scaleRange, color, id)
|
): FeatureId<LineFeature<XY>> = line(aCoordinates.toCoordinates(), bCoordinates.toCoordinates(), id)
|
||||||
|
|
||||||
|
|
||||||
public fun FeatureGroup<XY>.arc(
|
public fun FeatureGroup<XY>.arc(
|
||||||
@ -66,15 +59,11 @@ public fun FeatureGroup<XY>.arc(
|
|||||||
radius: Float,
|
radius: Float,
|
||||||
startAngle: Float,
|
startAngle: Float,
|
||||||
arcLength: Float,
|
arcLength: Float,
|
||||||
zoomRange: FloatRange = defaultZoomRange,
|
|
||||||
color: Color = Color.Red,
|
|
||||||
id: String? = null,
|
id: String? = null,
|
||||||
): FeatureId<ArcFeature<XY>> = arc(
|
): FeatureId<ArcFeature<XY>> = arc(
|
||||||
oval = XYCoordinateSpace.Rectangle(center.toCoordinates(), radius, radius),
|
oval = XYCoordinateSpace.Rectangle(center.toCoordinates(), radius, radius),
|
||||||
startAngle = startAngle,
|
startAngle = startAngle,
|
||||||
arcLength = arcLength,
|
arcLength = arcLength,
|
||||||
zoomRange = zoomRange,
|
|
||||||
color = color,
|
|
||||||
id = id
|
id = id
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -82,16 +71,13 @@ fun FeatureGroup<XY>.image(
|
|||||||
position: Pair<Number, Number>,
|
position: Pair<Number, Number>,
|
||||||
image: ImageVector,
|
image: ImageVector,
|
||||||
size: DpSize = DpSize(image.defaultWidth, image.defaultHeight),
|
size: DpSize = DpSize(image.defaultWidth, image.defaultHeight),
|
||||||
zoomRange: FloatRange = defaultZoomRange,
|
|
||||||
id: String? = null,
|
id: String? = null,
|
||||||
): FeatureId<VectorImageFeature<XY>> =
|
): FeatureId<VectorImageFeature<XY>> =
|
||||||
image(position.toCoordinates(), image, size = size, zoomRange = zoomRange, id = id)
|
image(position.toCoordinates(), image, size = size, id = id)
|
||||||
|
|
||||||
fun FeatureGroup<XY>.text(
|
fun FeatureGroup<XY>.text(
|
||||||
position: Pair<Number, Number>,
|
position: Pair<Number, Number>,
|
||||||
text: String,
|
text: String,
|
||||||
zoomRange: FloatRange = defaultZoomRange,
|
|
||||||
color: Color = Color.Red,
|
|
||||||
id: String? = null,
|
id: String? = null,
|
||||||
): FeatureId<TextFeature<XY>> = text(position.toCoordinates(), text, zoomRange, color, id = id)
|
): FeatureId<TextFeature<XY>> = text(position.toCoordinates(), text, id = id)
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import androidx.compose.ui.graphics.drawscope.Stroke
|
|||||||
import androidx.compose.ui.graphics.drawscope.clipRect
|
import androidx.compose.ui.graphics.drawscope.clipRect
|
||||||
import androidx.compose.ui.graphics.painter.Painter
|
import androidx.compose.ui.graphics.painter.Painter
|
||||||
import androidx.compose.ui.unit.DpSize
|
import androidx.compose.ui.unit.DpSize
|
||||||
|
import center.sciprog.attributes.z
|
||||||
import center.sciprog.maps.compose.mapControls
|
import center.sciprog.maps.compose.mapControls
|
||||||
import center.sciprog.maps.features.*
|
import center.sciprog.maps.features.*
|
||||||
import mu.KotlinLogging
|
import mu.KotlinLogging
|
||||||
@ -30,7 +31,7 @@ public fun SchemeView(
|
|||||||
featuresState.features.filterIsInstance<PainterFeature<XY>>().associateWith { it.getPainter() }
|
featuresState.features.filterIsInstance<PainterFeature<XY>>().associateWith { it.getPainter() }
|
||||||
}
|
}
|
||||||
|
|
||||||
Canvas(modifier = modifier.mapControls(state, featuresState.features).fillMaxSize()) {
|
Canvas(modifier = modifier.mapControls(state, featuresState).fillMaxSize()) {
|
||||||
|
|
||||||
if (canvasSize != size.toDpSize()) {
|
if (canvasSize != size.toDpSize()) {
|
||||||
canvasSize = size.toDpSize()
|
canvasSize = size.toDpSize()
|
||||||
@ -38,7 +39,7 @@ public fun SchemeView(
|
|||||||
}
|
}
|
||||||
|
|
||||||
clipRect {
|
clipRect {
|
||||||
featuresState.features
|
featuresState.featureMap.values.sortedBy { it.z }
|
||||||
.filter { viewPoint.zoom in it.zoomRange }
|
.filter { viewPoint.zoom in it.zoomRange }
|
||||||
.forEach { background ->
|
.forEach { background ->
|
||||||
drawFeature(state, painterCache, background)
|
drawFeature(state, painterCache, background)
|
||||||
|
@ -3,10 +3,12 @@ package center.sciprog.maps.svg
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.geometry.Offset
|
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.drawscope.Stroke
|
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||||
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
|
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
|
||||||
import androidx.compose.ui.graphics.drawscope.translate
|
import androidx.compose.ui.graphics.drawscope.translate
|
||||||
import androidx.compose.ui.graphics.painter.Painter
|
import androidx.compose.ui.graphics.painter.Painter
|
||||||
|
import center.sciprog.attributes.AlphaAttribute
|
||||||
import center.sciprog.maps.features.*
|
import center.sciprog.maps.features.*
|
||||||
import center.sciprog.maps.scheme.*
|
import center.sciprog.maps.scheme.*
|
||||||
import org.jfree.svg.SVGGraphics2D
|
import org.jfree.svg.SVGGraphics2D
|
||||||
@ -41,6 +43,10 @@ fun FeatureStateSnapshot<XY>.generateSvg(
|
|||||||
|
|
||||||
|
|
||||||
fun SvgDrawScope.drawFeature(scale: Float, feature: Feature<XY>) {
|
fun SvgDrawScope.drawFeature(scale: Float, feature: Feature<XY>) {
|
||||||
|
|
||||||
|
val color = feature.color ?: Color.Red
|
||||||
|
val alpha = feature.attributes[AlphaAttribute]?:1f
|
||||||
|
|
||||||
when (feature) {
|
when (feature) {
|
||||||
is ScalableImageFeature -> {
|
is ScalableImageFeature -> {
|
||||||
val offset = XY(feature.rectangle.left, feature.rectangle.top).toOffset()
|
val offset = XY(feature.rectangle.left, feature.rectangle.top).toOffset()
|
||||||
@ -59,12 +65,12 @@ fun FeatureStateSnapshot<XY>.generateSvg(
|
|||||||
is FeatureSelector -> drawFeature(scale, feature.selector(scale))
|
is FeatureSelector -> drawFeature(scale, feature.selector(scale))
|
||||||
|
|
||||||
is CircleFeature -> drawCircle(
|
is CircleFeature -> drawCircle(
|
||||||
feature.color,
|
color,
|
||||||
feature.size.toPx(),
|
feature.size.toPx(),
|
||||||
center = feature.center.toOffset()
|
center = feature.center.toOffset()
|
||||||
)
|
)
|
||||||
|
|
||||||
is LineFeature -> drawLine(feature.color, feature.a.toOffset(), feature.b.toOffset())
|
is LineFeature -> drawLine(color, feature.a.toOffset(), feature.b.toOffset())
|
||||||
|
|
||||||
is ArcFeature -> {
|
is ArcFeature -> {
|
||||||
val topLeft = feature.oval.leftTop.toOffset()
|
val topLeft = feature.oval.leftTop.toOffset()
|
||||||
@ -73,7 +79,7 @@ fun FeatureStateSnapshot<XY>.generateSvg(
|
|||||||
val size = Size(abs(topLeft.x - bottomRight.x), abs(topLeft.y - bottomRight.y))
|
val size = Size(abs(topLeft.x - bottomRight.x), abs(topLeft.y - bottomRight.y))
|
||||||
|
|
||||||
drawArc(
|
drawArc(
|
||||||
color = feature.color,
|
color = color,
|
||||||
startAngle = (feature.startAngle * 180 / PI).toFloat(),
|
startAngle = (feature.startAngle * 180 / PI).toFloat(),
|
||||||
sweepAngle = (feature.arcLength * 180 / PI).toFloat(),
|
sweepAngle = (feature.arcLength * 180 / PI).toFloat(),
|
||||||
useCenter = false,
|
useCenter = false,
|
||||||
@ -102,7 +108,7 @@ fun FeatureStateSnapshot<XY>.generateSvg(
|
|||||||
offset.x + 5,
|
offset.x + 5,
|
||||||
offset.y - 5,
|
offset.y - 5,
|
||||||
java.awt.Font(null, PLAIN, 16),
|
java.awt.Font(null, PLAIN, 16),
|
||||||
feature.color
|
color
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user