Merge lp:~nik90/unav/reverse-geocode into lp:unav

Proposed by Nekhelesh Ramananthan
Status: Merged
Merged at revision: 46
Proposed branch: lp:~nik90/unav/reverse-geocode
Merge into: lp:unav
Diff against target: 208 lines (+100/-14)
3 files modified
qml/FavoritesPage.qml (+7/-7)
qml/Main.qml (+87/-6)
qml/components/PoiPopup.qml (+6/-1)
To merge this branch: bzr merge lp:~nik90/unav/reverse-geocode
Reviewer Review Type Date Requested Status
costales Approve
JkB Approve
Review via email: mp+291821@code.launchpad.net

Description of the change

This MP implements,
- Reverse geocoding (clicking on a point will now check if it is a just generic point or a POI. If it is a generic point, we just show the address. If it is a POI, we show the POI popup)
- Minor bug fixes

To post a comment you must log in.
Revision history for this message
JkB (joergberroth) wrote :

Hey, thanks a lot for finishing that!!
It's a great feature and it works perfectly!! Great work! Approve!

FavButtons Approve.

clickButtons approve.

Thx Joerg

review: Approve
lp:~nik90/unav/reverse-geocode updated
52. By Nekhelesh Ramananthan

Merged lp:unav

Revision history for this message
costales (costales) wrote :

So great improvement :)

What do you think about a bit smaller font for the address?

Issue:
 1. Click on map (reverse geolocation appears).
 2. Go to favorites and click in one.
 3. Bug: Popup is the previous.
Solution? Clear/Hide popup when user clicks on Route.

Improvement: It's working for a POI from coordinates. Is it possible working to for POIs from Search and Favorites?

Thanks in advance!

review: Needs Fixing
lp:~nik90/unav/reverse-geocode updated
53. By Nekhelesh Ramananthan

hide popover when clicking the menu

Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

Thanks Marcos. Good catch on the bug. I managed to fix it with your suggestion as well.

Revision history for this message
costales (costales) wrote :

