Skip to content

Commit

Permalink
allow to use pois in routing and nearby
Browse files Browse the repository at this point in the history
  • Loading branch information
rinigus committed Sep 2, 2018
1 parent 8dbf51b commit 7d6cb90
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
5 changes: 4 additions & 1 deletion qml/NearbyPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ Page {
onClicked: {
var dialog = app.pageStack.push("RoutePointPage.qml");
dialog.accepted.connect(function() {
if (dialog.page === app.tr("Current position")) {
if (dialog.selectedPoi && dialog.selectedPoi.coordinate) {
page.near = [dialog.selectedPoi.coordinate.longitude, dialog.selectedPoi.coordinate.latitude];
page.nearText = dialog.selectedPoi.title || app.tr("Unnamed point");
} else if (dialog.page === app.tr("Current position")) {
page.near = map.getPosition();
page.nearText = dialog.query;
} else {
Expand Down
10 changes: 8 additions & 2 deletions qml/RoutePage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ Page {
onClicked: {
var dialog = app.pageStack.push("RoutePointPage.qml");
dialog.accepted.connect(function() {
if (dialog.query === app.tr("Current position")) {
if (dialog.selectedPoi && dialog.selectedPoi.coordinate) {
page.from = [dialog.selectedPoi.coordinate.longitude, dialog.selectedPoi.coordinate.latitude];
page.fromText = dialog.selectedPoi.title || app.tr("Unnamed point");
} else if (dialog.query === app.tr("Current position")) {
page.from = map.getPosition();
page.fromText = dialog.query;
} else {
Expand Down Expand Up @@ -118,7 +121,10 @@ Page {
onClicked: {
var dialog = app.pageStack.push("RoutePointPage.qml");
dialog.accepted.connect(function() {
if (dialog.query === app.tr("Current position")) {
if (dialog.selectedPoi && dialog.selectedPoi.coordinate) {
page.to = [dialog.selectedPoi.coordinate.longitude, dialog.selectedPoi.coordinate.latitude];
page.toText = dialog.selectedPoi.title || app.tr("Unnamed point");
} else if (dialog.query === app.tr("Current position")) {
page.to = map.getPosition();
page.toText = dialog.query;
} else {
Expand Down
22 changes: 22 additions & 0 deletions qml/RoutePointPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ Dialog {
property var autocompletions: []
property var completionDetails: []
property var history: []
property var poiCompletionDetails: []
property string prevAutocompleteQuery: "."
property string query: ""
property var selectedPoi: undefined

SilicaListView {
id: listView
Expand Down Expand Up @@ -70,6 +72,8 @@ Dialog {

onClicked: {
listItem.focus = true;
var poi = dialog.poiCompletionDetails[model.place.toLowerCase()];
if (poi) dialog.selectedPoi = poi;
dialog.query = model.place;
dialog.accept();
}
Expand Down Expand Up @@ -160,6 +164,7 @@ Dialog {
var x = map.position.coordinate.longitude || 0;
var y = map.position.coordinate.latitude || 0;
py.call("poor.app.router.geocoder.autocomplete", [query, x, y], function(results) {
if (!dialog) return;
dialog.autocompletePending = false;
if (dialog.status !== PageStatus.Active) return;
results = results || [];
Expand All @@ -183,6 +188,23 @@ Dialog {
dialog.autocompletions,
listView.model.count);

// Find POIs matching the completions
var searchKeys = ["title", "poiType", "address", "postcode", "text", "phone", "link"];
var s = Util.findMatchesInObjects(query, map.pois, searchKeys);
var jointResults = [];
// Limit to max 10 POIs if there are many completions
if (found.length > 20 && s.length > 10)
s = s.slice(0, 9);
// save poi completions details
dialog.poiCompletionDetails = [];
s.map(function (p) {
var txt = p.title || s.address || app.tr("Unnamed point");
dialog.poiCompletionDetails[txt.toLowerCase()] = p;
jointResults.push({"text": txt, "markup": txt});
});

// Merge all completions
found = jointResults.concat(found);
Util.injectMatches(listView.model, found, "place", "text");
viewPlaceholder.enabled = found.length === 0;
}
Expand Down

0 comments on commit 7d6cb90

Please sign in to comment.