Skip to content
Snippets Groups Projects
Commit e0f9cc5f authored by Sara Savanovic Djordjevic's avatar Sara Savanovic Djordjevic
Browse files

update: minor improvement swapping lakes

parent 74bf5813
No related branches found
No related tags found
1 merge request!13Clhp map
...@@ -6,6 +6,7 @@ import 'package:liquid_pull_to_refresh/liquid_pull_to_refresh.dart'; ...@@ -6,6 +6,7 @@ import 'package:liquid_pull_to_refresh/liquid_pull_to_refresh.dart';
import '../consts.dart'; import '../consts.dart';
import '../widgets/main_layout.dart'; import '../widgets/main_layout.dart';
import '../widgets/choropleth_map.dart';
import '../utils/custom_search_delegate.dart'; import '../utils/custom_search_delegate.dart';
class DefaultPage extends StatefulWidget { class DefaultPage extends StatefulWidget {
...@@ -66,6 +67,7 @@ class _DefaultPageState extends State<DefaultPage> { ...@@ -66,6 +67,7 @@ class _DefaultPageState extends State<DefaultPage> {
setState(() { setState(() {
print("SetState called!"); print("SetState called!");
selectedLake = result; selectedLake = result;
// NB update lastLake persistent variable
initialiseState(false); initialiseState(false);
}); });
} }
......
...@@ -9,7 +9,8 @@ import '../data_classes.dart'; ...@@ -9,7 +9,8 @@ import '../data_classes.dart';
/// The map is created using the Syncfusion Flutter Maps library and /// The map is created using the Syncfusion Flutter Maps library and
/// coordinates fetched from the server. /// coordinates fetched from the server.
class ChoroplethMap extends StatefulWidget { class ChoroplethMap extends StatefulWidget {
const ChoroplethMap({Key? key, const ChoroplethMap({
Key? key,
required this.relation, required this.relation,
required this.measurements, required this.measurements,
required this.onSelectionChanged, required this.onSelectionChanged,
...@@ -20,64 +21,75 @@ class ChoroplethMap extends StatefulWidget { ...@@ -20,64 +21,75 @@ class ChoroplethMap extends StatefulWidget {
final void Function(int selectedIndex) onSelectionChanged; final void Function(int selectedIndex) onSelectionChanged;
@override @override
_ChoroplethMapState createState() => _ChoroplethMapState(); ChoroplethMapState createState() => ChoroplethMapState();
} }
class _ChoroplethMapState extends State<ChoroplethMap> { class ChoroplethMapState extends State<ChoroplethMap> {
int selectedIndex = -1; // Subdivision/map tile index int selectedIndex = -1; // Subdivision/map tile index
late MapShapeSource dataSource; late MapShapeSource dataSource;
late final MapZoomPanBehavior _zoomPanBehavior = MapZoomPanBehavior(); late final MapZoomPanBehavior _zoomPanBehavior = MapZoomPanBehavior();
final List<SubDiv> _subdivisions = <SubDiv>[]; final List<SubDiv> _subdivisions = <SubDiv>[];
void updateDataSource() {
_initDataSource();
}
@override @override
void initState() { void initState() {
super.initState(); super.initState();
// Extract all _subdivisions from list of measurements _initDataSource();
for (Measurement measurement in widget.measurements) { }
for (SubDiv subdivision in measurement.subDivs) {
_subdivisions.add(subdivision); 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(
dataSource = MapShapeSource.memory( widget.relation,
widget.relation, shapeDataField: 'sub_div_id',
shapeDataField: 'sub_div_id', dataCount: _subdivisions.length,
dataCount: _subdivisions.length, primaryValueMapper: (int index) => _subdivisions[index].sub_div_id,
primaryValueMapper: (int index) => _subdivisions[index].sub_div_id, shapeColorValueMapper: (int index) => _subdivisions[index].avgThickness, // NB will later be minThickness
shapeColorValueMapper: (int index) => _subdivisions[index].avgThickness, // NB will later be minThickness shapeColorMappers: const [
shapeColorMappers: const [ MapColorMapper(
from: -2,
to: -1,
color: Color(0xFF8C8C8C),
text: '>8'),
MapColorMapper(
from: 0,
to: 4,
color: Color(0xFFff0000),
text: '{0},{4}'),
MapColorMapper( MapColorMapper(
from: -2, from: 4,
to: -1, to: 6,
color: Color(0xFF8C8C8C), 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'), 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
updateDataSource();
return Stack( return Stack(
children: [ children: [
SfMapsTheme( SfMapsTheme(
......
...@@ -75,7 +75,6 @@ class _MapContainerWidgetState extends State<MapContainerWidget> { ...@@ -75,7 +75,6 @@ class _MapContainerWidgetState extends State<MapContainerWidget> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
// Initialise selectedMarker to first element in markerList // Initialise selectedMarker to first element in markerList
selectedSubDiv ??= widget.measurements[0].subDivs[0]; selectedSubDiv ??= widget.measurements[0].subDivs[0];
checkAndSetLastUpdate(); checkAndSetLastUpdate();
const double contPadding = 30; // Container padding space const double contPadding = 30; // Container padding space
...@@ -107,7 +106,8 @@ class _MapContainerWidgetState extends State<MapContainerWidget> { ...@@ -107,7 +106,8 @@ class _MapContainerWidgetState extends State<MapContainerWidget> {
child: ChoroplethMap( child: ChoroplethMap(
relation: widget.relation, relation: widget.relation,
measurements: widget.measurements, measurements: widget.measurements,
onSelectionChanged: handleSelection,), onSelectionChanged: handleSelection,
),
), ),
), ),
SizedBox( SizedBox(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment