From c1d74ab227f5a1996f9b68a5687acdea5ba04a17 Mon Sep 17 00:00:00 2001 From: Remy Moll Date: Sat, 1 Jun 2024 19:58:25 +0200 Subject: [PATCH] use structs to draw custom map pointers --- .vscode/launch.json | 28 ++++++++ frontend/lib/layout.dart | 8 +-- frontend/lib/modules/landmark_card.dart | 2 +- frontend/lib/modules/map.dart | 96 +++++++------------------ frontend/lib/pages/profile.dart | 11 +-- frontend/lib/utils/get_landmarks.dart | 10 +-- frontend/pubspec.lock | 40 ----------- frontend/pubspec.yaml | 2 - frontend/web/index.html | 2 +- 9 files changed, 71 insertions(+), 128 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..71f1c8d --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,28 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "frontend", + "cwd": "frontend", + "request": "launch", + "type": "dart" + }, + { + "name": "frontend (profile mode)", + "cwd": "frontend", + "request": "launch", + "type": "dart", + "flutterMode": "profile" + }, + { + "name": "frontend (release mode)", + "cwd": "frontend", + "request": "launch", + "type": "dart", + "flutterMode": "release" + }, + ] +} \ No newline at end of file diff --git a/frontend/lib/layout.dart b/frontend/lib/layout.dart index 1c7a1be..4d2d85f 100644 --- a/frontend/lib/layout.dart +++ b/frontend/lib/layout.dart @@ -46,7 +46,8 @@ class _BasePageState extends State { child: const Text('The fanciest navigation!'), ), ListTile( - title: const Text('Home'), + title: const Text('Start'), + leading: const Icon(Icons.map), selected: _selectedIndex == 0, onTap: () { // Update the state of the app @@ -57,7 +58,8 @@ class _BasePageState extends State { }, ), ListTile( - title: const Text('Business'), + title: const Text('How to use'), + leading: Icon(Icons.help), selected: _selectedIndex == 1, onTap: () { // Update the state of the app @@ -68,8 +70,6 @@ class _BasePageState extends State { Navigator.pop(context); }, ), - // add a whitespace so that the settings are at the bottom - const Divider(), ListTile( title: const Text('Settings'), diff --git a/frontend/lib/modules/landmark_card.dart b/frontend/lib/modules/landmark_card.dart index 78bf280..8b42b7a 100644 --- a/frontend/lib/modules/landmark_card.dart +++ b/frontend/lib/modules/landmark_card.dart @@ -66,7 +66,7 @@ class _LandmarkCardState extends State { // alignment: Alignment.topRight, // child: Icon(Icons.push_pin, color: theme.primaryColor), // ), - ], + ], ), ); } diff --git a/frontend/lib/modules/map.dart b/frontend/lib/modules/map.dart index 8f88489..341d6cd 100644 --- a/frontend/lib/modules/map.dart +++ b/frontend/lib/modules/map.dart @@ -1,4 +1,5 @@ import 'package:fast_network_navigation/structs/landmark.dart'; +import 'package:fast_network_navigation/utils/get_landmarks.dart'; import 'package:flutter/material.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; @@ -10,33 +11,36 @@ class MapWidget extends StatefulWidget { class _MapWidgetState extends State { late GoogleMapController mapController; // coordinates of Paris - final LatLng _center = const LatLng(48.8566, 2.3522); + CameraPosition _cameraPosition = CameraPosition( + target: LatLng(48.8566, 2.3522), + zoom: 11.0, + ); + Set markers = {}; + void _onMapCreated(GoogleMapController controller) { mapController = controller; - addLandmarks(); + drawLandmarks(); } + + void _onCameraIdle() { - // print(mapController.getLatLng()); + // print(mapController.getLatLng(ScreenCoordinate(x: 0, y: 0))); } - void addLandmarks() { - // // adds a marker for each landmark - // List landmarks = [ - // Landmark(name: "Eiffel Tower", location: [48.8584, 2.2945], type: LandmarkType(name: "Type 1")), - // Landmark(name: "Louvre Museum", location: [48.8606, 2.3376], type: LandmarkType(name: "Type 1")), - // Landmark(name: "Notre-Dame Cathedral", location: [48.8529, 2.3499], type: LandmarkType(name: "Type 1")), - // Landmark(name: "Arc de Triomphe", location: [48.8738, 2.2950], type: LandmarkType(name: "Type 1")), - // Landmark(name: "Palace of Versailles", location: [48.8014, 2.1301], type: LandmarkType(name: "Type 1")), - // ]; - // for (Landmark landmark in landmarks) { - // mapController. - // mapController.addMarker(MarkerOptions( - // position: LatLng(landmark.location[0], landmark.location[1]), - // infoWindowText: InfoWindowText(landmark.name, landmark.type.name), - // )); - // } + void drawLandmarks() async { + // (re)draws landmarks on the map + List landmarks = await fetchLandmarks(); + setState(() { + for (Landmark landmark in landmarks) { + markers.add(Marker( + markerId: MarkerId(landmark.name), + position: LatLng(landmark.location[0], landmark.location[1]), + infoWindow: InfoWindow(title: landmark.name, snippet: landmark.type.name), + )); + } + }); } @@ -44,61 +48,11 @@ class _MapWidgetState extends State { Widget build(BuildContext context) { return GoogleMap( onMapCreated: _onMapCreated, - initialCameraPosition: CameraPosition( - target: _center, - zoom: 11.0, - ), + initialCameraPosition: _cameraPosition, onCameraIdle: _onCameraIdle, // onLongPress: , - // markers: #, + markers: markers, ); } } - - - // GeoCode geoCode = GeoCode(); - // String _currentCityName = "..."; - // final Debounce _debounce = Debounce(Duration(seconds: 3)); - - // final LatLng _center = const LatLng(45.521563, -122.677433); - // late GoogleMapController mapController; - - // void _onMapCreated(GoogleMapController controller) { - // mapController = controller; - // } - - // // void _setCurrentCityName() async { - // if (mapController.camera.zoom < 9) { - // return; // Don't bother if the view is too wide - // } - // var currentCoordinates = mapController.camera.center; - // String? city; - - // try{ - // List placemarks = await placemarkFromCoordinates(currentCoordinates.latitude, currentCoordinates.longitude); - // city = placemarks[0].locality.toString(); - // } catch (e) { - // debugPrint("Error: $e"); - // try { - // Address address = await geoCode.reverseGeocoding(latitude: currentCoordinates.latitude, longitude: currentCoordinates.longitude); - - // if (address.city == null || address.city.toString().contains("Throttled!")){ - // throw Exception("Probably rate limited"); - // } - // city = address.city.toString(); - // } catch (e) { - // debugPrint("Error: $e"); - - // } - // } - // if (city != null) { - // setState(() { - // _currentCityName = city!; - // }); - // } else { - // _debounce(() async {_setCurrentCityName();}); - // } - // } - - \ No newline at end of file diff --git a/frontend/lib/pages/profile.dart b/frontend/lib/pages/profile.dart index e8beb08..1133940 100644 --- a/frontend/lib/pages/profile.dart +++ b/frontend/lib/pages/profile.dart @@ -24,11 +24,14 @@ class _ProfilePageState extends State { child: Text('Curious traveler', style: TextStyle(fontSize: 24)) ), - Padding( - padding: EdgeInsets.all(10), - ), + Padding(padding: EdgeInsets.all(10)), + Divider(indent: 25, endIndent: 25), + Padding(padding: EdgeInsets.all(10)), - Text('Please rate your preferences for the following activities:'), + Padding( + padding: EdgeInsets.only(left: 10, right: 10, top: 0, bottom: 10), + child: Text('Please rate your personal preferences so that we can taylor your experience.', style: TextStyle(fontSize: 20), ) + ), // Now the sliders ImportanceSliders() diff --git a/frontend/lib/utils/get_landmarks.dart b/frontend/lib/utils/get_landmarks.dart index c538b0f..3c47728 100644 --- a/frontend/lib/utils/get_landmarks.dart +++ b/frontend/lib/utils/get_landmarks.dart @@ -10,11 +10,11 @@ Future> fetchLandmarks() async { // If the server did return a 200 OK response, // then parse the JSON. List landmarks = [ - Landmark(name: "Landmark 1", location: [0, 0], type: LandmarkType(name: "Type 1")), - Landmark(name: "Landmark 2", location: [0, 0], type: LandmarkType(name: "Type 2")), - Landmark(name: "Landmark 3", location: [0, 0], type: LandmarkType(name: "Type 3")), - Landmark(name: "Landmark 4", location: [0, 0], type: LandmarkType(name: "Type 4")), - Landmark(name: "Landmark 5", location: [0, 0], type: LandmarkType(name: "Type 5")), + Landmark(name: "Landmark 1", location: [48.85, 2.35], type: LandmarkType(name: "Type 1")), + Landmark(name: "Landmark 2", location: [48.86, 2.36], type: LandmarkType(name: "Type 2")), + Landmark(name: "Landmark 3", location: [48.75, 2.3], type: LandmarkType(name: "Type 3")), + Landmark(name: "Landmark 4", location: [48.9, 2.4], type: LandmarkType(name: "Type 4")), + Landmark(name: "Landmark 5", location: [48.91, 2.45], type: LandmarkType(name: "Type 5")), ]; return landmarks; // } else { diff --git a/frontend/pubspec.lock b/frontend/pubspec.lock index 7c2f396..e959889 100644 --- a/frontend/pubspec.lock +++ b/frontend/pubspec.lock @@ -112,46 +112,6 @@ packages: description: flutter source: sdk version: "0.0.0" - geocode: - dependency: "direct main" - description: - name: geocode - sha256: cf9727c369bb3703b97d6e440225962dc27b7f3c686662fe3cdcc91cbfb7074d - url: "https://pub.dev" - source: hosted - version: "1.0.3" - geocoding: - dependency: "direct main" - description: - name: geocoding - sha256: d580c801cba9386b4fac5047c4c785a4e19554f46be42f4f5e5b7deacd088a66 - url: "https://pub.dev" - source: hosted - version: "3.0.0" - geocoding_android: - dependency: transitive - description: - name: geocoding_android - sha256: "1b13eca79b11c497c434678fed109c2be020b158cec7512c848c102bc7232603" - url: "https://pub.dev" - source: hosted - version: "3.3.1" - geocoding_ios: - dependency: transitive - description: - name: geocoding_ios - sha256: "94ddba60387501bd1c11e18dca7c5a9e8c645d6e3da9c38b9762434941870c24" - url: "https://pub.dev" - source: hosted - version: "3.0.1" - geocoding_platform_interface: - dependency: transitive - description: - name: geocoding_platform_interface - sha256: "8c2c8226e5c276594c2e18bfe88b19110ed770aeb7c1ab50ede570be8b92229b" - url: "https://pub.dev" - source: hosted - version: "3.2.0" google_maps: dependency: transitive description: diff --git a/frontend/pubspec.yaml b/frontend/pubspec.yaml index 9f1732c..e278579 100644 --- a/frontend/pubspec.yaml +++ b/frontend/pubspec.yaml @@ -36,8 +36,6 @@ dependencies: # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.6 sliding_up_panel: ^2.0.0+1 - geocoding: ^3.0.0 - geocode: ^1.0.3 google_maps_flutter: ^2.6.1 http: ^1.2.1 shared_preferences: ^2.2.3 diff --git a/frontend/web/index.html b/frontend/web/index.html index 5cbcc91..8d38cac 100644 --- a/frontend/web/index.html +++ b/frontend/web/index.html @@ -14,7 +14,7 @@ This is a placeholder for base href that will be replaced by the value of the `--base-href` argument provided to `flutter build`. --> - +