Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/flutter--map' into flutter--map
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanMcGuire30 committed Nov 7, 2023
2 parents a2fd82b + e14f971 commit 99f98ae
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 34 deletions.
4 changes: 2 additions & 2 deletions lib/hardware_interface/test_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class TestHardwareInterface extends BaseHardwareInterface {

database.updateDatabase("random_1", random.nextDouble());

database.updateDatabase("rocket latitude", sin(i / 50)/100 + 42.37);
database.updateDatabase("rocket longitude", cos(i / 50)/100 -71.06);
database.updateDatabase("rocket latitude", sin(i / 50) / 100 + 42.37);
database.updateDatabase("rocket longitude", cos(i / 50) / 100 - 71.06);

database.updateDatabase("groundstation latitude", 42.361145);
database.updateDatabase("groundstation longitude", -71.0570803);
Expand Down
55 changes: 24 additions & 31 deletions lib/widgets/map_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,37 @@ import 'package:latlong2/latlong.dart';
import 'package:url_launcher/url_launcher.dart';
//import 'package:flutter_groundstation/widgets/map_widget.dart';

double LatLonToDistance(loc1, loc2){
var p = 0.017453292519943295;
var c = cos;
var a = 0.5 - c((loc2.latitude - loc1.latitude) * p)/2 +
c(loc1.latitude * p) * c(loc2.latitude * p) *
(1 - c((loc2.longitude - loc1.longitude) * p))/2;
return 12742 * asin(sqrt(a));
}
double LatLonToDistance(loc1, loc2) {
var p = 0.017453292519943295;
var c = cos;
var a = 0.5 - c((loc2.latitude - loc1.latitude) * p) / 2 + c(loc1.latitude * p) * c(loc2.latitude * p) * (1 - c((loc2.longitude - loc1.longitude) * p)) / 2;
return 12742 * asin(sqrt(a));
}

class MapWidget extends StatefulWidget {
const MapWidget({super.key});

@override
State<StatefulWidget> createState() => _MapWidgetState();
}

late List<LatLng> circles;


class _MapWidgetState extends BaseWidgetState<MapWidget> {

var groundstation_location = LatLng(42.361145, -71.0570803);
List<LatLng> rocket_path = [];
var groundstation_location = LatLng(42.361145, -71.0570803);
List<LatLng> rocket_path = [];
@override
Widget build(BuildContext context) {

var rocket_location = LatLng(getDatabaseValue("rocket latitude", 42.37), getDatabaseValue("rocket longitude", -71.06));
if (rocket_path.isEmpty || LatLonToDistance(rocket_location, rocket_path.last) > 0.5) {
rocket_path.add(rocket_location);
}

return FlutterMap(
options: MapOptions(
center: LatLng(groundstation_location.latitude, groundstation_location.longitude),
zoom: 10,
),

nonRotatedChildren: [
RichAttributionWidget(
attributions: [
Expand All @@ -65,7 +59,7 @@ List<LatLng> rocket_path = [];
urlTemplate: 'https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}',
//urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
userAgentPackageName: 'com.example.app',
),
),
PolylineLayer(
polylines: [
Polyline(
Expand All @@ -76,21 +70,20 @@ List<LatLng> rocket_path = [];
],
),
CircleLayer(
circles: [
CircleMarker(
point: LatLng(rocket_location.latitude, rocket_location.longitude),
radius: 5,
color: Color.fromARGB(255, 133, 2, 255),
),
CircleMarker(
point: LatLng(groundstation_location.latitude, groundstation_location.longitude),
radius: 5,
color: Color.fromARGB(255, 255, 154, 2),
)
],
),
circles: [
CircleMarker(
point: LatLng(rocket_location.latitude, rocket_location.longitude),
radius: 5,
color: Color.fromARGB(255, 133, 2, 255),
),
CircleMarker(
point: LatLng(groundstation_location.latitude, groundstation_location.longitude),
radius: 5,
color: Color.fromARGB(255, 255, 154, 2),
)
],
),
],
);
}
}

2 changes: 1 addition & 1 deletion lib/widgets/tabs/map_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ class MapTab extends StatelessWidget {
],
);
}
}
}

0 comments on commit 99f98ae

Please sign in to comment.