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

add: cloro-map to map widget, not working

parent 27c49bc1
No related branches found
No related tags found
1 merge request!3Choropleth map implementation
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}');
}
}
}
......@@ -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,
......
name: app
description: "A new Flutter project."
description: "IceMap Application"
publish_to: 'none'
version: 0.1.0
......
No preview for this file type
......@@ -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)
......
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