From 58fbb5ca698d795663407029275d88718d317866 Mon Sep 17 00:00:00 2001
From: Sara <sarasdj@stud.ntnu.no>
Date: Mon, 26 Feb 2024 15:51:26 +0100
Subject: [PATCH] update: InteractivePolygon

---
 app/lib/pages/widgets/cloropleth_map.dart     | 33 +++++++++++++++++
 .../pages/widgets/interactive_polygon.dart    | 35 +++++--------------
 2 files changed, 42 insertions(+), 26 deletions(-)
 create mode 100644 app/lib/pages/widgets/cloropleth_map.dart

diff --git a/app/lib/pages/widgets/cloropleth_map.dart b/app/lib/pages/widgets/cloropleth_map.dart
new file mode 100644
index 00000000..fc1cb5f0
--- /dev/null
+++ b/app/lib/pages/widgets/cloropleth_map.dart
@@ -0,0 +1,33 @@
+import 'package:flutter/material.dart';
+import '../marker_handler/marker_data.dart';
+
+// From https://www.syncfusion.com/blogs/post/create-choropleth-map-using-in-flutter.aspx
+class _ChoroplethMapState extends State {
+  List<Measurement> iceThickness;
+  MapShapeSource _mapShapeSource;
+
+  @override
+  void initState() {
+    super.initState();
+
+    _mapShapeSource = MapShapeSource.asset(
+      'assets/world_map.json',
+      shapeDataField: 'name',
+      dataCount: _mapShapeSource.length,
+      primaryValueMapper: (int index) =>
+      _mapShapeSource[index].countryName,
+    );
+  }
+
+  @override
+  Widget build(BuildContext context) {
+    return SfMaps(
+      layers: [
+        MapShapeLayer(
+            source: _mapShapeSource,
+            strokeColor: Colors.white30
+        ),
+      ],
+    );
+  }
+}
\ No newline at end of file
diff --git a/app/lib/pages/widgets/interactive_polygon.dart b/app/lib/pages/widgets/interactive_polygon.dart
index 07dc4603..4edfecc4 100644
--- a/app/lib/pages/widgets/interactive_polygon.dart
+++ b/app/lib/pages/widgets/interactive_polygon.dart
@@ -2,8 +2,8 @@ import 'package:flutter/material.dart';
 import '../marker_handler/marker_data.dart';
 import 'package:latlong2/latlong.dart' as latLng;
 
-// InteractivePolygon returns a Polygon object wrapped in a CustomPaint,
-// which is then wrapped in a GestureDetector. This is in order to make the Polygon clickable
+// InteractivePolygon returns a Polygon in a CustomPaint, in a GestureDetector
+// in order to make the polygon clickable
 class InteractivePolygon extends StatelessWidget {
   final List<latLng.LatLng> points;
   final void Function(Measurement)? onTap;
@@ -34,8 +34,8 @@ class InteractivePolygon extends StatelessWidget {
   }
 }
 
-// PolygonPainter takes the points, color, and stroke width from a
-// object of type InteractivePolygon, and renders it
+// PolygonPainter is a custom polygon renderer for Measurement objects
+// NB: from https://www.kindacode.com/article/flutter-custompaint-and-custompainter/
 class PolygonPainter extends CustomPainter {
   final List<latLng.LatLng> points;
   final Color bodyColor;
@@ -69,6 +69,11 @@ class PolygonPainter extends CustomPainter {
 
     final path = Path();
     if (points.isNotEmpty) {
+      print("\n");
+      for (final coord in points) {
+        print("Corner: ${coord.latitude}, ${coord.longitude}");
+      }
+
       final firstPoint = points.first;
       path.moveTo(firstPoint.latitude, firstPoint.longitude);
 
@@ -84,28 +89,6 @@ class PolygonPainter extends CustomPainter {
     else {
       print("Error in rendering polygon. No points provided");
     }
-
-    /*final paint = Paint()
-      ..color = color
-      ..style = PaintingStyle.stroke
-      ..strokeWidth = strokeWidth;
-
-    final path = Path();
-    if (points.isNotEmpty) {
-      final firstPoint = points.first;
-      path.moveTo(firstPoint.latitude, firstPoint.longitude);
-
-      for (var i = 1; i < points.length; i++) {
-        final point = points[i];
-        path.lineTo(point.latitude, point.longitude);
-      }
-
-      path.close();
-      canvas.drawPath(path, paint);
-    }
-    else {
-      print("Error in rendering polygon. No points provided");
-    }*/
   }
 
   @override
-- 
GitLab