diff --git a/app/lib/consts.dart b/app/lib/consts.dart index 041ea98b141259f609c01c99537bd6976563622f..4767d5fbade1ded71268bcfac97f7f1f6d8c47a4 100644 --- a/app/lib/consts.dart +++ b/app/lib/consts.dart @@ -9,6 +9,7 @@ const String mapEndpoint = "update_map"; const int fetchInterval = 60; // Fetch marker data every n minutes // Map variables +String selectedLake = 'Mjøsa'; // Initialise to Mjøsa, NB should be initialised to last selected lake LatLng mapCenter = LatLng(60.8000, 10.8471); DateTime ?lastUpdate; // Last time data was fetched from server diff --git a/app/lib/pages/default_page.dart b/app/lib/pages/default_page.dart index 8e9d3737aa733f26fbf867f976a8b14b73422f2d..5d64a50b3ea512da8ee92c336f90dbc3ddd2c382 100644 --- a/app/lib/pages/default_page.dart +++ b/app/lib/pages/default_page.dart @@ -101,7 +101,7 @@ class _DefaultPageState extends State<DefaultPage> { }, ), title: Text( - 'Mjøsa', + selectedLake, // Display name of current map style: regTextStyleBig, ), actions: [ @@ -112,11 +112,13 @@ class _DefaultPageState extends State<DefaultPage> { ), onPressed: () { showSearch( - context: context, - delegate: _CustomSearchDelegate()); - /*setState(() { - showBar = !showBar; - });*/ + context: context, + delegate: _CustomSearchDelegate((String result) { + setState(() { + selectedLake = result; + }); + }), + ); }, ), ], @@ -146,7 +148,13 @@ class _DefaultPageState extends State<DefaultPage> { } } +typedef SearchResultCallback = void Function(String result); + class _CustomSearchDelegate extends SearchDelegate { + final SearchResultCallback onResultSelected; + + _CustomSearchDelegate(this.onResultSelected); + List<String> searchItems = [ // NB temp values "Mjøsa", "Bogstadsvannet", @@ -183,7 +191,7 @@ class _CustomSearchDelegate extends SearchDelegate { @override Widget buildResults(BuildContext context) { List<String> searchResults = []; - final options = FuzzyOptions(threshold: 0.3, findAllMatches: true); + final options = FuzzyOptions(threshold: 0.4, findAllMatches: true); final matcher = Fuzzy(searchItems, options: options); final results = matcher.search(query); searchResults = results.map((result) => result.item as String).toList(); @@ -192,8 +200,14 @@ class _CustomSearchDelegate extends SearchDelegate { itemCount: searchResults.length, itemBuilder: (context, index) { var result = searchResults[index]; - return ListTile( - title: Text(result), + return GestureDetector( + onTap: () { + onResultSelected(result); + close(context, result); + }, + child: ListTile( + title: Text(result), + ), ); }, ); @@ -202,7 +216,7 @@ class _CustomSearchDelegate extends SearchDelegate { @override Widget buildSuggestions(BuildContext context) { List<String> searchResults = []; - final options = FuzzyOptions(threshold: 0.3, findAllMatches: true); + final options = FuzzyOptions(threshold: 0.4, findAllMatches: true); final matcher = Fuzzy(searchItems, options: options); final results = matcher.search(query); searchResults = results.map((result) => result.item as String).toList(); diff --git a/server/map_handler/process_lake.py b/server/map_handler/process_lake.py index d018938571fa67ee33cadbf333956c064fb8b505..dd0d202b30990c2ec7019fa8bf2d311df793bb2a 100644 --- a/server/map_handler/process_lake.py +++ b/server/map_handler/process_lake.py @@ -1,7 +1,7 @@ import geopandas as gpd -from shapely.geometry import Polygon, LineString, MultiLineString +from shapely.geometry import Polygon, MultiPolygon import json -from server.map.add_lake import write_json_to_file +from server.map_handler.add_lake import write_json_to_file # Writes contents of a map_handler json file to the response