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