2 Commits

4 changed files with 39 additions and 6 deletions

View File

@@ -66,6 +66,12 @@ fun App() {
pointTwo.second + (end.focus.longitude - start.focus.longitude).toDegrees()
false// returning false, because when we are dragging circle we don't want to drag map
} else true
},
onRelease = {
println("On drag ended $this")
},
onClick = {
println("On CLick $this")
}
)
) {

View File

@@ -3,11 +3,15 @@ import androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import center.sciprog.maps.scheme.*
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
@Composable
@Preview
@@ -20,6 +24,7 @@ fun App() {
1f
)
}
val scope = rememberCoroutineScope()
SchemeView(
@@ -33,9 +38,24 @@ fun App() {
) {
background(painterResource("middle-earth.jpg"))
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)
text(1132.0881 to 394.99127, "Ordruin",color = Color.Red)
text(1132.0881 to 394.99127, "Ordruin", color = Color.Red)
val hobbitId = circle(410.52737 to 868.7676)
scope.launch {
var t = 0.0
while (isActive) {
val x = 410.52737 + t * (1132.0881 - 410.52737)
val y = 868.7676 + t * (394.99127 - 868.7676)
circle(x to y, color = Color.Green, id = hobbitId)
delay(100)
t += 0.005
if (t >= 1.0) t = 0.0
}
}
}
}
}

View File

@@ -22,8 +22,9 @@ public data class MapViewConfig(
val onDrag: (start: MapViewPoint, end: MapViewPoint) -> Boolean = { _, _ -> true },
val onViewChange: MapViewPoint.() -> Unit = {},
val onSelect: (GmcBox) -> Unit = {},
val onRelease: MapViewPoint.() -> Unit = {},
val zoomOnSelect: Boolean = true,
val resetViewPoint: Boolean = false
val resetViewPoint: Boolean = false,
)
@Composable

View File

@@ -141,9 +141,6 @@ public actual fun MapView(
selectRect = null
}
} else {
val dragStart = change.position
val dpPos = DpOffset(dragStart.x.toDp(), dragStart.y.toDp())
config.onClick(MapViewPoint(dpPos.toGeodetic(), viewPoint.zoom))
drag(change.id) { dragChange ->
val dragAmount = dragChange.position - dragChange.previousPosition
val dpStart =
@@ -174,6 +171,15 @@ public actual fun MapView(
val newViewPoint = viewPoint.zoom(-change.scrollDelta.y.toDouble() * config.zoomSpeed, invariant)
config.onViewChange(newViewPoint)
viewPointInternal = newViewPoint
}.onPointerEvent(PointerEventType.Release) {
val change = it.changes.first()
val (xPos, yPos) = change.position
val dpOffset = DpOffset(xPos.toDp(), yPos.toDp())
config.onRelease(MapViewPoint(dpOffset.toGeodetic(), viewPoint.zoom))
}.onPointerEvent(PointerEventType.Press) {
val dragStart = it.changes.first().position
val dpPos = DpOffset(dragStart.x.toDp(), dragStart.y.toDp())
config.onClick(MapViewPoint(dpPos.toGeodetic(), viewPoint.zoom))
}.fillMaxSize()