-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnominatim.qml
87 lines (82 loc) · 3.2 KB
/
nominatim.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import QtQuick
import org.qfield
Item {
signal prepareResult(var details)
signal fetchResultsEnded()
function fetchResults(string, context, parameters) {
if (parameters["service_url"] === undefined || string === "") {
fetchResultsEnded();
}
console.log('Fetching results....');
let request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (request.readyState === XMLHttpRequest.DONE) {
let features = FeatureUtils.featuresFromJsonString(request.response)
for (let feature of features) {
let address = feature.attribute("address")
let addressDetails = []
if (address["house_humber"] !== undefined && address["house_number"] !== "")
{
addressDetails.push(address["house_humber"])
}
if (address["road"] !== undefined && address["road"] !== "")
{
addressDetails.push(address["road"])
}
if (address["village"] !== undefined && address["village"] !== "")
{
addressDetails.push(address["village"])
}
if (address["city_district"] !== undefined && address["city_district"] !== "")
{
addressDetails.push(address["city_district"])
}
if (address["town"] !== undefined && address["town"] !== "")
{
addressDetails.push(address["town"])
}
if (address["city"] !== undefined && address["city"] !== "")
{
addressDetails.push(address["city"])
}
if (address["state"] !== undefined && address["state"] !== "")
{
addressDetails.push(address["state"])
}
if (address["country"] !== undefined && address["country"] !== "")
{
addressDetails.push(address["country"])
}
let details = {
"userData": feature,
"displayString": feature.attribute('name'),
"description": addressDetails.join(', '),
"score": 1,
"group": feature.attribute('category').replace('_', ' ') + ': ' + feature.attribute('type').replace('_', ' '),
"groupScore":1,
"actions":[]
}
let actions = []
let extratags = feature.attribute("extratags")
if (extratags["phone"] !== undefined && extratags["phone"] !== "") {
details["actions"].push({
"id": 2,
"name": "Call",
"icon": Qt.resolvedUrl("phone.svg")
})
}
details["actions"].push({
"id": 1,
"name": "Set as destination",
"icon": "qrc:/themes/qfield/nodpi/ic_navigation_flag_purple_24dp.svg"
})
prepareResult(details);
}
fetchResultsEnded()
}
}
let viewbox = GeometryUtils.reprojectRectangle(context.targetExtent, context.targetExtentCrs, CoordinateReferenceSystemUtils.fromDescription(parameters["service_crs"])).toString().replace(" : ", ",")
request.open("GET", parameters["service_url"] + "?q=" + encodeURIComponent(string) + '&viewbox=' + viewbox + '&format=geojson&extratags=1&addressdetails=1&limit=20')
request.send();
}
}