diff --git a/app/lib/pages/widgets/cloropleth_map.dart b/app/lib/pages/widgets/cloropleth_map.dart index b8239d0447fa9abd4de5273f347ba8dcecf93123..ea33009a252ee2efb5cc34af16d580ab190035fa 100644 --- a/app/lib/pages/widgets/cloropleth_map.dart +++ b/app/lib/pages/widgets/cloropleth_map.dart @@ -21,11 +21,13 @@ class IceThicknessModel { class ChoroplethMap extends StatefulWidget { const ChoroplethMap({Key? key, required this.relation, - required this.measurements + required this.measurements, + required this.onSelectionChanged, }) : super(key: key); final Uint8List relation; final List<Measurement> measurements; + final void Function(int selectedIndex) onSelectionChanged; // Callback function @override _ChoroplethMapState createState() => _ChoroplethMapState(); @@ -84,7 +86,7 @@ class _ChoroplethMapState extends State<ChoroplethMap> { iceThicknessList[i].color = i == index ? Colors.red : iceThicknessList[i].savedColor; } }); - print("Selection triggered"); + widget.onSelectionChanged(selectedIndex); }, selectionSettings: MapSelectionSettings( color: Colors.orange, diff --git a/app/lib/pages/widgets/map_widget.dart b/app/lib/pages/widgets/map_widget.dart index d308527304fe415fb17550657a2f715a36f2df4d..7d824eef6f43bbdfdfd7c80fe579bee0470c81af 100644 --- a/app/lib/pages/widgets/map_widget.dart +++ b/app/lib/pages/widgets/map_widget.dart @@ -28,6 +28,7 @@ class MapContainerWidget extends StatefulWidget { class _MapContainerWidgetState extends State<MapContainerWidget> { Measurement? selectedMarker; // Containing data for selected marker + int selectedMarkerIndex = 0; bool isMinimized = true; // Quick view box state tacker bool satLayer = false; // Satellite layer visibility tracker bool isTapped = false; // Button tap state tracker @@ -53,10 +54,17 @@ class _MapContainerWidgetState extends State<MapContainerWidget> { } } + // Tile selection handler + void handleSelection(int index) { + setState(() { + selectedMarkerIndex = index; + }); + } + @override Widget build(BuildContext context) { // Initialise selectedMarker to first element in markerList - selectedMarker ??= widget.markerList[0]; + selectedMarker ??= widget.markerList[selectedMarkerIndex]; checkAndSetLastUpdate(); @@ -154,7 +162,10 @@ class _MapContainerWidgetState extends State<MapContainerWidget> { height: screenWidth * boxHeight, child: Padding( padding: const EdgeInsets.all(15.0), // Padding around map - child: ChoroplethMap(relation: widget.relation, measurements: widget.markerList,), + child: ChoroplethMap( + relation: widget.relation, + measurements: widget.markerList, + onSelectionChanged: handleSelection,), ), ), Positioned( // Quick view box layered over map