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

update: add Measurement objects to map

parent a8e9d14b
No related branches found
No related tags found
2 merge requests!9Clhp map,!8Clhp map
......@@ -8,7 +8,7 @@ class Measurement {
Sensor sensor;
String bodyOfWater;
LatLng center;
List <SubDiv> subDiv;
List <SubDiv> subDivs;
List <LatLng> corners;
Measurement({
......@@ -17,7 +17,7 @@ class Measurement {
required this.sensor,
required this.bodyOfWater,
required this.center,
required this.subDiv,
required this.subDivs,
required this.corners,
});
......@@ -28,14 +28,14 @@ class Measurement {
sensor: Sensor.fromJson(json['Sensor']),
bodyOfWater: json['BodyOfWater'] ?? 'nil',
center: LatLng(json['CenterLat'], json['CenterLon']),
subDiv: (json['Subdivisions'] as List<dynamic>).map((data) => SubDiv.fromJson(data)).toList(),
subDivs: (json['Subdivisions'] as List<dynamic>).map((data) => SubDiv.fromJson(data)).toList(),
corners: (json['Corners'] as List<dynamic>).map((corner) => LatLng(corner[0], corner[1])).toList(),
);
}
}
class SubDiv {
int sub_div_id;
String sub_div_id;
int groupID;
double minThickness;
double avgThickness;
......@@ -57,7 +57,7 @@ class SubDiv {
factory SubDiv.fromJson(Map<String, dynamic> json) {
return SubDiv(
sub_div_id: json['SubdivID'],
sub_div_id: json['SubdivID'].toString(),
groupID: json['GroupID'],
minThickness: json['MinThickness'],
avgThickness: json['AvgThickness'],
......
......@@ -37,27 +37,18 @@ class _ChoroplethMapState extends State<ChoroplethMap> {
int selectedIndex = -1;
late MapShapeSource mapShapeSource;
late final MapZoomPanBehavior _zoomPanBehavior = MapZoomPanBehavior();
List<IceThicknessModel> iceThicknessList = <IceThicknessModel>[];
List<Color> testColors = [ // NB test color
const Color(0xff8a003b),
const Color(0xff8a4300),
const Color(0xff8a7a00),
const Color(0xff538a00),
const Color(0xff007b8a),
];
List<SubDiv> subdivisions = <SubDiv>[];
@override
void initState() {
super.initState();
final Random random = Random();
for (int i = 0; i <= 120; i++) {
int ran = random.nextInt(5); // NB test color
Color randomColor = testColors[ran];
int randomNumber = random.nextInt(21); // 0 -> 20, NB: temp test data
iceThicknessList.add(IceThicknessModel(i.toString(), randomNumber, randomColor, randomColor));
}
// Create list of all subdivisions
for (Measurement measurement in widget.measurements) {
for (SubDiv subdivision in measurement.subDivs) {
subdivisions.add(subdivision);
}
};
}
@override
......@@ -70,9 +61,9 @@ class _ChoroplethMapState extends State<ChoroplethMap> {
source: MapShapeSource.memory( // Map polygon
widget.relation, // JSON coordinates from server
shapeDataField: 'sub_div_id',
dataCount: iceThicknessList.length,
primaryValueMapper: (int index) => iceThicknessList[index].sub_div_id,
shapeColorValueMapper: (int index) => iceThicknessList[index].color,
dataCount: widget.measurements.length,
primaryValueMapper: (int index) => subdivisions[index].sub_div_id,
shapeColorValueMapper: (int index) => subdivisions[index].color,
),
//color: Colors.blue.shade400, // Map color
zoomPanBehavior: _zoomPanBehavior,
......@@ -82,8 +73,8 @@ class _ChoroplethMapState extends State<ChoroplethMap> {
onSelectionChanged: (int index) {
setState(() {
selectedIndex = index;
for (int i = 0; i < iceThicknessList.length; i++) {
iceThicknessList[i].color = i == index ? Colors.red : iceThicknessList[i].savedColor;
for (int i = 0; i < subdivisions.length; i++) {
subdivisions[i].color = i == index ? Colors.red : subdivisions[i].savedColor;
}
});
widget.onSelectionChanged(selectedIndex);
......
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