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