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

update: InteractivePolygon

parent 2d6d1f8e
No related branches found
No related tags found
1 merge request!3Choropleth map implementation
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
......@@ -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
......
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