diff --git a/app/lib/pages/widgets/cloropleth_map.dart b/app/lib/pages/widgets/cloropleth_map.dart index 6625ce00338431d1f49c074b4b941b8ebad76aa3..404de178d04f101981ddb25c92afb2d37bb930cf 100644 --- a/app/lib/pages/widgets/cloropleth_map.dart +++ b/app/lib/pages/widgets/cloropleth_map.dart @@ -1,9 +1,14 @@ import 'dart:convert'; - import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; import 'package:syncfusion_flutter_maps/maps.dart'; + +class ChoroplethMap extends StatefulWidget { + @override + _ChoroplethMapState createState() => _ChoroplethMapState(); +} + class _ChoroplethMapState extends State { late MapShapeSource mapShapeSource; @@ -12,11 +17,14 @@ class _ChoroplethMapState extends State { super.initState(); getRelation().then((geojsonData) { setState(() { - mapShapeSource = MapShapeSource.geoJson( - geojsonData, - shapeDataField: 'features', - primaryValueMapper: (Map<String, dynamic> shapeData) { - return shapeData['Mjøsa']; + final geoJsonData = json.decode(geojsonData); + + mapShapeSource = MapShapeSource.asset( + geoJsonData, + shapeDataField: 'coordinates', + dataCount: geoJsonData.length, + primaryValueMapper: (int index) { + return 'lake'; // NB: temp hardcoded value, no subdivisions yet }, ); }); @@ -30,23 +38,25 @@ class _ChoroplethMapState extends State { return SfMaps( layers: [ MapShapeLayer( - source: mapShapeSource, - strokeColor: Colors.white30, - legend: const MapLegend.bar(MapElement.shape, + source: mapShapeSource, + strokeColor: Colors.white30, + legend: const MapLegend.bar( + MapElement.shape, position: MapLegendPosition.bottom, - segmentSize: Size(55.0, 9.0) - ) + segmentSize: Size(55.0, 9.0), + ), ), ], ); } + // getRelation requests the polygon coordinates from the server Future<String> getRelation() async { final response = await http.get(Uri.parse('get_relation')); if (response.statusCode == 200) { return response.body; } else { - throw Exception('Failed to retrieve geojson data'); + throw Exception('Failed to retrieve geojson data from server. Status code: ${response.statusCode}'); } } } diff --git a/app/lib/pages/widgets/map_widget.dart b/app/lib/pages/widgets/map_widget.dart index 5629fc17519bd26f52813e8b9ef80531267fcda4..694b5dc908731ea03087ab06a3186acedac78ebd 100644 --- a/app/lib/pages/widgets/map_widget.dart +++ b/app/lib/pages/widgets/map_widget.dart @@ -6,6 +6,7 @@ import 'stat_charts.dart'; import 'sat_layer.dart'; import 'package:flutter_map/flutter_map.dart'; import 'interactive_polygon.dart'; +import 'cloropleth_map.dart'; import 'package:latlong2/latlong.dart' as latLng; @@ -59,7 +60,8 @@ class _MapContainerWidgetState extends State<MapContainerWidget> { SizedBox( width: screenWidth * boxWidth, height: screenWidth * boxHeight, - child: FlutterMap( + child: ChoroplethMap() + /*FlutterMap( options: MapOptions( center: mapCenter, zoom: 9.0, @@ -102,7 +104,7 @@ class _MapContainerWidgetState extends State<MapContainerWidget> { }).toList(), ), ], - ), + ),*/ ), /*SizedBox( width: screenWidth * boxWidth, diff --git a/app/pubspec.yaml b/app/pubspec.yaml index 344f9e07b5b9e3ace2761d23128ad9bfe85bd9e4..339a8292989238321a9c0c381b638b84d4a71ba2 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -1,5 +1,5 @@ name: app -description: "A new Flutter project." +description: "IceMap Application" publish_to: 'none' version: 0.1.0 diff --git a/server/map/__pycache__/get_relation.cpython-311.pyc b/server/map/__pycache__/get_relation.cpython-311.pyc index d6bc7b01570aaf2317e1583cdcc14afae62499ee..5c895e2e0a57f69d3a5a3793d4d4e3a916090cd8 100644 Binary files a/server/map/__pycache__/get_relation.cpython-311.pyc and b/server/map/__pycache__/get_relation.cpython-311.pyc differ diff --git a/server/map/get_relation.py b/server/map/get_relation.py index f325b168f3bed7968af46e935bdff173f3fa82a7..581afaa5ed28d834e88e701ff198f23d22cc45e2 100644 --- a/server/map/get_relation.py +++ b/server/map/get_relation.py @@ -8,17 +8,8 @@ def get_relation(self, body_of_water: string): with open("server/map/" + body_of_water.lower() + ".geojson") as f: data = json.load(f) - # Extracting coordinates from the GeoJSON features - coordinates = [] - for feature in data['features']: - if feature['geometry']['type'] == 'Polygon': - coordinates.extend(feature['geometry']['coordinates'][0]) - elif feature['geometry']['type'] == 'MultiPolygon': - for polygon_coords in feature['geometry']['coordinates']: - coordinates.extend(polygon_coords[0]) - - # Convert response data to JSON string - response_json = json.dumps(coordinates) + # Convert data to JSON string + response_json = json.dumps(data) # Set headers self.send_response(200)