diff --git a/app/lib/pages/default_page.dart b/app/lib/pages/default_page.dart index ac2bf189ccb814f0f3e29e6d0dacbb9416a47b61..213bea6b6c76a11ca14d76061b609f6d267d855d 100644 --- a/app/lib/pages/default_page.dart +++ b/app/lib/pages/default_page.dart @@ -6,6 +6,7 @@ import 'package:liquid_pull_to_refresh/liquid_pull_to_refresh.dart'; import '../consts.dart'; import '../widgets/main_layout.dart'; +import '../widgets/choropleth_map.dart'; import '../utils/custom_search_delegate.dart'; class DefaultPage extends StatefulWidget { @@ -66,6 +67,7 @@ class _DefaultPageState extends State<DefaultPage> { setState(() { print("SetState called!"); selectedLake = result; + // NB update lastLake persistent variable initialiseState(false); }); } diff --git a/app/lib/widgets/choropleth_map.dart b/app/lib/widgets/choropleth_map.dart index af44d65c517f7d6053ff2787c874100b8dc25d91..aa004fe2385f01bdcc06f2b456fd7e08a4247e29 100644 --- a/app/lib/widgets/choropleth_map.dart +++ b/app/lib/widgets/choropleth_map.dart @@ -9,7 +9,8 @@ import '../data_classes.dart'; /// The map is created using the Syncfusion Flutter Maps library and /// coordinates fetched from the server. class ChoroplethMap extends StatefulWidget { - const ChoroplethMap({Key? key, + const ChoroplethMap({ + Key? key, required this.relation, required this.measurements, required this.onSelectionChanged, @@ -20,64 +21,75 @@ class ChoroplethMap extends StatefulWidget { final void Function(int selectedIndex) onSelectionChanged; @override - _ChoroplethMapState createState() => _ChoroplethMapState(); + ChoroplethMapState createState() => ChoroplethMapState(); } -class _ChoroplethMapState extends State<ChoroplethMap> { +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>[]; + void updateDataSource() { + _initDataSource(); + } + @override void initState() { super.initState(); - // Extract all _subdivisions from list of measurements - for (Measurement measurement in widget.measurements) { - for (SubDiv subdivision in measurement.subDivs) { - _subdivisions.add(subdivision); + _initDataSource(); + } + + void _initDataSource() { + _subdivisions.clear(); + + // Extract all _subdivisions from list of measurements + for (Measurement measurement in widget.measurements) { + for (SubDiv subdivision in measurement.subDivs) { + _subdivisions.add(subdivision); + } } - }; - // Initialise data source - dataSource = MapShapeSource.memory( - widget.relation, - shapeDataField: 'sub_div_id', - dataCount: _subdivisions.length, - primaryValueMapper: (int index) => _subdivisions[index].sub_div_id, - shapeColorValueMapper: (int index) => _subdivisions[index].avgThickness, // NB will later be minThickness - shapeColorMappers: const [ + dataSource = MapShapeSource.memory( + widget.relation, + shapeDataField: 'sub_div_id', + dataCount: _subdivisions.length, + primaryValueMapper: (int index) => _subdivisions[index].sub_div_id, + shapeColorValueMapper: (int index) => _subdivisions[index].avgThickness, // NB will later be minThickness + shapeColorMappers: const [ + MapColorMapper( + from: -2, + to: -1, + color: Color(0xFF8C8C8C), + text: '>8'), + MapColorMapper( + from: 0, + to: 4, + color: Color(0xFFff0000), + text: '{0},{4}'), MapColorMapper( - from: -2, - to: -1, - color: Color(0xFF8C8C8C), + from: 4, + to: 6, + color: Color(0xffff6a00), + text: '6'), + MapColorMapper( + from: 6, + to: 8, + color: Color(0xFFb1ff00), + text: '8'), + MapColorMapper( + from: 8, + to: 400, + color: Color(0xFF00d6ff), text: '>8'), - MapColorMapper( - from: 0, - to: 4, - color: Color(0xFFff0000), - text: '{0},{4}'), - MapColorMapper( - from: 4, - to: 6, - color: Color(0xffff6a00), - text: '6'), - MapColorMapper( - from: 6, - to: 8, - color: Color(0xFFb1ff00), - text: '8'), - MapColorMapper( - from: 8, - to: 400, - color: Color(0xFF00d6ff), - text: '>8'), - ], - ); + ], + ); } @override Widget build(BuildContext context) { + updateDataSource(); + return Stack( children: [ SfMapsTheme( diff --git a/app/lib/widgets/main_layout.dart b/app/lib/widgets/main_layout.dart index 5b77d99291a23092d53752cb41a23bd50fcb8e6a..7ce31055996fbbd61463f1c2aabc3ef9d923832d 100644 --- a/app/lib/widgets/main_layout.dart +++ b/app/lib/widgets/main_layout.dart @@ -75,7 +75,6 @@ class _MapContainerWidgetState extends State<MapContainerWidget> { Widget build(BuildContext context) { // Initialise selectedMarker to first element in markerList selectedSubDiv ??= widget.measurements[0].subDivs[0]; - checkAndSetLastUpdate(); const double contPadding = 30; // Container padding space @@ -107,7 +106,8 @@ class _MapContainerWidgetState extends State<MapContainerWidget> { child: ChoroplethMap( relation: widget.relation, measurements: widget.measurements, - onSelectionChanged: handleSelection,), + onSelectionChanged: handleSelection, + ), ), ), SizedBox(