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

add: working test map, autralia

parent e8dd395b
No related branches found
No related tags found
1 merge request!3Choropleth map implementation
Source diff could not be displayed: it is too large. Options to address this: view the blob.
Source diff could not be displayed: it is too large. Options to address this: view the blob.
......@@ -17,17 +17,14 @@ class _DefaultPageState extends State<DefaultPage> {
bool showBar = false;
List<Measurement> markerList = [];
String relation = '';
// Call fetchMarkerTemplate and await its result before setting the state
Future<void> loadMarkerList() async {
try {
List<Measurement> fetchedMarkers = await fetchMarkerData();
String fetchedRelation = await fetchRelation();
setState(() {
markerList = fetchedMarkers;
relation = fetchedRelation;
});
} catch (e) {
showDialog(
......@@ -98,7 +95,7 @@ class _DefaultPageState extends State<DefaultPage> {
),
body: ListView(
children: [ // Add main widget
MapContainerWidget(markerList: markerList, relation: relation),
MapContainerWidget(markerList: markerList),
],
),
),
......
......@@ -41,35 +41,3 @@ Future<List<Measurement>> fetchMarkerData() async {
throw Exception('Failed to fetch marker data: ${e.toString()}');
}
}
// fetchRelation requests lake relation data from the server
Future<String> fetchRelation() async {
try {
// Custom HTTP client
HttpClient client = HttpClient()
..badCertificateCallback = // NB: temporary disable SSL certificate validation
(X509Certificate cert, String host, int port) => true;
// Request markers from server
var request = await client.getUrl(Uri.parse(serverURI + 'get_relation'));
var response = await request.close(); // Close response body at end of function
// Parse body to JSON if request is ok
if (response.statusCode == 200) {
var responseBody = await response.transform(utf8.decoder).join();
if (responseBody.isNotEmpty) {
return responseBody;
} else {
throw Exception('Failed to fetch relation, body is empty');
}
} else {
throw Exception('Failed to fetch relation: Status code ${response.statusCode}');
}
} catch (e) {
throw Exception('Failed to fetch relation: ${e.toString()}');
}
}
import 'package:app/pages/consts.dart';
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_maps/maps.dart';
import 'package:flutter/services.dart';
/// A class containing thickness for each subdivision of the map.
class IceThicknessModel {
......@@ -14,11 +15,7 @@ class IceThicknessModel {
/// The map data is fetched from the server, and the map is rendered
/// using the Syncfusion Flutter Maps library.
class ChoroplethMap extends StatefulWidget {
final String relation;
const ChoroplethMap({Key? key,
required this.relation,
}) : super(key: key);
const ChoroplethMap({Key? key,}) : super(key: key);
@override
_ChoroplethMapState createState() => _ChoroplethMapState();
......@@ -28,45 +25,18 @@ class _ChoroplethMapState extends State<ChoroplethMap> {
late MapShapeSource mapShapeSource;
List<IceThicknessModel> iceThicknessList = <IceThicknessModel>[];
@override
void initState() {
super.initState();
iceThicknessList = <IceThicknessModel>[ // NB temp test data
IceThicknessModel(1, 2.5),
IceThicknessModel(2, 4.9),
IceThicknessModel(3, 8.0),
IceThicknessModel(4, 5.6),
IceThicknessModel(5, 7.3),
IceThicknessModel(6, 6.6),
IceThicknessModel(7, 6.0),
IceThicknessModel(8, 9.0),
];
mapShapeSource = MapShapeSource.network(
'${serverURI}get_relation', // Request map coordinates from server
shapeDataField: 'subDivID',
dataCount: iceThicknessList.length,
primaryValueMapper: (int index) => iceThicknessList[index].subDivID.toString(),
);
}
@override
Widget build(BuildContext context) {
return SfMaps(
return const SfMaps(
layers: [
MapShapeLayer(
source: mapShapeSource,
strokeColor: Colors.white30,
source: MapShapeSource.asset(
'assets/australia.json',
shapeDataField: 'STATE_NAME',
),
color: Colors.orange,
),
],
);
}
@override
void dispose() {
iceThicknessList?.clear();
super.dispose();
}
}
......@@ -11,11 +11,9 @@ import 'cloropleth_map.dart';
/// its layers, polygons and markers.
class MapContainerWidget extends StatefulWidget {
final List<Measurement> markerList;
final String relation;
const MapContainerWidget({Key? key,
required this.markerList,
required this.relation,
}) : super(key: key);
@override
......@@ -61,7 +59,7 @@ class _MapContainerWidgetState extends State<MapContainerWidget> {
SizedBox(
width: screenWidth * boxWidth,
height: screenWidth * boxHeight,
child: ChoroplethMap(relation: widget.relation)
child: ChoroplethMap(),
/*FlutterMap(
options: MapOptions(
center: mapCenter,
......
......@@ -26,3 +26,5 @@ flutter:
uses-material-design: true
assets:
- assets/icons/
- assets/mjosa.geojson
- assets/australia.json
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment