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

update: get_relation, return json coords

parent 58fbb5ca
No related branches found
No related tags found
1 merge request!3Choropleth map implementation
import 'dart:convert';
import 'package:flutter/material.dart';
import '../marker_handler/marker_data.dart';
import 'package:http/http.dart' as http;
import 'package:syncfusion_flutter_maps/maps.dart';
// From https://www.syncfusion.com/blogs/post/create-choropleth-map-using-in-flutter.aspx
class _ChoroplethMapState extends State {
List<Measurement> iceThickness;
MapShapeSource _mapShapeSource;
late 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,
);
getRelation().then((geojsonData) {
setState(() {
mapShapeSource = MapShapeSource.geoJson(
geojsonData,
shapeDataField: 'features',
primaryValueMapper: (Map<String, dynamic> shapeData) {
return shapeData['Mjøsa'];
},
);
});
}).catchError((error) {
throw Exception('Failed to retrieve geojson data');
});
}
@override
......@@ -24,10 +30,23 @@ class _ChoroplethMapState extends State {
return SfMaps(
layers: [
MapShapeLayer(
source: _mapShapeSource,
strokeColor: Colors.white30
source: mapShapeSource,
strokeColor: Colors.white30,
legend: const MapLegend.bar(MapElement.shape,
position: MapLegendPosition.bottom,
segmentSize: Size(55.0, 9.0)
)
),
],
);
}
}
\ No newline at end of file
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');
}
}
}
......@@ -119,10 +119,10 @@ packages:
dependency: "direct main"
description:
name: http
sha256: "5895291c13fa8a3bd82e76d5627f69e0d85ca6a30dcac95c4ea19a5d555879c2"
sha256: "6aa2946395183537c8b880962d935877325d6a09a2867c3970c05c0fed6ac482"
url: "https://pub.dev"
source: hosted
version: "0.13.6"
version: "0.13.5"
http_parser:
dependency: transitive
description:
......@@ -360,6 +360,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.2.0"
syncfusion_flutter_core:
dependency: transitive
description:
name: syncfusion_flutter_core
sha256: "3979f0b1c5a97422cadae52d476c21fa3e0fb671ef51de6cae1d646d8b99fe1f"
url: "https://pub.dev"
source: hosted
version: "20.4.54"
syncfusion_flutter_maps:
dependency: "direct main"
description:
name: syncfusion_flutter_maps
sha256: "1c95924e2dee5bbad922c2d2f1d5fb1b13ce4548c34a6d30fe6bf8821dfcfcd6"
url: "https://pub.dev"
source: hosted
version: "20.4.54"
term_glyph:
dependency: transitive
description:
......
......@@ -15,6 +15,7 @@ dependencies:
provider: ^5.0.0
fl_chart: ^0.20.0-nullsafety1
google_fonts: any
syncfusion_flutter_maps: ^20.4.41
dev_dependencies:
flutter_test:
......
......@@ -2,6 +2,7 @@ from flask import Flask
from http.server import HTTPServer, BaseHTTPRequestHandler
from consts import SSL_CERT_PATH, SSL_KEY_PATH, HOST, PORT
from map.get_markers import get_all_markers
from map.get_relation import get_relation
from APIs.get_weather import get_weather
import ssl
import keyboard
......@@ -41,6 +42,8 @@ class IceHTTP(BaseHTTPRequestHandler):
elif self.path == '/get_valid_markers': # NB: should be POST?
get_all_markers(self, self.cursor, True, 'Mjosa') # Get only valid markers
# NB: temporary hardcoded waterBodyName
elif self.path == '/get_relation':
get_relation(self, 'Mjosa') # NB temp hardcoded value
def do_POST(self):
if self.path == '/get_weather_data':
......
File added
import string
import json
# get_relation returns the geojson data for a selected body of water
def get_relation(self, body_of_water: string):
# Read geojson file
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)
# Set headers
self.send_response(200)
self.send_header("Content-type", "application/json")
self.end_headers()
# Write coordinates to response object
self.wfile.write(response_json.encode('utf-8'))
Source diff could not be displayed: it is too large. Options to address this: view the blob.
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