From 71724a6fd22d2b648d9873247c9ffa6092e07fbd Mon Sep 17 00:00:00 2001 From: PWRxPSYCHO Date: Tue, 8 Mar 2022 13:49:22 -0500 Subject: [PATCH] Cleaning up some code --- .../java/com/geeksville/mesh/ui/MapFragment.kt | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 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 f925615c4..e18943566 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt @@ -1,7 +1,6 @@ package com.geeksville.mesh.ui import android.app.AlertDialog -import android.content.DialogInterface import android.graphics.Color import android.os.Bundle import android.os.Handler @@ -39,7 +38,6 @@ import com.mapbox.maps.extension.style.sources.generated.GeoJsonSource import com.mapbox.maps.extension.style.sources.generated.geoJsonSource import com.mapbox.maps.plugin.animation.MapAnimationOptions import com.mapbox.maps.plugin.animation.flyTo -import com.mapbox.maps.plugin.gestures.OnMapClickListener import com.mapbox.maps.plugin.gestures.OnMapLongClickListener import com.mapbox.maps.plugin.gestures.gestures import dagger.hilt.android.AndroidEntryPoint @@ -248,7 +246,6 @@ class MapFragment : ScreenFragment("Map"), Logging { // Note this will not remove the downloaded style pack, instead, it will just mark the resources // not a part of the existing style pack. The resources still exists as disk cache. offlineManager.removeStylePack(mapView?.getMapboxMap()?.getStyle()?.styleURI.toString()) - MapboxMap.clearData(resourceOptions) { it.error?.let { error -> debug(error) @@ -454,10 +451,12 @@ class MapFragment : ScreenFragment("Map"), Logging { 5 miles NE,NW,SE,SW from user center point. 25 Sq Mile Region */ + //____________________________________________________________________________________________ val topRight = calculateCoordinate(45.0, point?.latitude()!!, point?.longitude()!!) val topLeft = calculateCoordinate(135.0, point?.latitude()!!, point?.longitude()!!) val bottomLeft = calculateCoordinate(225.0, point?.latitude()!!, point?.longitude()!!) val bottomRight = calculateCoordinate(315.0, point?.latitude()!!, point?.longitude()!!) + //____________________________________________________________________________________________ val pointList = listOf(topRight, topLeft, bottomLeft, bottomRight, topRight) @@ -505,18 +504,18 @@ class MapFragment : ScreenFragment("Map"), Logging { /** * 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 + * @param degrees degree of desired position from current position. (center point is 0,0 and desired point, top right corner, is 45 degrees from 0,0) + * @param lat latitude position (current position lat) + * @param lon longitude position (current position lon) * @return Point */ - private fun calculateCoordinate(degrees: Double, lat: Double, long: Double): Point { + private fun calculateCoordinate(degrees: Double, lat: Double, lon: Double): Point { val deg = Math.toRadians(degrees) val distancesInMeters = 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( + lon + (180 / Math.PI) * (distancesInMeters / radiusOfEarthInMeters) * cos( deg ) val y = @@ -591,6 +590,9 @@ class MapFragment : ScreenFragment("Map"), Logging { .build(), MapAnimationOptions.mapAnimationOptions { duration(1000) }) if (userStyleURI != null) { it?.loadStyleUri(userStyleURI.toString()) + it?.getStyle().also { style -> + //TODO: Add box for downloaded region + } } else { it?.getStyle().also { style -> style?.removeStyleImage(userPointImageId)