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