Skip to content

Commit

Permalink
use double for zoom/tilt/orientation, fix issues with rotation and ti…
Browse files Browse the repository at this point in the history
…lt interpreted as rad
  • Loading branch information
Helium314 committed Feb 22, 2024
1 parent cf04cb8 commit 5835ea1
Show file tree
Hide file tree
Showing 19 changed files with 57 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class NotesDownloader(

yield()

noteController.putAllForBBox(bbox, notes)
noteController.putAllForBBox(bbox, notes)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ abstract class AStreetSideSelectOverlayForm<I> : AbstractOverlayForm() {
}
}

override fun onMapOrientation(rotation: Float, tilt: Float) {
override fun onMapOrientation(rotation: Double, tilt: Double) {
streetSideSelect.onMapOrientation(rotation, tilt)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ abstract class AbstractOverlayForm :
protected val geometry: ElementGeometry
get() = _geometry ?: ElementPointGeometry(getDefaultMarkerPosition()!!)

private var initialMapRotation = 0f
private var initialMapTilt = 0f
private var initialMapRotation = 0.0
private var initialMapTilt = 0.0
override val elementKey: ElementKey? get() = element?.key

protected val metersPerPixel: Double? get() = listener?.metersPerPixel
Expand Down Expand Up @@ -171,8 +171,8 @@ abstract class AbstractOverlayForm :
element = args.getString(ARG_ELEMENT)?.let { Json.decodeFromString(it) }
_geometry = (savedInstanceState?.getString(ARG_GEOMETRY) ?: args.getString(ARG_GEOMETRY))
?.let { Json.decodeFromString(it) }
initialMapRotation = args.getFloat(ARG_MAP_ROTATION)
initialMapTilt = args.getFloat(ARG_MAP_TILT)
initialMapRotation = args.getDouble(ARG_MAP_ROTATION)
initialMapTilt = args.getDouble(ARG_MAP_TILT)
_countryInfo = null // reset lazy field

/* deliberately did not copy the mobile-country-code hack from AbstractQuestForm because
Expand Down Expand Up @@ -236,7 +236,7 @@ abstract class AbstractOverlayForm :
}
}

override fun onMapOrientation(rotation: Float, tilt: Float) {
override fun onMapOrientation(rotation: Double, tilt: Double) {
// default empty implementation
}

Expand Down Expand Up @@ -450,7 +450,7 @@ abstract class AbstractOverlayForm :
private const val ARG_MAP_ROTATION = "map_rotation"
private const val ARG_MAP_TILT = "map_tilt"

fun createArguments(overlay: Overlay, element: Element?, geometry: ElementGeometry?, rotation: Float, tilt: Float) = bundleOf(
fun createArguments(overlay: Overlay, element: Element?, geometry: ElementGeometry?, rotation: Double, tilt: Double) = bundleOf(
ARG_ELEMENT to element?.let { Json.encodeToString(it) },
ARG_GEOMETRY to geometry?.let { Json.encodeToString(it) },
ARG_OVERLAY to overlay.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ abstract class AStreetSideSelectForm<I, T> : AbstractOsmQuestForm<T>() {
checkIsFormComplete()
}

override fun onMapOrientation(rotation: Float, tilt: Float) {
override fun onMapOrientation(rotation: Double, tilt: Double) {
streetSideSelect.onMapOrientation(rotation, tilt)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ abstract class AbstractQuestForm :
override lateinit var questKey: QuestKey
protected lateinit var questType: QuestType
protected lateinit var geometry: ElementGeometry private set
private var initialMapRotation = 0f
private var initialMapTilt = 0f
private var initialMapRotation = 0.0
private var initialMapTilt = 0.0

// overridable by child classes
open val contentLayoutResId: Int? = null
Expand All @@ -102,8 +102,8 @@ abstract class AbstractQuestForm :
questKey = Json.decodeFromString(args.getString(ARG_QUEST_KEY)!!)
questType = questTypeRegistry.getByName(args.getString(ARG_QUESTTYPE)!!)!!
geometry = Json.decodeFromString(args.getString(ARG_GEOMETRY)!!)
initialMapRotation = args.getFloat(ARG_MAP_ROTATION)
initialMapTilt = args.getFloat(ARG_MAP_TILT)
initialMapRotation = args.getDouble(ARG_MAP_ROTATION)
initialMapTilt = args.getDouble(ARG_MAP_TILT)
_countryInfo = null // reset lazy field
}

Expand Down Expand Up @@ -202,7 +202,7 @@ abstract class AbstractQuestForm :

protected open fun isFormComplete(): Boolean = false

@AnyThread override fun onMapOrientation(rotation: Float, tilt: Float) {
@AnyThread override fun onMapOrientation(rotation: Double, tilt: Double) {
// default empty implementation
}

Expand All @@ -219,7 +219,7 @@ abstract class AbstractQuestForm :
private const val ARG_MAP_ROTATION = "map_rotation"
private const val ARG_MAP_TILT = "map_tilt"

fun createArguments(questKey: QuestKey, questType: QuestType, geometry: ElementGeometry, rotation: Float, tilt: Float) = bundleOf(
fun createArguments(questKey: QuestKey, questType: QuestType, geometry: ElementGeometry, rotation: Double, tilt: Double) = bundleOf(
ARG_QUEST_KEY to Json.encodeToString(questKey),
ARG_GEOMETRY to Json.encodeToString(geometry),
ARG_QUESTTYPE to questType.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class AddBicycleInclineForm : AImageListQuestForm<Incline, BicycleInclineAnswer>
imageSelector.cellLayoutId = R.layout.cell_icon_select_with_label_below
}

override fun onMapOrientation(rotation: Float, tilt: Float) {
mapRotation = (rotation * 180 / PI).toFloat()
override fun onMapOrientation(rotation: Double, tilt: Double) {
mapRotation = rotation.toFloat()
imageSelector.items = items
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class AddInclineForm : AImageListQuestForm<Incline, Incline>() {
imageSelector.cellLayoutId = R.layout.cell_icon_select_with_label_below
}

override fun onMapOrientation(rotation: Float, tilt: Float) {
mapRotation = (rotation * 180 / PI).toFloat()
override fun onMapOrientation(rotation: Double, tilt: Double) {
mapRotation = rotation.toFloat()
imageSelector.items = items
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ class AddLanesForm : AbstractOsmQuestForm<LanesAnswer>() {
}
}

@AnyThread override fun onMapOrientation(rotation: Float, tilt: Float) {
mapRotation = (rotation * 180 / PI).toFloat()
mapTilt = (tilt * 180 / PI).toFloat()
@AnyThread override fun onMapOrientation(rotation: Double, tilt: Double) {
mapRotation = rotation.toFloat()
mapTilt = tilt.toFloat()
updateStreetOrientation()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class AddOnewayForm : AImageListQuestForm<OnewayAnswer, OnewayAnswer>() {
imageSelector.cellLayoutId = R.layout.cell_icon_select_with_label_below
}

override fun onMapOrientation(rotation: Float, tilt: Float) {
mapRotation = (rotation * 180 / PI).toFloat()
override fun onMapOrientation(rotation: Double, tilt: Double) {
mapRotation = rotation.toFloat()
imageSelector.items = items
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class AddSuspectedOnewayForm : AbstractOsmQuestForm<SuspectedOnewayAnswer>() {
}
}

override fun onMapOrientation(rotation: Float, tilt: Float) {
mapRotation = (rotation * 180 / PI).toFloat()
override fun onMapOrientation(rotation: Double, tilt: Double) {
mapRotation = rotation.toFloat()
binding.onewayIcon.rotation = wayRotation + mapRotation
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ class MainActivity :
val data = intent.data ?: return
if ("geo" != data.scheme) return
val geo = parseGeoUri(data) ?: return
val zoom = if (geo.zoom == null || geo.zoom < 14) 18f else geo.zoom
val zoom = if (geo.zoom == null || geo.zoom < 14) 18.0 else geo.zoom
val pos = LatLon(geo.latitude, geo.longitude)
mainFragment?.setCameraPosition(pos, zoom.toFloat())
mainFragment?.setCameraPosition(pos, zoom)
}

public override fun onStart() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,11 @@ class MainFragment :
binding.gpsTrackingButton.isNavigation = mapFragment?.isNavigationMode ?: false
binding.stopTracksButton.isVisible = mapFragment?.isRecordingTracks ?: false
updateLocationPointerPin()
mapFragment?.cameraPosition?.zoom?.let { updateCreateButtonEnablement(it.toFloat()) }
mapFragment?.cameraPosition?.zoom?.let { updateCreateButtonEnablement(it) }
listener?.onMapInitialized()
}

override fun onMapIsChanging(position: LatLon, rotation: Float, tilt: Float, zoom: Float) {
override fun onMapIsChanging(position: LatLon, rotation: Double, tilt: Double, zoom: Double) {
// binding.compassView.rotation = (180 * rotation / PI).toFloat()
// binding.compassView.rotationX = (180 * tilt / PI).toFloat()

Expand All @@ -347,7 +347,7 @@ class MainFragment :
}
}

override fun onMapDidChange(position: LatLon, rotation: Float, tilt: Float, zoom: Float) { }
override fun onMapDidChange(position: LatLon, rotation: Double, tilt: Double, zoom: Double) { }

override fun onLongPress(x: Float, y: Float) {
val point = PointF(x, y)
Expand Down Expand Up @@ -771,8 +771,8 @@ class MainFragment :
binding.crosshairView.isGone = !isCreateNodeEnabled
}

private fun updateCreateButtonEnablement(zoom: Float) {
binding.createButton.isEnabled = zoom >= 18f
private fun updateCreateButtonEnablement(zoom: Double) {
binding.createButton.isEnabled = zoom >= 18.0
}

private fun setIsNavigationMode(navigation: Boolean) {
Expand Down Expand Up @@ -992,7 +992,7 @@ class MainFragment :
val camera = mapFragment.cameraPosition
val rotation = camera?.rotation ?: 0.0
val tilt = camera?.tilt ?: 0.0
val args = AbstractOverlayForm.createArguments(overlay, null, null, rotation.toFloat(), tilt.toFloat())
val args = AbstractOverlayForm.createArguments(overlay, null, null, rotation, tilt)
f.requireArguments().putAll(args)

showInBottomSheet(f)
Expand Down Expand Up @@ -1025,7 +1025,7 @@ class MainFragment :
val camera = mapFragment.cameraPosition
val rotation = camera?.rotation ?: 0.0
val tilt = camera?.tilt ?: 0.0
val args = AbstractOverlayForm.createArguments(overlay, element, geometry, rotation.toFloat(), tilt.toFloat())
val args = AbstractOverlayForm.createArguments(overlay, element, geometry, rotation, tilt)
f.requireArguments().putAll(args)

showInBottomSheet(f)
Expand Down Expand Up @@ -1059,7 +1059,7 @@ class MainFragment :
val camera = mapFragment.cameraPosition
val rotation = camera?.rotation ?: 0.0
val tilt = camera?.tilt ?: 0.0
val args = AbstractQuestForm.createArguments(quest.key, quest.type, quest.geometry, rotation.toFloat(), tilt.toFloat())
val args = AbstractQuestForm.createArguments(quest.key, quest.type, quest.geometry, rotation, tilt)
f.requireArguments().putAll(args)

if (quest is OsmQuest) {
Expand Down Expand Up @@ -1186,10 +1186,10 @@ class MainFragment :
return mapFragment?.cameraPosition
}

fun setCameraPosition(position: LatLon, zoom: Float) {
fun setCameraPosition(position: LatLon, zoom: Double) {
mapFragment?.isFollowingPosition = false
mapFragment?.isNavigationMode = false
mapFragment?.setInitialCameraPosition(ScCameraPosition(position, 0.0, 0.0, zoom.toDouble()))
mapFragment?.setInitialCameraPosition(ScCameraPosition(position, 0.0, 0.0, zoom))
setIsFollowingPosition(false)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package de.westnordost.streetcomplete.screens.main.bottom_sheet

interface IsMapOrientationAware {
fun onMapOrientation(rotation: Float, tilt: Float)
fun onMapOrientation(rotation: Double, tilt: Double)
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ open class LocationAwareMapFragment : MapFragment() {
centerCurrentPositionIfFollowing()
}

override fun onMapIsChanging(position: LatLon, rotation: Float, tilt: Float, zoom: Float) {
override fun onMapIsChanging(position: LatLon, rotation: Double, tilt: Double, zoom: Double) {
super.onMapIsChanging(position, rotation, tilt, zoom)
locationMapComponent?.currentMapZoom = zoom
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class MainMapFragment : LocationAwareMapFragment(), ShowsGeometryMarkers {
// enable offline stuff
// needs some file at server because for absolutely no reason you can't supply a local style (or even just tile url) for offline stuff
// see MapTilesDownloader
// moving to user position after auto-zoom from opening a quest does not center user (looks like it keeps the insets)
// moving to user position after auto-zoom from opening a quest does not center user (looks like it keeps the insets/padding)
// zoom very often is choppy, far not as smooth as tangram
// more quests make it a little worse, but most of it seems to be "natural"
// is it definitely a maplibre issue? or maybe some map change listener?
Expand Down Expand Up @@ -540,7 +540,7 @@ class MainMapFragment : LocationAwareMapFragment(), ShowsGeometryMarkers {
style.addLayerBelow(downloadedAreaLayer, "pins-layer")
}

override fun onMapIsChanging(position: LatLon, rotation: Float, tilt: Float, zoom: Float) {
override fun onMapIsChanging(position: LatLon, rotation: Double, tilt: Double, zoom: Double) {
super.onMapIsChanging(position, rotation, tilt, zoom)
questPinsManager?.onNewScreenPosition()
styleableOverlayManager?.onNewScreenPosition()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ open class MapFragment : Fragment() {
/** Called when the map has been completely initialized */
fun onMapInitialized()
/** Called during camera animation and while the map is being controlled by a user */
fun onMapIsChanging(position: LatLon, rotation: Float, tilt: Float, zoom: Float)
fun onMapIsChanging(position: LatLon, rotation: Double, tilt: Double, zoom: Double)
/** Called after camera animation or after the map was controlled by a user */
fun onMapDidChange(position: LatLon, rotation: Float, tilt: Float, zoom: Float)
fun onMapDidChange(position: LatLon, rotation: Double, tilt: Double, zoom: Double)
/** Called when the user begins to pan the map */
fun onPanBegin()
/** Called when the user long-presses the map */
Expand Down Expand Up @@ -223,15 +223,15 @@ open class MapFragment : Fragment() {
val camera = cameraPosition ?: return
if (camera == previousCameraPosition) return
previousCameraPosition = camera
onMapIsChanging(camera.position, camera.rotation.toFloat(), camera.tilt.toFloat(), camera.zoom.toFloat())
listener?.onMapIsChanging(camera.position, camera.rotation.toFloat(), camera.tilt.toFloat(), camera.zoom.toFloat())
onMapIsChanging(camera.position, camera.rotation, camera.tilt, camera.zoom)
listener?.onMapIsChanging(camera.position, camera.rotation, camera.tilt, camera.zoom)
}
override fun onMapDidChange() {
val camera = cameraPosition ?: return
if (camera == previousCameraPosition) return
previousCameraPosition = camera
onMapDidChange(camera.position, camera.rotation.toFloat(), camera.tilt.toFloat(), camera.zoom.toFloat())
listener?.onMapDidChange(camera.position, camera.rotation.toFloat(), camera.tilt.toFloat(), camera.zoom.toFloat())
onMapDidChange(camera.position, camera.rotation, camera.tilt, camera.zoom)
listener?.onMapDidChange(camera.position, camera.rotation, camera.tilt, camera.zoom)
}
})
}
Expand All @@ -248,9 +248,9 @@ open class MapFragment : Fragment() {

@CallSuper protected open suspend fun onBeforeLoadScene() {}

protected open fun onMapIsChanging(position: LatLon, rotation: Float, tilt: Float, zoom: Float) {}
protected open fun onMapIsChanging(position: LatLon, rotation: Double, tilt: Double, zoom: Double) {}

protected open fun onMapDidChange(position: LatLon, rotation: Float, tilt: Float, zoom: Float) {}
protected open fun onMapDidChange(position: LatLon, rotation: Double, tilt: Double, zoom: Double) {}

/* ---------------------- Overridable callbacks for map interaction ------------------------ */
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class CurrentLocationMapComponent(ctx: Context, mapStyle: Style, private val ctr
* but it needs to know when it changed. There is no specific event for that. Whenever the
* zoom changed, the marker showing the accuracy must be updated because the accuracy's marker
* size is calculated programmatically using the current zoom. */
var currentMapZoom: Float? = null
var currentMapZoom: Double? = null
set(value) {
if (field == value) return
field = value
Expand All @@ -79,6 +79,7 @@ class CurrentLocationMapComponent(ctx: Context, mapStyle: Style, private val ctr
delay(100)
}
delay(500) // just to be sure
// this is the maplibre location component, could be used instead most of the stuff in here
val options = LocationComponentOptions.builder(ctx)
.bearingDrawable(R.drawable.location_direction) // todo: not displayed
.gpsDrawable(R.drawable.location_dot) // todo: not displayed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class ShowQuestFormsActivity : BaseActivity(), AbstractOsmQuestForm.Listener {
val f = questType.createForm()
if (f.arguments == null) f.arguments = bundleOf()
f.requireArguments().putAll(
AbstractQuestForm.createArguments(quest.key, quest.type, geometry, 30.0f, 0.0f)
AbstractQuestForm.createArguments(quest.key, quest.type, geometry, 30.0, 0.0)
)
f.requireArguments().putAll(AbstractOsmQuestForm.createArguments(element))
f.hideOsmQuestController = object : HideOsmQuestController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ class StreetSideSelectWithLastAnswerButtonViewController<I>(

/* ------------------------------------ rotate view ----------------------------------------- */

fun onMapOrientation(rotation: Float, tilt: Float) {
puzzleView.streetRotation = offsetPuzzleRotation + (180 * rotation / PI).toFloat()
compassView.rotation = (180 * rotation / PI).toFloat()
compassView.rotationX = (180 * tilt / PI).toFloat()
fun onMapOrientation(rotation: Double, tilt: Double) {
puzzleView.streetRotation = offsetPuzzleRotation + rotation.toFloat()
compassView.rotation = rotation.toFloat()
compassView.rotationX = tilt.toFloat()
}

/* ------------------------------------------------------------------------------------------ */
Expand Down

0 comments on commit 5835ea1

Please sign in to comment.