Skip to content

Commit

Permalink
Fix measure bearing
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamza417 committed Aug 7, 2024
1 parent 0b07d0b commit 194cf7b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class MeasureMaps(context: Context, attrs: AttributeSet) : CustomMaps(context, a
private var isCompassRotation = true
private var lastZoom = 20F
private var lastTilt = 0F
private var lastBearing = 0F
private val incrementFactor = 2

private var polylineOptions: PolylineOptions? = null
Expand Down Expand Up @@ -274,22 +275,26 @@ class MeasureMaps(context: Context, attrs: AttributeSet) : CustomMaps(context, a

fun resetCamera(zoom: Float) {
if (location != null) {
moveMapCamera(LatLng(location!!.latitude, location!!.longitude), zoom, MeasurePreferences.getMapTilt())
moveMapCamera(
LatLng(location!!.latitude, location!!.longitude),
zoom,
MeasurePreferences.getMapTilt(),
MeasurePreferences.getMapBearing())
}
}

fun moveMapCamera(latLng: LatLng, zoom: Float, tilt: Float) {
fun moveMapCamera(latLng: LatLng, zoom: Float, tilt: Float, bearing: Float) {
if (googleMap.isNull() && latLng.isNull()) return

animateCamera(latLng, zoom, tilt)
animateCamera(latLng, zoom, tilt, bearing)

isWrapped = false
MeasurePreferences.setPolylinesWrapped(false)
}

fun wrapUnwrap() {
if (isWrapped) {
moveMapCamera(latLng!!, lastZoom, lastTilt)
moveMapCamera(latLng!!, lastZoom, lastTilt, lastBearing)
} else {
wrap(true)
}
Expand All @@ -299,8 +304,9 @@ class MeasureMaps(context: Context, attrs: AttributeSet) : CustomMaps(context, a
kotlin.runCatching {
clearAnimation()
latLng = googleMap?.cameraPosition?.target
lastZoom = MeasurePreferences.getMapZoom()
lastTilt = MeasurePreferences.getMapTilt()
lastZoom = googleMap?.cameraPosition?.zoom!!
lastTilt = googleMap?.cameraPosition?.tilt ?: 0F
lastBearing = googleMap?.cameraPosition?.bearing ?: 0F

val builder = LatLngBounds.Builder()
for (latLng in currentPolylines) {
Expand All @@ -326,7 +332,7 @@ class MeasureMaps(context: Context, attrs: AttributeSet) : CustomMaps(context, a

private fun unwrap() {
clearAnimation()
moveMapCamera(latLng!!, lastZoom, lastTilt)
moveMapCamera(latLng!!, lastZoom, lastTilt, lastBearing)
}

private fun updatePolylines(points: ArrayList<MeasurePoint>) {
Expand Down
3 changes: 2 additions & 1 deletion app/src/full/java/app/simple/positional/ui/panels/Measure.kt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ class Measure : ScopedFragment(), FloatingButtonStateCommunicator.FloatingButton
} else {
maps?.moveMapCamera(LatLng(location!!.latitude, location!!.longitude),
MeasurePreferences.getMapZoom(),
MeasurePreferences.getMapTilt())
MeasurePreferences.getMapTilt(),
MeasurePreferences.getMapBearing())
}
}
} else {
Expand Down

0 comments on commit 194cf7b

Please sign in to comment.