From 74bf58130ec5b0f7bf9044dfb1da97c9084632ad Mon Sep 17 00:00:00 2001 From: Sara <sarasdj@stud.ntnu.no> Date: Tue, 16 Apr 2024 10:32:36 +0200 Subject: [PATCH] add: setLastLake() --- app/lib/server_requests/init_state.dart | 8 +++++++- app/lib/widgets/choropleth_map.dart | 20 ++++++++++---------- server/map_handler/get_measurements.py | 3 ++- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/app/lib/server_requests/init_state.dart b/app/lib/server_requests/init_state.dart index 6cdf33eb..ce522506 100644 --- a/app/lib/server_requests/init_state.dart +++ b/app/lib/server_requests/init_state.dart @@ -3,13 +3,13 @@ import 'dart:async'; import 'dart:convert'; import 'dart:typed_data'; import 'package:app/consts.dart'; +import 'package:shared_preferences/shared_preferences.dart'; import '../consts.dart'; import '../data_classes.dart'; import '../server_requests/fetch_markers.dart'; import '../server_requests/fetch_relation.dart'; - /// initialiseState makes three requests to the server, one requesting /// measurements for the selected relation, the other requesting the relation, /// and the last requesting the list of all system lakes @@ -31,6 +31,7 @@ Future<void> initialiseState(bool fetchSearchOptions) async { markerListFuture = fetchMeasurements().then((fetchResult) { List<Measurement> measurements = fetchResult.measurements; serverConnection = fetchResult.connected; + setLastLake(); // Return measurements return measurements; @@ -87,4 +88,9 @@ Future<void> initSearchOptions() async { } catch (e) { print("Failed to fetch lake names: $e"); } +} + +Future<void> setLastLake() async { + final prefs = await SharedPreferences.getInstance(); + await prefs.setString('lastLake', selectedLake); } \ No newline at end of file diff --git a/app/lib/widgets/choropleth_map.dart b/app/lib/widgets/choropleth_map.dart index d55e79ca..af44d65c 100644 --- a/app/lib/widgets/choropleth_map.dart +++ b/app/lib/widgets/choropleth_map.dart @@ -17,15 +17,15 @@ class ChoroplethMap extends StatefulWidget { final Uint8List relation; final List<Measurement> measurements; - final void Function(int _selectedIndex) onSelectionChanged; + final void Function(int selectedIndex) onSelectionChanged; @override - ChoroplethMapState createState() => ChoroplethMapState(); + _ChoroplethMapState createState() => _ChoroplethMapState(); } -class ChoroplethMapState extends State<ChoroplethMap> { - int _selectedIndex = -1; // Subdivision/map tile index - late MapShapeSource _dataSource; +class _ChoroplethMapState extends State<ChoroplethMap> { + int selectedIndex = -1; // Subdivision/map tile index + late MapShapeSource dataSource; late final MapZoomPanBehavior _zoomPanBehavior = MapZoomPanBehavior(); final List<SubDiv> _subdivisions = <SubDiv>[]; @@ -40,7 +40,7 @@ class ChoroplethMapState extends State<ChoroplethMap> { }; // Initialise data source - _dataSource = MapShapeSource.memory( + dataSource = MapShapeSource.memory( widget.relation, shapeDataField: 'sub_div_id', dataCount: _subdivisions.length, @@ -88,17 +88,17 @@ class ChoroplethMapState extends State<ChoroplethMap> { child: SfMaps( layers: [ MapShapeLayer( - source: _dataSource, + source: dataSource, zoomPanBehavior: _zoomPanBehavior, strokeColor: Colors.blue.shade50, strokeWidth: 1, // Shape selection - selectedIndex: _selectedIndex, + selectedIndex: selectedIndex, onSelectionChanged: (int index) { setState(() { - _selectedIndex = index; + selectedIndex = index; }); - widget.onSelectionChanged(_selectedIndex); + widget.onSelectionChanged(selectedIndex); }, ), ], diff --git a/server/map_handler/get_measurements.py b/server/map_handler/get_measurements.py index a6b2872c..4de8c8a0 100644 --- a/server/map_handler/get_measurements.py +++ b/server/map_handler/get_measurements.py @@ -138,7 +138,8 @@ def fill_remaining_subdivisions(lake_name: str, sub_div_ids: list): 'CenLatitude': center_lat, 'CenLongitude': center_lng, 'Accuracy': None, - 'Color': calculateColor(ice_stats[0]['Total ice (m)']), # Calculate ice thickness based on total ice, temporary + # Calculate ice thickness based on total ice, temporary + 'Color': calculateColor(ice_stats[0]['Total ice (m)']), 'IceStats': ice_stats, } -- GitLab