Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .claude/settings.local.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"Bash(find:*)",
"Bash(for:*)",
"WebFetch(domain:github.com)",
"Bash(grep:*)"
"Bash(grep:*)",
"Bash(rm:*)"
],
"deny": [],
"ask": []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MainActivity : ComponentActivity() {

setContent {
DemoAppScreen(
// initPage = "marker-animation",
// initPage = "polyline-click",
initPage = "startup",
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import com.mapconductor.core.map.MapCameraPositionImpl
import com.mapconductor.core.map.MapViewState
import com.mapconductor.core.marker.DefaultIcon
import com.mapconductor.core.marker.MarkerState
import com.mapconductor.core.spherical.WGS84Geodesic.computeDistanceBetween
import com.mapconductor.core.spherical.calculatePositionAtDistance
import com.mapconductor.core.spherical.haversineDistance
import com.mapconductor.example.toast.ToastMessage
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
Expand Down Expand Up @@ -119,7 +119,7 @@ class CirclePageViewModelImpl :
get() = _edgeMarker.value

override val radiusMeters by derivedStateOf {
haversineDistance(circleCenter, _edgeMarker.value.position)
computeDistanceBetween(circleCenter, _edgeMarker.value.position)
}

override val circleState: CircleState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import com.mapconductor.core.map.OnMapLoadedHandler
import com.mapconductor.core.marker.ColorDefaultIcon
import com.mapconductor.core.marker.Marker
import com.mapconductor.core.marker.MarkerState
import com.mapconductor.core.spherical.WGS84Geodesic.computeDistanceBetween
import com.mapconductor.example.MapViewContainer
import android.annotation.SuppressLint
import android.content.ClipData
Expand Down Expand Up @@ -471,14 +472,14 @@ private fun createVisibleRegionInfo(visibleRegion: com.mapconductor.core.map.Vis
}

val widthKm =
calculateDistance(
bounds.southWest!!.latitude, bounds.southWest!!.longitude,
bounds.southWest!!.latitude, bounds.northEast!!.longitude,
computeDistanceBetween(
bounds.southWest!!,
GeoPointImpl(bounds.southWest!!.latitude, bounds.northEast!!.longitude),
)
val heightKm =
calculateDistance(
bounds.southWest!!.latitude, bounds.southWest!!.longitude,
bounds.northEast!!.latitude, bounds.southWest!!.longitude,
computeDistanceBetween(
bounds.southWest!!,
GeoPointImpl(bounds.northEast!!.latitude, bounds.southWest!!.longitude),
)

return VisibleRegionInfo(
Expand All @@ -489,20 +490,3 @@ private fun createVisibleRegionInfo(visibleRegion: com.mapconductor.core.map.Vis
heightKm = heightKm,
)
}

private fun calculateDistance(
lat1: Double,
lon1: Double,
lat2: Double,
lon2: Double,
): Double {
val earthRadius = 6371.0
val dLat = Math.toRadians(lat2 - lat1)
val dLon = Math.toRadians(lon2 - lon1)
val a =
kotlin.math.sin(dLat / 2) * kotlin.math.sin(dLat / 2) +
kotlin.math.cos(Math.toRadians(lat1)) * kotlin.math.cos(Math.toRadians(lat2)) *
kotlin.math.sin(dLon / 2) * kotlin.math.sin(dLon / 2)
val c = 2 * kotlin.math.atan2(kotlin.math.sqrt(a), kotlin.math.sqrt(1 - a))
return earthRadius * c
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package com.mapconductor.example.pages.map.visibleregion
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import com.mapconductor.core.features.GeoPointImpl
import com.mapconductor.core.map.MapCameraPosition
import com.mapconductor.core.map.MapViewState
import com.mapconductor.core.map.VisibleRegion
import com.mapconductor.core.spherical.WGS84Geodesic.computeDistanceBetween

interface VisibleRegionViewModel {
val mapViewState: State<MapViewState<*>?>
Expand Down Expand Up @@ -110,14 +112,14 @@ class VisibleRegionViewModelImpl :
val centerString = "Center: (${String.format("%.6f", centerLat)}, ${String.format("%.6f", centerLng)})"

val widthKm =
calculateDistance(
bounds.southWest!!.latitude, bounds.southWest!!.longitude,
bounds.southWest!!.latitude, bounds.northEast!!.longitude,
computeDistanceBetween(
bounds.southWest!!,
GeoPointImpl(bounds.southWest!!.latitude, bounds.northEast!!.longitude),
)
val heightKm =
calculateDistance(
bounds.southWest!!.latitude, bounds.southWest!!.longitude,
bounds.northEast!!.latitude, bounds.southWest!!.longitude,
computeDistanceBetween(
bounds.southWest!!,
GeoPointImpl(bounds.northEast!!.latitude, bounds.southWest!!.longitude),
)

return VisibleRegionInfo(
Expand All @@ -128,21 +130,4 @@ class VisibleRegionViewModelImpl :
heightKm = heightKm,
)
}

private fun calculateDistance(
lat1: Double,
lon1: Double,
lat2: Double,
lon2: Double,
): Double {
val earthRadius = 6371.0 // Earth's radius in kilometers
val dLat = Math.toRadians(lat2 - lat1)
val dLon = Math.toRadians(lon2 - lon1)
val a =
kotlin.math.sin(dLat / 2) * kotlin.math.sin(dLat / 2) +
kotlin.math.cos(Math.toRadians(lat1)) * kotlin.math.cos(Math.toRadians(lat2)) *
kotlin.math.sin(dLon / 2) * kotlin.math.sin(dLon / 2)
val c = 2 * kotlin.math.atan2(kotlin.math.sqrt(a), kotlin.math.sqrt(1 - a))
return earthRadius * c
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,9 @@ import com.mapconductor.arcgis.ArcGISMapView
import com.mapconductor.arcgis.rememberArcGISMapViewState
import com.mapconductor.core.features.GeoPointImpl
import com.mapconductor.core.map.MapCameraPositionImpl
import com.mapconductor.core.spherical.WGS84Geodesic.computeDistanceBetween
import com.mapconductor.googlemaps.GoogleMapsView
import com.mapconductor.googlemaps.rememberGoogleMapViewState
import kotlin.math.atan2
import kotlin.math.cos
import kotlin.math.sin
import kotlin.math.sqrt
import android.annotation.SuppressLint

@SuppressLint("DefaultLocale")
Expand Down Expand Up @@ -583,14 +580,14 @@ private fun createVisibleRegionInfo(visibleRegion: com.mapconductor.core.map.Vis
}

val widthKm =
calculateDistance(
bounds.southWest!!.latitude, bounds.southWest!!.longitude,
bounds.southWest!!.latitude, bounds.northEast!!.longitude,
computeDistanceBetween(
bounds.southWest!!,
GeoPointImpl(bounds.southWest!!.latitude, bounds.northEast!!.longitude),
)
val heightKm =
calculateDistance(
bounds.southWest!!.latitude, bounds.southWest!!.longitude,
bounds.northEast!!.latitude, bounds.southWest!!.longitude,
computeDistanceBetween(
bounds.southWest!!,
GeoPointImpl(bounds.northEast!!.latitude, bounds.southWest!!.longitude),
)

return VisibleRegionInfo(
Expand All @@ -601,20 +598,3 @@ private fun createVisibleRegionInfo(visibleRegion: com.mapconductor.core.map.Vis
heightKm = heightKm,
)
}

private fun calculateDistance(
lat1: Double,
lon1: Double,
lat2: Double,
lon2: Double,
): Double {
val earthRadius = 6371.0
val dLat = Math.toRadians(lat2 - lat1)
val dLon = Math.toRadians(lon2 - lon1)
val a =
sin(dLat / 2) * sin(dLat / 2) +
cos(Math.toRadians(lat1)) * cos(Math.toRadians(lat2)) *
sin(dLon / 2) * sin(dLon / 2)
val c = 2 * atan2(sqrt(a), sqrt(1 - a))
return earthRadius * c
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.mapconductor.example.pages.polyline

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import com.mapconductor.core.map.MapViewState
import com.mapconductor.core.marker.Marker
import com.mapconductor.core.marker.MarkerState
Expand All @@ -26,6 +27,13 @@ fun PolylineClickMapComponent(
) {
// Polyline
Polyline(polylineState)
Polyline(
polylineState.copy(
id = "${polylineState.id}-straight",
geodesic = false,
strokeColor = Color.Blue,
),
)

// Waypoint markers
markers.forEach { marker ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fun PolylineClickMapPage(onToggleSidebar: () -> Unit = {}) {
end = paddingValues.calculateEndPadding(LayoutDirection.Ltr) + 16.dp,
),
) {
Text("Tap on the curved polyline")
Text("Tap on the curved polyline. A marker would be placed on the tapped polyline.")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import androidx.lifecycle.ViewModel
import com.mapconductor.core.features.GeoPointImpl
import com.mapconductor.core.map.MapCameraPositionImpl
import com.mapconductor.core.map.MapViewState
import com.mapconductor.core.marker.MarkerAnimation
import com.mapconductor.core.marker.DefaultIcon
import com.mapconductor.core.marker.MarkerState
import com.mapconductor.core.polyline.PolylineEvent
import com.mapconductor.core.polyline.PolylineState
Expand Down Expand Up @@ -65,6 +65,7 @@ class PolylineClickPageViewModelImpl :
override val mapViewState: StateFlow<MapViewState<*>?> = _mapViewState.asStateFlow()

override fun onMapViewChanged(state: MapViewState<*>) {
_markers.value = emptyList<MarkerState>()
mapViewState.value?.cameraPosition?.value?.let {
state.moveCameraTo(it)
}
Expand All @@ -75,7 +76,10 @@ class PolylineClickPageViewModelImpl :
_markers.value = _markers.value +
MarkerState(
position = clicked.clicked,
animation = MarkerAnimation.Drop,
icon =
DefaultIcon(
fillColor = clicked.state.strokeColor,
),
)
}

Expand Down
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ ktLint = "13.1.0"
uiToolingPreviewAndroid = "1.9.1"
uiToolingPreview = "1.9.1"
uiTooling = "1.9.1"
geographiclib = "2.1"

[libraries]
# Android 基本
Expand Down Expand Up @@ -84,6 +85,8 @@ androidx-compose-ui-tooling-preview-android = { group = "androidx.compose.ui", n
androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview", version.ref = "uiToolingPreview" }
androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling", version.ref = "uiTooling" }

net-sf-geographiclib = { group = "net.sf.geographiclib", name="GeographicLib-Java", version.ref="geographiclib"}

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
Expand Down
1 change: 1 addition & 0 deletions mapconductor-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ dependencies {
implementation(libs.androidx.ui.tooling.preview)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.foundation)
implementation(libs.net.sf.geographiclib)

// Core dependencies - use api to avoid version conflicts
api(libs.androidx.core.ktx)
Expand Down
Loading