]> git.openstreetmap.org Git - nominatim.git/blob - lib-php/template/details-json.php
convert admin --analyse-indexing to new indexing method
[nominatim.git] / lib-php / template / details-json.php
1 <?php
2 /**
3  * SPDX-License-Identifier: GPL-2.0-only
4  *
5  * This file is part of Nominatim. (https://nominatim.org)
6  *
7  * Copyright (C) 2022 by the Nominatim developer community.
8  * For a full list of authors see the git log.
9  */
10
11 $aPlaceDetails = array();
12
13 $aPlaceDetails['place_id'] = (int) $aPointDetails['place_id'];
14 $aPlaceDetails['parent_place_id'] = (int) $aPointDetails['parent_place_id'];
15
16 $aPlaceDetails['osm_type'] = $aPointDetails['osm_type'];
17 $aPlaceDetails['osm_id'] = (int) $aPointDetails['osm_id'];
18
19 $aPlaceDetails['category'] = $aPointDetails['class'];
20 $aPlaceDetails['type'] = $aPointDetails['type'];
21 $aPlaceDetails['admin_level'] = $aPointDetails['admin_level'];
22
23 $aPlaceDetails['localname'] = $aPointDetails['localname'];
24 $aPlaceDetails['names'] = $aPointDetails['aNames'];
25
26 $aPlaceDetails['addresstags'] = $aPointDetails['aAddressTags'];
27 $aPlaceDetails['housenumber'] = $aPointDetails['housenumber'];
28 $aPlaceDetails['calculated_postcode'] = $aPointDetails['postcode'];
29 $aPlaceDetails['country_code'] = $aPointDetails['country_code'];
30
31 $aPlaceDetails['indexed_date'] = (new DateTime('@'.$aPointDetails['indexed_epoch']))->format(DateTime::RFC3339);
32 $aPlaceDetails['importance'] = (float) $aPointDetails['importance'];
33 $aPlaceDetails['calculated_importance'] = (float) $aPointDetails['calculated_importance'];
34
35 $aPlaceDetails['extratags'] = $aPointDetails['aExtraTags'];
36 $aPlaceDetails['calculated_wikipedia'] = $aPointDetails['wikipedia'];
37 $sIcon = Nominatim\ClassTypes\getIconFile($aPointDetails);
38 if (isset($sIcon)) {
39     $aPlaceDetails['icon'] = $sIcon;
40 }
41
42 $aPlaceDetails['rank_address'] = (int) $aPointDetails['rank_address'];
43 $aPlaceDetails['rank_search'] = (int) $aPointDetails['rank_search'];
44
45 $aPlaceDetails['isarea'] = $aPointDetails['isarea'];
46 $aPlaceDetails['centroid'] = array(
47                               'type' => 'Point',
48                               'coordinates' => array( (float) $aPointDetails['lon'], (float) $aPointDetails['lat'] )
49                              );
50
51 $aPlaceDetails['geometry'] = json_decode($aPointDetails['asgeojson']);
52
53 $funcMapAddressLine = function ($aFull) {
54     return array(
55             'localname' => $aFull['localname'],
56             'place_id' => isset($aFull['place_id']) ? (int) $aFull['place_id'] : null,
57             'osm_id' => isset($aFull['osm_id']) ? (int) $aFull['osm_id'] : null,
58             'osm_type' => isset($aFull['osm_type']) ? $aFull['osm_type'] : null,
59             'place_type' => isset($aFull['place_type']) ? $aFull['place_type'] : null,
60             'class' => $aFull['class'],
61             'type' => $aFull['type'],
62             'admin_level' => isset($aFull['admin_level']) ? (int) $aFull['admin_level'] : null,
63             'rank_address' => $aFull['rank_address'] ? (int) $aFull['rank_address'] : null,
64             'distance' => (float) $aFull['distance'],
65             'isaddress' => isset($aFull['isaddress']) ? (bool) $aFull['isaddress'] : null
66            );
67 };
68
69 $funcMapKeyword = function ($aFull) {
70     return array(
71             'id' => (int) $aFull['word_id'],
72             'token' => $aFull['word_token']
73            );
74 };
75
76 if ($aAddressLines) {
77     $aPlaceDetails['address'] = array_map($funcMapAddressLine, $aAddressLines);
78 }
79
80 if ($aLinkedLines) {
81     $aPlaceDetails['linked_places'] = array_map($funcMapAddressLine, $aLinkedLines);
82 }
83
84 if ($bIncludeKeywords) {
85     $aPlaceDetails['keywords'] = array();
86
87     if ($aPlaceSearchNameKeywords) {
88         $aPlaceDetails['keywords']['name'] = array_map($funcMapKeyword, $aPlaceSearchNameKeywords);
89     } else {
90         $aPlaceDetails['keywords']['name'] = array();
91     }
92
93     if ($aPlaceSearchAddressKeywords) {
94         $aPlaceDetails['keywords']['address'] = array_map($funcMapKeyword, $aPlaceSearchAddressKeywords);
95     } else {
96         $aPlaceDetails['keywords']['address'] = array();
97     }
98 }
99
100 if ($bIncludeHierarchy) {
101     if ($bGroupHierarchy) {
102         $aPlaceDetails['hierarchy'] = array();
103         foreach ($aHierarchyLines as $aAddressLine) {
104             if ($aAddressLine['type'] == 'yes') {
105                 $sType = $aAddressLine['class'];
106             } else {
107                 $sType = $aAddressLine['type'];
108             }
109
110             if (!isset($aPlaceDetails['hierarchy'][$sType])) {
111                 $aPlaceDetails['hierarchy'][$sType] = array();
112             }
113             $aPlaceDetails['hierarchy'][$sType][] = $funcMapAddressLine($aAddressLine);
114         }
115     } else {
116         $aPlaceDetails['hierarchy'] = array_map($funcMapAddressLine, $aHierarchyLines);
117     }
118 }
119
120 javascript_renderData($aPlaceDetails);