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 pointLat by rememberSaveable { viewModel.rememberedPointLat }
|
||||||
var pointLon by rememberSaveable { viewModel.rememberedPointLon }
|
var pointLon by rememberSaveable { viewModel.rememberedPointLon }
|
||||||
var invokeHeightCalc by remember { mutableStateOf(false) }
|
var invokeHeightCalc by remember { mutableStateOf(false) }
|
||||||
|
val startTargetMeters = 64 * 1000 * 1000
|
||||||
Canvas(
|
Canvas(
|
||||||
modifier = modifier.fillMaxSize()
|
modifier = modifier.fillMaxSize()
|
||||||
.pointerInput(Unit) {
|
.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 centerTileX = (1 + (offsetX + halvedX) / TILE_SIZE).toDouble()
|
||||||
val centerTileY = (1 + (offsetY + halvedY) / TILE_SIZE).toDouble()
|
val centerTileY = (1 + (offsetY + halvedY) / TILE_SIZE).toDouble()
|
||||||
|
|
||||||
|
|
@ -239,19 +244,31 @@ fun MapCanvas(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cursor path
|
// Cursor path
|
||||||
val path = Path()
|
val cursorPath = Path()
|
||||||
path.moveTo(halvedX - crossRadius, halvedY)
|
with(cursorPath) {
|
||||||
path.lineTo(halvedX + crossRadius, halvedY)
|
moveTo(halvedX - crossRadius, halvedY)
|
||||||
path.moveTo(halvedX, halvedY - crossRadius)
|
lineTo(halvedX + crossRadius, halvedY)
|
||||||
path.lineTo(halvedX, halvedY + crossRadius)
|
moveTo(halvedX, halvedY - crossRadius)
|
||||||
path.close()
|
lineTo(halvedX, halvedY + crossRadius)
|
||||||
|
close()
|
||||||
|
}
|
||||||
|
|
||||||
// Cursor
|
// Cursor
|
||||||
drawPath(
|
drawPath(
|
||||||
path,
|
cursorPath,
|
||||||
Color.White,
|
Color.White,
|
||||||
style = Stroke(width = 6F)
|
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
|
// Info box
|
||||||
drawRect(
|
drawRect(
|
||||||
|
|
@ -277,15 +294,41 @@ fun MapCanvas(
|
||||||
topLeft = latLonOffset
|
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(
|
drawText(
|
||||||
textMeasurer = textMeasurer,
|
textMeasurer = textMeasurer,
|
||||||
text = buildAnnotatedString {
|
text = buildAnnotatedString {
|
||||||
|
withStyle(ParagraphStyle(textAlign = TextAlign.Center)) {
|
||||||
withStyle(SpanStyle(color = Color.White)) {
|
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