]> git.openstreetmap.org Git - nominatim.git/blob - lib/template/details-json.php
show simple query field when no parameters are given
[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['calculated_postcode'] = $aPointDetails['postcode'];
21 $aPlaceDetails['country_code'] = $aPointDetails['country_code'];
22
23 $aPlaceDetails['indexed_date'] = (new DateTime('@'.$aPointDetails['indexed_epoch']))->format(DateTime::RFC3339);
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 if ($aPointDetails['icon']) {
30     $aPlaceDetails['icon'] = CONST_Website_BaseURL.'images/mapicons/'.$aPointDetails['icon'].'.n.32.png';
31 }
32
33 $aPlaceDetails['rank_address'] = (int) $aPointDetails['rank_address'];
34 $aPlaceDetails['rank_search'] = (int) $aPointDetails['rank_search'];
35
36 $aPlaceDetails['isarea'] = $aPointDetails['isarea'];
37 $aPlaceDetails['centroid'] = array(
38                               'type' => 'Point',
39                               'coordinates' => array( (float) $aPointDetails['lon'], (float) $aPointDetails['lat'] )
40                              );
41
42 $aPlaceDetails['geometry'] = json_decode($aPointDetails['asgeojson']);
43
44 $funcMapAddressLine = function ($aFull) {
45     $aMapped = array(
46                 'localname' => $aFull['localname'],
47                 'place_id' => isset($aFull['place_id']) ? (int) $aFull['place_id'] : null,
48                 'osm_id' => isset($aFull['osm_id']) ? (int) $aFull['osm_id'] : null,
49                 'osm_type' => isset($aFull['osm_type']) ? $aFull['osm_type'] : null,
50                 'place_type' => isset($aFull['place_type']) ? $aFull['place_type'] : null,
51                 'class' => $aFull['class'],
52                 'type' => $aFull['type'],
53                 'admin_level' => isset($aFull['admin_level']) ? (int) $aFull['admin_level'] : null,
54                 'rank_address' => $aFull['rank_address'] ? (int) $aFull['rank_address'] : null,
55                 'distance' => (float) $aFull['distance'],
56                 'isaddress' => isset($aFull['isaddress']) ? (bool) $aFull['isaddress'] : null
57                );
58
59     return $aMapped;
60 };
61
62 $funcMapKeyword = function ($aFull) {
63     $aMapped = array(
64                 'id' => (int) $aFull['word_id'],
65                 'token' => $aFull['word_token']
66                );
67     return $aMapped;
68 };
69
70 if ($aAddressLines) {
71     $aPlaceDetails['address'] = array_map($funcMapAddressLine, $aAddressLines);
72 }
73
74 if ($aLinkedLines) {
75     $aPlaceDetails['linked_places'] = array_map($funcMapAddressLine, $aLinkedLines);
76 }
77
78 if ($bIncludeKeywords) {
79     $aPlaceDetails['keywords'] = array();
80
81     if ($aPlaceSearchNameKeywords) {
82         $aPlaceDetails['keywords']['name'] = array_map($funcMapKeyword, $aPlaceSearchNameKeywords);
83     }
84
85     if ($aPlaceSearchAddressKeywords) {
86         $aPlaceDetails['keywords']['address'] = array_map($funcMapKeyword, $aPlaceSearchAddressKeywords);
87     }
88 }
89
90 if ($bIncludeHierarchy) {
91     if ($bGroupHierarchy) {
92         $aPlaceDetails['hierarchy'] = array();
93         foreach ($aHierarchyLines as $aAddressLine) {
94             if ($aAddressLine['type'] == 'yes') $sType = $aAddressLine['class'];
95             else $sType = $aAddressLine['type'];
96
97             if (!isset($aPlaceDetails['hierarchy'][$sType]))
98                 $aPlaceDetails['hierarchy'][$sType] = array();
99             $aPlaceDetails['hierarchy'][$sType][] = $funcMapAddressLine($aAddressLine);
100         }
101     } else {
102         $aPlaceDetails['hierarchy'] = array_map($funcMapAddressLine, $aHierarchyLines);
103     }
104 }
105
106 javascript_renderData($aPlaceDetails);