]> git.openstreetmap.org Git - nominatim.git/blob - lib/template/details-json.php
5513dbd9e8adadb4a427817f4bac50b3b8b52d48
[nominatim.git] / lib / template / details-json.php
1 <?php
2
3 $aPlaceDetails = array();
4
5 $aPlaceDetails['place_id'] = (int) $aPointDetails['place_id'];
6 $aPlaceDetails['parent_place_id'] = (int) $aPointDetails['parent_place_id'];
7
8 $aPlaceDetails['osm_type'] = $aPointDetails['osm_type'];
9 $aPlaceDetails['osm_id'] = (int) $aPointDetails['osm_id'];
10
11 $aPlaceDetails['category'] = $aPointDetails['class'];
12 $aPlaceDetails['type'] = $aPointDetails['type'];
13 $aPlaceDetails['admin_level'] = $aPointDetails['admin_level'];
14
15 $aPlaceDetails['localname'] = $aPointDetails['localname'];
16 $aPlaceDetails['names'] = $aPointDetails['aNames'];
17
18 $aPlaceDetails['addresstags'] = $aPointDetails['aAddressTags'];
19 $aPlaceDetails['housenumber'] = $aPointDetails['housenumber'];
20 $aPlaceDetails['postcode'] = $aPointDetails['postcode']; // computed
21 $aPlaceDetails['country_code'] = $aPointDetails['country_code'];
22
23 $aPlaceDetails['indexed_date'] = $aPointDetails['indexed_date'];
24 $aPlaceDetails['importance'] = (float) $aPointDetails['importance'];
25 $aPlaceDetails['calculated_importance'] = (float) $aPointDetails['calculated_importance'];
26
27 $aPlaceDetails['extratags'] = $aPointDetails['aExtraTags'];
28 $aPlaceDetails['calculated_wikipedia'] = $aPointDetails['wikipedia'];
29 $aPlaceDetails['icon'] = $aPointDetails['icon'];
30
31 $aPlaceDetails['rank_address'] = (int) $aPointDetails['rank_address'];
32 $aPlaceDetails['rank_search'] = (int) $aPointDetails['rank_search'];
33 $aPlaceDetails['rank_search_label'] = $aPointDetails['rank_search_label'];
34
35 $aPlaceDetails['isarea'] = ($aPointDetails['isarea'] == 't');
36 $aPlaceDetails['lat'] = (float) $aPointDetails['lat'];
37 $aPlaceDetails['lon'] = (float) $aPointDetails['lon'];
38
39
40 $aPlaceDetails['geometry'] = json_decode($aPointDetails['asgeojson']);
41
42 $funcMapAddressLines = function ($aFull) {
43     $aMapped = [
44         'localname' => $aFull['localname'],
45         'place_id' => (int) $aFull['place_id'],
46         'osm_id' => (int) $aFull['osm_id'],
47         'osm_type' => formatOSMType($aFull['osm_type']),
48         'class' => $aFull['class'],
49         'type' => $aFull['type'],
50         'admin_level' => (int) $aFull['admin_level'],
51         'rank_address' => (int) $aFull['rank_address'],
52         'distance' => (float) $aFull['distance']
53     ];
54     return $aMapped;
55 };
56
57 $funcMapKeywords = function ($aFull) {
58     $aMapped = [
59         'id' => (int) $aFull['word_id'],
60         'token' => $aFull['word_token']
61     ];
62     return $aMapped;
63 };
64
65 if ($aAddressLines) {
66     $aPlaceDetails['address'] = array_map($funcMapAddressLines, $aAddressLines);
67 }
68
69 if ($aLinkedLines) {
70     $aPlaceDetails['linked_places'] = array_map($funcMapAddressLines, $aLinkedLines);
71 }
72
73 if ($bIncludeKeywords) {
74     $aPlaceDetails['keywords'] = array();
75
76     if ($aPlaceSearchNameKeywords) {
77         $aPlaceDetails['keywords']['name'] = array_map($funcMapKeywords, $aPlaceSearchNameKeywords);
78     }
79
80     if ($aPlaceSearchAddressKeywords) {
81         $aPlaceDetails['keywords']['address'] = array_map($funcMapKeywords, $aPlaceSearchAddressKeywords);
82     }
83 }
84
85 if ($bIncludeChildPlaces) {
86     $aPlaceDetails['parentof'] =  array_map($funcMapAddressLines, $aParentOfLines);
87
88     if ($bGroupChildPlaces) {
89         $aGroupedAddressLines = [];
90         foreach ($aParentOfLines as $aAddressLine) {
91             if ($aAddressLine['type'] == 'yes') $sType = $aAddressLine['class'];
92             else $sType = $aAddressLine['type'];
93
94             if (!isset($aGroupedAddressLines[$sType]))
95                 $aGroupedAddressLines[$sType] = [];
96             $aGroupedAddressLines[$sType][] = $aAddressLine;
97         }
98         $aPlaceDetails['parentof'] = $aGroupedAddressLines;
99     }
100 }
101
102 javascript_renderData($aPlaceDetails);