Amenities GeoUtils
This commit is contained in:
@@ -26,7 +26,7 @@ import com.kouros.navigation.data.Constants.MAXIMAL_ROUTE_DEVIATION
|
||||
import com.kouros.navigation.data.Constants.MAXIMAL_SNAP_CORRECTION
|
||||
import com.kouros.navigation.data.Constants.TAG
|
||||
import com.kouros.navigation.data.ObjectBox
|
||||
import com.kouros.navigation.utils.NavigationUtils.snapLocation
|
||||
import com.kouros.navigation.utils.GeoUtils.snapLocation
|
||||
|
||||
class NavigationSession : Session(), NavigationScreen.Listener {
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ import com.kouros.navigation.data.Constants
|
||||
import com.kouros.navigation.data.ObjectBox
|
||||
import com.kouros.navigation.model.RouteModel
|
||||
import com.kouros.navigation.utils.bearing
|
||||
import com.kouros.navigation.utils.calcTilt
|
||||
import com.kouros.navigation.utils.calculateZoom
|
||||
import com.kouros.navigation.utils.duration
|
||||
import com.kouros.navigation.utils.location
|
||||
@@ -188,36 +189,17 @@ class SurfaceRenderer(
|
||||
) {
|
||||
val cameraDuration =
|
||||
duration(viewStyle == ViewStyle.PREVIEW, position!!.bearing, lastBearing)
|
||||
var bearing = position.bearing
|
||||
var zoom = position.zoom
|
||||
var target = position.target
|
||||
var localTilt = tilt
|
||||
val currentSpeed: Float? by speed.observeAsState()
|
||||
when (viewStyle) {
|
||||
ViewStyle.VIEW -> {
|
||||
DrawImage(paddingValues, currentSpeed, width, height)
|
||||
}
|
||||
|
||||
ViewStyle.PREVIEW -> {
|
||||
bearing = 0.0
|
||||
zoom = previewZoom(previewDistance)
|
||||
target = Position(centerLocation.longitude, centerLocation.latitude)
|
||||
localTilt = 0.0
|
||||
}
|
||||
|
||||
else -> {
|
||||
bearing = 0.0
|
||||
localTilt = 0.0
|
||||
zoom = 12.0
|
||||
}
|
||||
val currentSpeed: Float? by speed.observeAsState()
|
||||
if (viewStyle == ViewStyle.VIEW) {
|
||||
DrawImage(paddingValues, currentSpeed, width, height)
|
||||
}
|
||||
LaunchedEffect(position, viewStyle) {
|
||||
cameraState.animateTo(
|
||||
finalPosition = CameraPosition(
|
||||
bearing = bearing,
|
||||
zoom = zoom,
|
||||
target = target,
|
||||
tilt = localTilt,
|
||||
bearing = position.bearing,
|
||||
zoom = position.zoom,
|
||||
target = position.target,
|
||||
tilt = tilt,
|
||||
padding = paddingValues
|
||||
),
|
||||
duration = cameraDuration
|
||||
@@ -235,21 +217,15 @@ class SurfaceRenderer(
|
||||
/** Handles the map zoom-in and zoom-out events. */
|
||||
fun handleScale(zoomSign: Int) {
|
||||
synchronized(this) {
|
||||
viewStyle = ViewStyle.PAN_VIEW
|
||||
if (viewStyle == ViewStyle.VIEW) {
|
||||
viewStyle = ViewStyle.PAN_VIEW
|
||||
}
|
||||
val newZoom = if (zoomSign < 0) {
|
||||
cameraPosition.value!!.zoom - 1.0
|
||||
} else {
|
||||
cameraPosition.value!!.zoom + 1.0
|
||||
}
|
||||
tilt = if (newZoom < 13) {
|
||||
0.0
|
||||
} else {
|
||||
if (tilt == 0.0) {
|
||||
55.0
|
||||
} else {
|
||||
tilt
|
||||
}
|
||||
}
|
||||
tilt = calcTilt(newZoom, tilt)
|
||||
updateCameraPosition(
|
||||
cameraPosition.value!!.bearing,
|
||||
newZoom,
|
||||
|
||||
@@ -112,7 +112,6 @@ fun MapLibre(
|
||||
@Composable
|
||||
fun RouteLayer(routeData: String?, viewStyle: ViewStyle) {
|
||||
if (routeData != null && routeData.isNotEmpty()) {
|
||||
println(routeData)
|
||||
val routes = rememberGeoJsonSource(GeoJsonData.JsonString(routeData))
|
||||
if (viewStyle == ViewStyle.VIEW) {
|
||||
LineLayer(
|
||||
@@ -149,10 +148,10 @@ fun RouteLayer(routeData: String?, viewStyle: ViewStyle) {
|
||||
source = routes,
|
||||
// Convert a drawable resource to a MapLibre image
|
||||
// drawAsSdf = true allows us to tint the image programmatically
|
||||
iconImage = image(painterResource(R.drawable.ic_place_white_24dp), drawAsSdf = true),
|
||||
iconImage = image(painterResource(com.kouros.android.cars.carappservice.R.drawable.ev_station_24px), drawAsSdf = true),
|
||||
// Now we can apply any color we want!
|
||||
iconColor = const(Color.Blue),
|
||||
iconSize = const(1.5f)
|
||||
iconColor = const(Color.Red),
|
||||
iconSize = const(5.0f)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -283,7 +282,7 @@ fun getPaddingValues(height: Int, viewStyle: ViewStyle): PaddingValues {
|
||||
return when (viewStyle) {
|
||||
ViewStyle.VIEW -> PaddingValues(start = 50.dp, top = distanceFromTop(height).dp)
|
||||
ViewStyle.PREVIEW -> PaddingValues(start = 150.dp, bottom = 0.dp)
|
||||
else -> PaddingValues(start = 450.dp, bottom = 0.dp)
|
||||
else -> PaddingValues(start = 250.dp, bottom = 0.dp)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ class CategoriesScreen(
|
||||
|
||||
val header = Header.Builder()
|
||||
.setStartHeaderAction(Action.BACK)
|
||||
.setTitle("title")
|
||||
.setTitle(carContext.getString(R.string.category_title))
|
||||
.build()
|
||||
|
||||
return ListTemplate.Builder()
|
||||
|
||||
@@ -23,11 +23,10 @@ import androidx.lifecycle.Observer
|
||||
import com.kouros.data.R
|
||||
import com.kouros.navigation.car.SurfaceRenderer
|
||||
import com.kouros.navigation.car.navigation.NavigationMessage
|
||||
import com.kouros.navigation.data.Constants.homeLocation
|
||||
import com.kouros.navigation.data.NavigationRepository
|
||||
import com.kouros.navigation.data.overpass.Elements
|
||||
import com.kouros.navigation.model.ViewModel
|
||||
import com.kouros.navigation.utils.NavigationUtils.createGeoJson
|
||||
import com.kouros.navigation.utils.GeoUtils.createPointCollection
|
||||
import com.kouros.navigation.utils.location
|
||||
import kotlin.math.min
|
||||
|
||||
@@ -50,11 +49,10 @@ class CategoryScreen(
|
||||
loc.longitude = it.lon!!
|
||||
loc.latitude = it.lat!!
|
||||
}
|
||||
if (coordinates.isEmpty())
|
||||
coordinates.add(listOf(location.longitude, location.latitude))
|
||||
coordinates.add(listOf(it.lon!!, it.lat!!))
|
||||
}
|
||||
if (elements.isNotEmpty()) {
|
||||
val route = createGeoJson("Point", coordinates)
|
||||
val route = createPointCollection(coordinates)
|
||||
surfaceRenderer.setCategories(loc, route)
|
||||
invalidate()
|
||||
}
|
||||
@@ -106,7 +104,6 @@ class CategoryScreen(
|
||||
.setStartHeaderAction(Action.BACK)
|
||||
.setTitle(carContext.getString(R.string.charging_station))
|
||||
.build()
|
||||
|
||||
val builder = MapWithContentTemplate.Builder()
|
||||
.setContentTemplate(
|
||||
ListTemplate.Builder()
|
||||
|
||||
Reference in New Issue
Block a user