diff --git a/app/lib/pages/default_page.dart b/app/lib/pages/default_page.dart index cc43913ffeca68d27044609b98e196fe6d368149..981308634ce92ee9ec5d8ea09f70990b3d9a8b25 100644 --- a/app/lib/pages/default_page.dart +++ b/app/lib/pages/default_page.dart @@ -112,10 +112,26 @@ class _DefaultPageState extends State<DefaultPage> { color: Colors.white54 ), onPressed: () { - showSearch( + showSearch( // Fetch new relation and measurements on search context: context, delegate: CustomSearchDelegate((String result) { setState(() { + markerListFuture = fetchMeasurements().then((fetchResult) { + List<Measurement> measurements = fetchResult.measurements; + serverConnection = fetchResult.connected; + + return measurements; + }).catchError((error) { + serverConnection = false; + throw Exception("Failed to fetch measurements: $error"); + }); + + if (serverConnection){ + relationFuture = fetchRelation(); + } else { // Read last saved data + relationFuture = loadSavedRelation(); + } + selectedLake = result; }); }), diff --git a/app/lib/pages/loading_page.dart b/app/lib/pages/loading_page.dart index 5e19257eb14c71d75de265c76f1409afa071b6c0..4952c3fe8216dce370ea1d12fba9cca98d4ae02f 100644 --- a/app/lib/pages/loading_page.dart +++ b/app/lib/pages/loading_page.dart @@ -1,19 +1,70 @@ import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; + +import 'default_page.dart'; + +class LoadingPage extends StatefulWidget { + const LoadingPage({super.key}); + + @override + State<StatefulWidget> createState() => _LoadingPageState(); +} + +class _LoadingPageState extends State<LoadingPage> + with SingleTickerProviderStateMixin{ + + @override + void initState() { + super.initState(); + // Remove app bar + SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive); + + // Hold loading page for 5 seconds before navigating to the default page + Future.delayed(const Duration(seconds: 5), () { + Navigator.of(context).pushReplacement(MaterialPageRoute( + builder: (_) => const DefaultPage(), + ) + ); + }); + } + + @override + void dispose() { // Add back app bar + super.dispose(); + SystemChrome.setEnabledSystemUIMode( + SystemUiMode.manual, + overlays: SystemUiOverlay.values, + ); + } -class _LoadingPage extends StatelessWidget { @override Widget build(BuildContext context) { - return Container( - decoration: BoxDecoration( // Loading screen - color: Colors.grey[900], - ), - child: Center( - child: Image.asset( - 'assets/icons/frozen.png', // Loading screen icon - // Icon from: https://www.flaticon.com/free-icons/cold-water" - color: Colors.grey, - width: 170, - height: 170, + return Scaffold( + body: Container( + width: double.infinity, + decoration: const BoxDecoration( // Loading screen + gradient: LinearGradient( + colors: [Colors.grey, Colors.black], + begin: Alignment.topLeft, + end: Alignment.bottomRight + ), + ), + child: Column( + children: [ + Image.asset( + 'assets/icons/frozen.png', // Loading screen icon + // Icon from: https://www.flaticon.com/free-icons/cold-water" + color: Colors.grey, + ), + const SizedBox(height: 20), + const Text( + "IceMap", + style: TextStyle( + color: Colors.white70, + fontStyle: FontStyle.italic, + ), + ) + ] ), ), ); diff --git a/server/__pycache__/consts.cpython-311.pyc b/server/__pycache__/consts.cpython-311.pyc index 1712cb5077bfd090a3e860cc1dca4556d993186a..d47db4fadc975e2973e185a82508db4d8429a975 100644 Binary files a/server/__pycache__/consts.cpython-311.pyc and b/server/__pycache__/consts.cpython-311.pyc differ diff --git a/server/main.py b/server/main.py index 587e72a793803f77a01316821ad9aeca80ca3cc7..ac2a8e28dfcf77334b3e8910d63a20a54deae68f 100644 --- a/server/main.py +++ b/server/main.py @@ -5,6 +5,7 @@ from map_handler.get_measurements import get_all_markers from map_handler.add_lake import cut_map from map_handler.process_lake import fetch_divided_map from map_handler.input_new_data import input_new_Lidar_data +from urllib.parse import urlparse, parse_qs import ssl import sqlite3 @@ -37,9 +38,13 @@ class IceHTTP(BaseHTTPRequestHandler): self.wfile.write(b"Root path hit!") elif self.path == '/update_map': # NB: should be POST? + parsed_path = urlparse(self.path) + query_params = parse_qs(parsed_path.query) get_all_markers(self, self.cursor, 'mjosa') # Get all markers # NB: temporary hardcoded waterBodyName elif self.path == '/get_relation': + parsed_path = urlparse(self.path) + query_params = parse_qs(parsed_path.query) fetch_divided_map(self, 'Mjosa') # NB temp hardcoded value elif self.path == '/divide_new_relation': cut_map(self, 'Mjosa') diff --git a/server/map_handler/__pycache__/add_lake.cpython-311.pyc b/server/map_handler/__pycache__/add_lake.cpython-311.pyc index aad95f09ac6501960bb1a2d802fb53b39b25c9f2..9273e1d98fac5a18558f571c266cc29040000aa5 100644 Binary files a/server/map_handler/__pycache__/add_lake.cpython-311.pyc and b/server/map_handler/__pycache__/add_lake.cpython-311.pyc differ diff --git a/server/map_handler/__pycache__/process_lake.cpython-311.pyc b/server/map_handler/__pycache__/process_lake.cpython-311.pyc index 8ac558cf013e2b17c0de9ccb902e44d262c42df9..5a0aa0d8078879c49ca64ebba1a48b02f6626337 100644 Binary files a/server/map_handler/__pycache__/process_lake.cpython-311.pyc and b/server/map_handler/__pycache__/process_lake.cpython-311.pyc differ diff --git a/server/map_handler/add_lake.py b/server/map_handler/add_lake.py index 80bdc2c3bd0bafa717267866f54a08403052c4ff..f8eced82bca76a39eb04e1a06503671b633131ff 100644 --- a/server/map_handler/add_lake.py +++ b/server/map_handler/add_lake.py @@ -138,32 +138,3 @@ def write_json_to_file(path: str, file_name: str, json_data: dict): with open(path + '/' + file_name + '_div.json', 'w') as f: json.dump(json_data, f) - -<<<<<<< HEAD:server/map_handler/add_lake.py - -def get_divided_map(file_name): - geo_data = gpd.read_file("server/map_handler/" + file_name + ".geojson") - polygon_data = geo_data[geo_data['geometry'].geom_type == 'Polygon'] - polygons = [Polygon(polygon.exterior) for polygon in polygon_data['geometry']] - - -# Returns a list of [(sub_div_id, sub_div_center)] -def get_id_and_center(file_name): # NB buggy - # Expected format: [(id, [x,y]), (id, [x,y])] - geo_data = gpd.read_file("server/lake_relations/" + file_name + "_div.json") - subdivisions = [] - for index, row in geo_data.iterrows(): - sub_div_id = row['sub_div_id'] - sub_div_center = row['sub_div_center'] - - print("sub_div_id: ", sub_div_id) - - subdivision = { - 'sub_div_id': sub_div_id, - 'sub_div_center': sub_div_center - } - subdivisions.append(subdivision) - return subdivisions - -======= ->>>>>>> b0c6d9be39ffc9557a93873ab827bf05847ef1c1:server/map/add_lake.py