0.3.0 #23
@ -77,9 +77,12 @@ fun App() {
|
||||
|
||||
icon(pointOne, Icons.Filled.Home)
|
||||
|
||||
val marker1 = rectangle(55.744 to 38.614, size = DpSize(10.dp, 10.dp)).color(Color.Magenta)
|
||||
val marker2 = rectangle(55.8 to 38.5, size = DpSize(10.dp, 10.dp)).color(Color.Magenta)
|
||||
val marker3 = rectangle(56.0 to 38.5, size = DpSize(10.dp, 10.dp)).color(Color.Magenta)
|
||||
val marker1 = rectangle(55.744 to 38.614, size = DpSize(10.dp, 10.dp))
|
||||
.color(Color.Magenta)
|
||||
val marker2 = rectangle(55.8 to 38.5, size = DpSize(10.dp, 10.dp))
|
||||
.color(Color.Magenta)
|
||||
val marker3 = rectangle(56.0 to 38.5, size = DpSize(10.dp, 10.dp))
|
||||
.color(Color.Magenta)
|
||||
|
||||
draggableLine(marker1, marker2, id = "line 1").color(Color.Red).onClick {
|
||||
println("line 1 clicked")
|
||||
@ -103,13 +106,13 @@ fun App() {
|
||||
),
|
||||
)
|
||||
|
||||
points(
|
||||
points = listOf(
|
||||
55.744 to 38.614,
|
||||
55.8 to 38.5,
|
||||
56.0 to 38.5,
|
||||
)
|
||||
).pointSize(5f)
|
||||
// points(
|
||||
// points = listOf(
|
||||
// 55.744 to 38.614,
|
||||
// 55.8 to 38.5,
|
||||
// 56.0 to 38.5,
|
||||
// )
|
||||
// ).pointSize(5f)
|
||||
|
||||
// geodeticLine(Gmc.ofDegrees(40.7128, -74.0060), Gmc.ofDegrees(55.742465, 37.615812)).color(Color.Blue)
|
||||
// line(Gmc.ofDegrees(40.7128, -74.0060), Gmc.ofDegrees(55.742465, 37.615812))
|
||||
|
@ -6,9 +6,6 @@ import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.mutableStateMapOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.PathEffect
|
||||
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||
import androidx.compose.ui.graphics.drawscope.clipRect
|
||||
import androidx.compose.ui.graphics.toComposeImageBitmap
|
||||
import androidx.compose.ui.unit.IntOffset
|
||||
@ -147,5 +144,6 @@ public fun MapView(
|
||||
buildFeatures: FeatureGroup<Gmc>.() -> Unit = {},
|
||||
) {
|
||||
val featureState = FeatureGroup.remember(WebMercatorSpace, buildFeatures)
|
||||
MapView(mapTileProvider, config, featureState, initialViewPoint, initialRectangle, modifier)
|
||||
val computedRectangle = initialRectangle ?: featureState.getBoundingBox()
|
||||
MapView(mapTileProvider, config, featureState, initialViewPoint, computedRectangle, modifier)
|
||||
}
|
@ -29,7 +29,7 @@ public abstract class FeatureDrawScope<T : Any>(
|
||||
toCoordinates(this@toCoordinates, this@FeatureDrawScope)
|
||||
}
|
||||
|
||||
public fun T.toOffset(): Offset = with(state) {
|
||||
public open fun T.toOffset(): Offset = with(state) {
|
||||
toOffset(this@toOffset, this@FeatureDrawScope)
|
||||
}
|
||||
|
||||
@ -54,11 +54,16 @@ public class ComposeFeatureDrawScope<T : Any>(
|
||||
try {
|
||||
drawText(textMeasurer, text, position)
|
||||
} catch (ex: Exception) {
|
||||
KotlinLogging.logger("features").error(ex){"Failed to measure text"}
|
||||
logger.error(ex) { "Failed to measure text" }
|
||||
}
|
||||
}
|
||||
|
||||
override fun painterFor(feature: PainterFeature<T>): Painter = painterCache[feature] ?: error("Can't resolve painter for $feature")
|
||||
override fun painterFor(feature: PainterFeature<T>): Painter =
|
||||
painterCache[feature] ?: error("Can't resolve painter for $feature")
|
||||
|
||||
public companion object{
|
||||
private val logger = KotlinLogging.logger("ComposeFeatureDrawScope")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -21,9 +21,8 @@ import java.awt.Color as AWTColor
|
||||
public class SvgDrawScope(
|
||||
state: CanvasState<XY>,
|
||||
private val graphics: SVGGraphics2D,
|
||||
size: Size,
|
||||
private val painterCache: Map<PainterFeature<XY>, Painter>,
|
||||
private val defaultStrokeWidth: Float = 1f
|
||||
private val defaultStrokeWidth: Float = 1f,
|
||||
) : FeatureDrawScope<XY>(state) {
|
||||
|
||||
override val layoutDirection: LayoutDirection
|
||||
@ -480,6 +479,6 @@ public class SvgDrawScope(
|
||||
graphics.drawString(text, position.x, position.y)
|
||||
}
|
||||
|
||||
override val drawContext: DrawContext = SvgDrawContext(graphics, size)
|
||||
override val drawContext: DrawContext = SvgDrawContext(graphics, state.canvasSize.toSize())
|
||||
|
||||
}
|
@ -3,6 +3,8 @@ package center.sciprog.maps.svg
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.geometry.Size
|
||||
import androidx.compose.ui.graphics.painter.Painter
|
||||
import androidx.compose.ui.unit.DpSize
|
||||
import androidx.compose.ui.unit.dp
|
||||
import center.sciprog.maps.features.*
|
||||
import center.sciprog.maps.scheme.XY
|
||||
import center.sciprog.maps.scheme.XYCanvasState
|
||||
@ -154,14 +156,17 @@ public fun FeatureStateSnapshot<XY>.generateSvg(
|
||||
// }
|
||||
|
||||
val svgGraphics2D: SVGGraphics2D = SVGGraphics2D(width, height)
|
||||
val svgCanvasState: XYCanvasState = XYCanvasState(ViewConfig())
|
||||
val svgScope = SvgDrawScope(svgCanvasState, svgGraphics2D, Size(width.toFloat(), height.toFloat()), painterCache)
|
||||
val svgCanvasState: XYCanvasState = XYCanvasState(ViewConfig()).apply {
|
||||
this.viewPoint = viewPoint
|
||||
this.canvasSize = DpSize(width.dp, height.dp)
|
||||
}
|
||||
val svgScope = SvgDrawScope(svgCanvasState, svgGraphics2D, painterCache)
|
||||
|
||||
svgScope.apply {
|
||||
features.values.filter {
|
||||
viewPoint.zoom in it.zoomRange
|
||||
}.forEach { feature ->
|
||||
drawFeature(feature)
|
||||
features.values.sortedBy { it.z }
|
||||
.filter { state.viewPoint.zoom in it.zoomRange }
|
||||
.forEach { feature ->
|
||||
this@apply.drawFeature(feature)
|
||||
}
|
||||
}
|
||||
return svgGraphics2D.getSVGElement(id)
|
||||
@ -173,8 +178,6 @@ public fun FeatureStateSnapshot<XY>.exportToSvg(
|
||||
height: Double,
|
||||
path: java.nio.file.Path,
|
||||
) {
|
||||
|
||||
val svgString = generateSvg(viewPoint, width, height)
|
||||
|
||||
val svgString: String = generateSvg(viewPoint, width, height)
|
||||
SVGUtils.writeToSVG(path.toFile(), svgString)
|
||||
}
|
Loading…
Reference in New Issue
Block a user