distance measurer
This commit is contained in:
parent
182f0b29b0
commit
049311ec9b
1 changed files with 54 additions and 11 deletions
|
|
@ -49,6 +49,7 @@ fun MapCanvas(
|
|||
var pointLat by rememberSaveable { viewModel.rememberedPointLat }
|
||||
var pointLon by rememberSaveable { viewModel.rememberedPointLon }
|
||||
var invokeHeightCalc by remember { mutableStateOf(false) }
|
||||
val startTargetMeters = 64 * 1000 * 1000
|
||||
Canvas(
|
||||
modifier = modifier.fillMaxSize()
|
||||
.pointerInput(Unit) {
|
||||
|
|
@ -93,6 +94,10 @@ fun MapCanvas(
|
|||
}
|
||||
}
|
||||
|
||||
val targetMeters = startTargetMeters shr level
|
||||
val targetPixels = (targetMeters).toFloat() / SphereMercator.scaledMetersPerPixel(level)
|
||||
val measurerHeight = 24F
|
||||
|
||||
val centerTileX = (1 + (offsetX + halvedX) / TILE_SIZE).toDouble()
|
||||
val centerTileY = (1 + (offsetY + halvedY) / TILE_SIZE).toDouble()
|
||||
|
||||
|
|
@ -239,19 +244,31 @@ fun MapCanvas(
|
|||
}
|
||||
|
||||
// Cursor path
|
||||
val path = Path()
|
||||
path.moveTo(halvedX - crossRadius, halvedY)
|
||||
path.lineTo(halvedX + crossRadius, halvedY)
|
||||
path.moveTo(halvedX, halvedY - crossRadius)
|
||||
path.lineTo(halvedX, halvedY + crossRadius)
|
||||
path.close()
|
||||
val cursorPath = Path()
|
||||
with(cursorPath) {
|
||||
moveTo(halvedX - crossRadius, halvedY)
|
||||
lineTo(halvedX + crossRadius, halvedY)
|
||||
moveTo(halvedX, halvedY - crossRadius)
|
||||
lineTo(halvedX, halvedY + crossRadius)
|
||||
close()
|
||||
}
|
||||
|
||||
// Cursor
|
||||
drawPath(
|
||||
path,
|
||||
cursorPath,
|
||||
Color.White,
|
||||
style = Stroke(width = 6F)
|
||||
)
|
||||
// Height under cursor
|
||||
drawText(
|
||||
textMeasurer = textMeasurer,
|
||||
text = buildAnnotatedString {
|
||||
withStyle(SpanStyle(color = Color.White)) {
|
||||
append("${KhmParser.getHeight(lon, lat, ctx)}m")
|
||||
}
|
||||
},
|
||||
topLeft = Offset(halvedX + crossRadius, halvedY + crossRadius)
|
||||
)
|
||||
|
||||
// Info box
|
||||
drawRect(
|
||||
|
|
@ -277,15 +294,41 @@ fun MapCanvas(
|
|||
topLeft = latLonOffset
|
||||
)
|
||||
|
||||
// Height under cursor
|
||||
// Distance measurer path
|
||||
val measurerPath = Path()
|
||||
with(measurerPath) {
|
||||
moveTo((halvedX - targetPixels).toFloat(), 8F)
|
||||
relativeLineTo(0F, measurerHeight)
|
||||
relativeMoveTo(targetPixels.toFloat() * 2F, 0F)
|
||||
relativeLineTo(0F, -measurerHeight)
|
||||
relativeMoveTo(0F, measurerHeight / 2F)
|
||||
relativeLineTo(-2F * targetPixels.toFloat(), 0F)
|
||||
close()
|
||||
}
|
||||
|
||||
// Distance measurer
|
||||
drawPath(
|
||||
measurerPath,
|
||||
Color.White,
|
||||
style = Stroke(width = 6F)
|
||||
)
|
||||
|
||||
// Distance measurer text
|
||||
drawText(
|
||||
textMeasurer = textMeasurer,
|
||||
text = buildAnnotatedString {
|
||||
withStyle(ParagraphStyle(textAlign = TextAlign.Center)) {
|
||||
withStyle(SpanStyle(color = Color.White)) {
|
||||
append("${KhmParser.getHeight(lon, lat, ctx)}m")
|
||||
val text = if (targetMeters >= 100000)
|
||||
"${targetMeters / 1000}km"
|
||||
else
|
||||
"${targetMeters}m"
|
||||
append(text)
|
||||
}
|
||||
}
|
||||
},
|
||||
topLeft = Offset(halvedX + crossRadius, halvedY + crossRadius)
|
||||
topLeft = Offset(targetPixels.toFloat() * 2F, measurerHeight),
|
||||
size = Size(targetPixels.toFloat() * 2F, 48F)
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue