From 4b1516da292d30794cf7adb761623923bcc0721a Mon Sep 17 00:00:00 2001 From: PWRxPSYCHO Date: Thu, 24 Feb 2022 08:44:32 -0500 Subject: [PATCH 1/3] fixed lat,lon text on dialog window --- .../com/geeksville/mesh/ui/MapFragment.kt | 26 +++++-------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt index 75b6de300..bd34ad6c4 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt @@ -464,8 +464,8 @@ class MapFragment : ScreenFragment("Map"), Logging { R.drawable.baseline_location_on_white_24dp )!! .toBitmap() - pointLong = String.format("%.2f", it.longitude()) - pointLat = String.format("%.2f", it.latitude()) + pointLong = String.format("%.6f", it.longitude()) + pointLat = String.format("%.6f", it.latitude()) point = Point.fromLngLat(it.longitude(), it.latitude()) @@ -516,7 +516,7 @@ class MapFragment : ScreenFragment("Map"), Logging { private fun calculateCoordinate(degrees: Double, lat: Double, long: Double): Point { val deg = Math.toRadians(degrees) - val distancesInMeters = 16093.44// 10 miles + val distancesInMeters = 1609.344 * 10 // 1609.344 is 1 mile in meters -> multiplier will be user specified up to a max of 10 val radiusOfEarthInMeters = 6378137 val x = long + (180 / Math.PI) * (distancesInMeters / radiusOfEarthInMeters) * cos( @@ -527,18 +527,6 @@ class MapFragment : ScreenFragment("Map"), Logging { return Point.fromLngLat(x, y) } - /* - if (this::point.isInitialized) { - if (it.latitude() == point.latitude() && it.longitude() == point.longitude()) { - mapView?.getMapboxMap()?.getStyle()?.let { style -> - style.removeStyleImage(userPointImageId) - style.removeStyleSource(userTouchPositionId) - style.removeStyleLayer(userTouchLayerId) - } - } - } - */ - private fun updateStylePackDownloadProgress( progress: Long, max: Long, @@ -582,12 +570,12 @@ class MapFragment : ScreenFragment("Map"), Logging { if (this::pointLat.isInitialized && this::pointLat.isInitialized) { val latText = mapDownloadView.findViewById(R.id.longitude) - "Lat: $pointLong".also { + "Lon: $pointLong".also { latText.text = it View.VISIBLE.also { latText.visibility = View.VISIBLE } } val longText = mapDownloadView.findViewById(R.id.latitude) - "Long: $pointLat".also { + "Lat: $pointLat".also { longText.text = it View.VISIBLE.also { longText.visibility = View.VISIBLE } } @@ -646,9 +634,7 @@ class MapFragment : ScreenFragment("Map"), Logging { .center(point) .build(), MapAnimationOptions.mapAnimationOptions { duration(1000) }) //debug(userStyleURI) - it?.loadStyleUri(mapView?.getMapboxMap()?.getStyle()?.styleURI.toString()) { - - } + it?.loadStyleUri(mapView?.getMapboxMap()?.getStyle()?.styleURI.toString()) } // Open up Downloaded Region managers mapView?.annotations?.createCircleAnnotationManager()?.create( From da99cee937b664c79739b7655539d07230dda81c Mon Sep 17 00:00:00 2001 From: PWRxPSYCHO Date: Thu, 24 Feb 2022 08:51:27 -0500 Subject: [PATCH 2/3] Remove layers on download cancel --- .../com/geeksville/mesh/ui/MapFragment.kt | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt index bd34ad6c4..7663f1eb7 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt @@ -443,16 +443,6 @@ class MapFragment : ScreenFragment("Map"), Logging { // prepareCancelButton() } - -// private fun addViewAnnotation(point: Point) { -// viewAnnotationManager?.addViewAnnotation( -// resId = R.layout.user_icon_menu, -// options = viewAnnotationOptions { -// geometry(point) -// } -// ) -// } - /** * OnLongClick of the map set a position marker. * If a user long-clicks again, the position of the first marker will be updated @@ -516,7 +506,8 @@ class MapFragment : ScreenFragment("Map"), Logging { private fun calculateCoordinate(degrees: Double, lat: Double, long: Double): Point { val deg = Math.toRadians(degrees) - val distancesInMeters = 1609.344 * 10 // 1609.344 is 1 mile in meters -> multiplier will be user specified up to a max of 10 + val distancesInMeters = + 1609.344 * 10 // 1609.344 is 1 mile in meters -> multiplier will be user specified up to a max of 10 val radiusOfEarthInMeters = 6378137 val x = long + (180 / Math.PI) * (distancesInMeters / radiusOfEarthInMeters) * cos( @@ -647,6 +638,13 @@ class MapFragment : ScreenFragment("Map"), Logging { .setNegativeButton( R.string.cancel ) { dialog, _ -> + mapView?.getMapboxMap()?.getStyle { style -> + style.removeStyleLayer(lineLayerId) + style.removeStyleSource(boundingBoxId) + style.removeStyleLayer(userTouchLayerId) + style.removeStyleSource(userTouchPositionId) + style.removeStyleImage(userPointImageId) + } removeOfflineRegions() //TODO: Add to offline manager window dialog.cancel() } From b07eb344d810ea1a22291a7bd5ab7e7ba8dc88f5 Mon Sep 17 00:00:00 2001 From: PWRxPSYCHO Date: Thu, 24 Feb 2022 17:53:40 -0500 Subject: [PATCH 3/3] Added doc comment --- .../java/com/geeksville/mesh/ui/MapFragment.kt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt index 7663f1eb7..4bdfb9590 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt @@ -65,7 +65,6 @@ class MapFragment : ScreenFragment("Map"), Logging { } } - //TODO: Setup menu when creating region for offline maps (On long press set a point to center region, then click that point to bring up menu) //TODO: View Offline Regions (This will allow you to select the region and the map will zoom to it) //TODO: Manage Offline Regions (Allow you to edit the name, delete, & select region) //TODO: Update download animation @@ -80,7 +79,6 @@ class MapFragment : ScreenFragment("Map"), Logging { private lateinit var handler: Handler private lateinit var binding: MapViewBinding private lateinit var mapNotAllowedBinding: MapNotAllowedBinding - private lateinit var viewAnnotationManager: ViewAnnotationManager private lateinit var pointLat: String private lateinit var pointLong: String private lateinit var userStyleURI: String @@ -504,10 +502,17 @@ class MapFragment : ScreenFragment("Map"), Logging { return@OnMapLongClickListener true } + /** + * Find's coordinates (Lat,Lon) a specified distance from given (lat,lon) using degrees to determine direction + * @param degrees Angle + * @param lat latitude position + * @param long longitude position + * @return Point + */ private fun calculateCoordinate(degrees: Double, lat: Double, long: Double): Point { val deg = Math.toRadians(degrees) val distancesInMeters = - 1609.344 * 10 // 1609.344 is 1 mile in meters -> multiplier will be user specified up to a max of 10 + 1609.344 * 5 // 1609.344 is 1 mile in meters -> multiplier will be user specified up to a max of 10 val radiusOfEarthInMeters = 6378137 val x = long + (180 / Math.PI) * (distancesInMeters / radiusOfEarthInMeters) * cos( @@ -616,15 +621,12 @@ class MapFragment : ScreenFragment("Map"), Logging { } } .setNeutralButton("View Regions") { dialog, _ -> - - //OfflineSwitch.getInstance().isMapboxStackConnected = false mapView?.getMapboxMap().also { it?.flyTo( CameraOptions.Builder() .zoom(ZOOM) .center(point) .build(), MapAnimationOptions.mapAnimationOptions { duration(1000) }) - //debug(userStyleURI) it?.loadStyleUri(mapView?.getMapboxMap()?.getStyle()?.styleURI.toString()) } // Open up Downloaded Region managers @@ -634,7 +636,6 @@ class MapFragment : ScreenFragment("Map"), Logging { .withCircleColor(Color.RED) ) } - .setNegativeButton( R.string.cancel ) { dialog, _ ->