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