+100 |o/
Thanks Nekhelesh!!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'qml/FavoritesPage.qml'
2--- qml/FavoritesPage.qml 2016-04-12 14:07:12 +0000
3+++ qml/FavoritesPage.qml 2016-04-14 19:07:42 +0000
4@@ -294,6 +294,13 @@
5 anchors.horizontalCenter: parent.horizontalCenter
6 spacing: units.gu(2)
7 Button {
8+ text: i18n.tr("Cancel")
9+ onClicked: {
10+ clear()
11+ PopupUtils.close(dialogue)
12+ }
13+ }
14+ Button {
15 text: isOverwriteMode ? i18n.tr("Overwrite") : isAddFavoriteMode ? i18n.tr("Add") : i18n.tr("Update")
16 color: isOverwriteMode ? UbuntuColors.red : UbuntuColors.green
17 enabled: favNameField.text.trim() && (!isAddFavoriteMode ? favoritesPage.favName_edit !== favNameField.text : true)
18@@ -305,13 +312,6 @@
19 PopupUtils.close(dialogue)
20 }
21 }
22- Button {
23- text: i18n.tr("Cancel")
24- onClicked: {
25- clear()
26- PopupUtils.close(dialogue)
27- }
28- }
29 }
30 }
31 }
32
33=== modified file 'qml/Main.qml'
34--- qml/Main.qml 2016-04-13 17:52:10 +0000
35+++ qml/Main.qml 2016-04-14 19:07:42 +0000
36@@ -27,6 +27,7 @@
37 import QtMultimedia 5.0
38 import QtFeedback 5.0
39 import QtSystemInfo 5.0
40+import QtQuick.XmlListModel 2.0
41 import "components"
42 import "js/utils.js" as QmlJs
43
44@@ -172,6 +173,7 @@
45 text: i18n.tr("Route")
46 enabled: navigationPage.buttonsEnabled
47 onTriggered: {
48+ goThereActionPopover.hide();
49 mainPageStack.push(Qt.resolvedUrl("RoutePage.qml"))
50 }
51 }
52@@ -268,6 +270,11 @@
53 mainPageStack.center_onpos = 1;
54 mainPageStack.favPopup = false;
55 goThereActionPopover.show();
56+
57+ // Perform reverse geocoding only when it is a generic marker that the user clicked on the map
58+ if (goThereActionPopover.poiName === "" && goThereActionPopover.osm_id === 'none') {
59+ reverseXmlModel.reverseSearch(mainPageStack.clickedLat, mainPageStack.clickedLng);
60+ }
61 break;
62
63 case "http://hide_popup/":
64@@ -385,7 +392,10 @@
65 ActionIcon {
66 icon.name: "send"
67 enabled: navigationPage.buttonsEnabled
68- onClicked: mainPageStack.push(Qt.resolvedUrl("RoutePage.qml"))
69+ onClicked: {
70+ goThereActionPopover.hide();
71+ mainPageStack.push(Qt.resolvedUrl("RoutePage.qml"))
72+ }
73 }
74
75 ActionIcon {
76@@ -419,22 +429,90 @@
77 onZoomedOut: mainPageStack.executeJavaScript("custom_zoom(-1)")
78 }
79
80+ XmlListModel {
81+ id: reverseXmlModel
82+
83+ readonly property string baseUrl: "https://nominatim.openstreetmap.org/reverse?format=xml&email=costales.marcos@gmail.com&addressdetails=0&extratags=1&zoom=18&namedetails=1&"
84+
85+ function reverseSearch(lat, lon) {
86+ source = (baseUrl + "lat=" + lat + "&lon=" + lon) ;
87+ console.log(source)
88+ }
89+
90+ function clear() {
91+ goThereActionPopover.reverseGeoString = "";
92+ source = "";
93+ }
94+
95+ onStatusChanged: {
96+ if (status === XmlListModel.Error || (status === XmlListModel.Ready && count === 0)) {
97+ goThereActionPopover.reverseGeoString = ""
98+ console.log("Error reverse geocoding the location!")
99+ }
100+
101+ else if (status === XmlListModel.Ready && count > 0) {
102+ // Check if the location returned by reverse geocoding is a POI by looking for the existence of certain parameters
103+ // like cuisine, phone, opening_hours, internet_access, wheelchair etc that do not apply to a generic address.
104+ if (reverseXmlModel.get(0).description || reverseXmlModel.get(0).cuisine || reverseXmlModel.get(0).phone || reverseXmlModel.get(0).opening_hours
105+ || reverseXmlModel.get(0).website && reverseXmlModel.get(0).wheelchair || reverseXmlModel.get(0).internet_access) {
106+
107+ // Check if the name, osm_id and osm_type are valid, otherwise the POI popup will break.
108+ if (reverseXmlModel.get(0).name && reverseXmlModel.get(0).osm_id && reverseXmlModel.get(0).osm_type) {
109+ goThereActionPopover.poiName = reverseXmlModel.get(0).name
110+ goThereActionPopover.osm_id = reverseXmlModel.get(0).osm_id
111+ goThereActionPopover.osm_type = reverseXmlModel.get(0).osm_type.charAt(0).toUpperCase()
112+ goThereActionPopover.phone = reverseXmlModel.get(0).phone
113+ } else {
114+ goThereActionPopover.reverseGeoString = reverseXmlModel.get(0).result
115+ }
116+ }
117+
118+ // If nothing works, fall back to just showing the address in a generic popup
119+ else {
120+ goThereActionPopover.reverseGeoString = reverseXmlModel.get(0).result
121+ }
122+ }
123+ }
124+
125+ source: ""
126+ query: "/reversegeocode"
127+
128+ XmlRole { name: "osm_type"; query: "result/@osm_type/string()" }
129+ XmlRole { name: "osm_id"; query: "result/@osm_id/string()" }
130+ XmlRole { name: "result"; query: "result/string()" }
131+ XmlRole { name: "name"; query: "namedetails/name/string()" }
132+ XmlRole { name: "description"; query: "extratags/tag[@key='description']/@value/string()" }
133+ XmlRole { name: "cuisine"; query: "extratags/tag[@key='cuisine']/@value/string()" }
134+ XmlRole { name: "phone"; query: "extratags/tag[@key='phone']/@value/string()" }
135+ XmlRole { name: "opening_hours"; query: "extratags/tag[@key='opening_hours']/@value/string()" }
136+ XmlRole { name: "website"; query: "extratags/tag[@key='website']/@value/string()" }
137+ XmlRole { name: "internet_access"; query: "extratags/tag[@key='internet_access']/@value/string()" }
138+ XmlRole { name: "wheelchair"; query: "extratags/tag[@key='wheelchair']/@value/string()" }
139+ }
140+
141 PoiPopup {
142 id: goThereActionPopover
143
144 // Dragons be here! Don't change these values
145 hidePosition: -3*height
146 showPosition: navApp.settings.headerVisible ? 0 : -navigationPage.header.height
147- anchors { top: navigationPage.header.bottom; topMargin: hidePosition }
148+ anchors { top: navigationPage.header.bottom }
149
150 height: mainContentLoader.height + 2*mainContentLoader.anchors.margins
151
152+ property string reverseGeoString: ""
153 property string poiName
154 property string osm_type
155 property string osm_id
156 property string website
157 property string phone
158
159+ onIsShownChanged: {
160+ if (!goThereActionPopover.isShown) {
161+ reverseXmlModel.clear()
162+ }
163+ }
164+
165 Loader {
166 id: mainContentLoader
167 sourceComponent: goThereActionPopover.isShown ? (goThereActionPopover.osm_id === 'none' ? genericPopupComponent : poiPopupComponent) : undefined
168@@ -447,12 +525,15 @@
169 spacing: units.gu(2)
170
171 Label {
172- textSize: Label.Large
173+ id: geoCodeLabel
174+ maximumLineCount: 3
175 width: parent.width
176- visible: !goThereActionPopover.poiName
177+ wrapMode: Text.WordWrap
178+ color: UbuntuColors.slate
179 horizontalAlignment: Text.AlignHCenter
180- text: i18n.tr("Coord: %1, %2").arg(parseFloat(mainPageStack.clickedLat).toFixed(5)).arg(parseFloat(mainPageStack.clickedLng).toFixed(5))
181- color: UbuntuColors.slate
182+ textSize: !truncated ? Label.Large : Label.Medium
183+ text: goThereActionPopover.reverseGeoString ? goThereActionPopover.reverseGeoString
184+ : i18n.tr("Coord: %1, %2").arg(parseFloat(mainPageStack.clickedLat).toFixed(5)).arg(parseFloat(mainPageStack.clickedLng).toFixed(5));
185 }
186
187 Row {
188
189=== modified file 'qml/components/PoiPopup.qml'
190--- qml/components/PoiPopup.qml 2016-04-12 18:47:27 +0000
191+++ qml/components/PoiPopup.qml 2016-04-14 19:07:42 +0000
192@@ -37,10 +37,15 @@
193 isShown = false
194 }
195
196+ Component.onCompleted: {
197+ // Without this, the popup hides when the height is changed after the popup is visible
198+ popup.anchors.topMargin = hidePosition
199+ }
200+
201+ // This mouse area is to stop any user input from leaking from the popup into the map.
202 MouseArea {
203 z: -1
204 anchors.fill: parent
205- propagateComposedEvents: true
206 }
207
208 UbuntuNumberAnimation {

Subscribers

People subscribed via source and target branches