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

add: search bar result selection

parent 3775c77b
No related branches found
No related tags found
1 merge request!10Clhp map
...@@ -9,6 +9,7 @@ const String mapEndpoint = "update_map"; ...@@ -9,6 +9,7 @@ const String mapEndpoint = "update_map";
const int fetchInterval = 60; // Fetch marker data every n minutes const int fetchInterval = 60; // Fetch marker data every n minutes
// Map variables // 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); LatLng mapCenter = LatLng(60.8000, 10.8471);
DateTime ?lastUpdate; // Last time data was fetched from server DateTime ?lastUpdate; // Last time data was fetched from server
......
...@@ -101,7 +101,7 @@ class _DefaultPageState extends State<DefaultPage> { ...@@ -101,7 +101,7 @@ class _DefaultPageState extends State<DefaultPage> {
}, },
), ),
title: Text( title: Text(
'Mjøsa', selectedLake, // Display name of current map
style: regTextStyleBig, style: regTextStyleBig,
), ),
actions: [ actions: [
...@@ -113,10 +113,12 @@ class _DefaultPageState extends State<DefaultPage> { ...@@ -113,10 +113,12 @@ class _DefaultPageState extends State<DefaultPage> {
onPressed: () { onPressed: () {
showSearch( showSearch(
context: context, context: context,
delegate: _CustomSearchDelegate()); delegate: _CustomSearchDelegate((String result) {
/*setState(() { setState(() {
showBar = !showBar; selectedLake = result;
});*/ });
}),
);
}, },
), ),
], ],
...@@ -146,7 +148,13 @@ class _DefaultPageState extends State<DefaultPage> { ...@@ -146,7 +148,13 @@ class _DefaultPageState extends State<DefaultPage> {
} }
} }
typedef SearchResultCallback = void Function(String result);
class _CustomSearchDelegate extends SearchDelegate { class _CustomSearchDelegate extends SearchDelegate {
final SearchResultCallback onResultSelected;
_CustomSearchDelegate(this.onResultSelected);
List<String> searchItems = [ // NB temp values List<String> searchItems = [ // NB temp values
"Mjøsa", "Mjøsa",
"Bogstadsvannet", "Bogstadsvannet",
...@@ -183,7 +191,7 @@ class _CustomSearchDelegate extends SearchDelegate { ...@@ -183,7 +191,7 @@ class _CustomSearchDelegate extends SearchDelegate {
@override @override
Widget buildResults(BuildContext context) { Widget buildResults(BuildContext context) {
List<String> searchResults = []; 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 matcher = Fuzzy(searchItems, options: options);
final results = matcher.search(query); final results = matcher.search(query);
searchResults = results.map((result) => result.item as String).toList(); searchResults = results.map((result) => result.item as String).toList();
...@@ -192,8 +200,14 @@ class _CustomSearchDelegate extends SearchDelegate { ...@@ -192,8 +200,14 @@ class _CustomSearchDelegate extends SearchDelegate {
itemCount: searchResults.length, itemCount: searchResults.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
var result = searchResults[index]; var result = searchResults[index];
return ListTile( return GestureDetector(
onTap: () {
onResultSelected(result);
close(context, result);
},
child: ListTile(
title: Text(result), title: Text(result),
),
); );
}, },
); );
...@@ -202,7 +216,7 @@ class _CustomSearchDelegate extends SearchDelegate { ...@@ -202,7 +216,7 @@ class _CustomSearchDelegate extends SearchDelegate {
@override @override
Widget buildSuggestions(BuildContext context) { Widget buildSuggestions(BuildContext context) {
List<String> searchResults = []; 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 matcher = Fuzzy(searchItems, options: options);
final results = matcher.search(query); final results = matcher.search(query);
searchResults = results.map((result) => result.item as String).toList(); searchResults = results.map((result) => result.item as String).toList();
......
import geopandas as gpd import geopandas as gpd
from shapely.geometry import Polygon, LineString, MultiLineString from shapely.geometry import Polygon, MultiPolygon
import json 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 # Writes contents of a map_handler json file to the response
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment