]> git.openstreetmap.org Git - nominatim.git/blob - lib-php/template/search-batch-json.php
430237a294a5d33782323fab3d789f5932730436
[nominatim.git] / lib-php / template / search-batch-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 $aOutput = array();
12 $aOutput['licence'] = 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright';
13 $aOutput['batch'] = array();
14
15 foreach ($aBatchResults as $aSearchResults) {
16     if (!$aSearchResults) {
17         $aSearchResults = array();
18     }
19     $aFilteredPlaces = array();
20     foreach ($aSearchResults as $iResNum => $aPointDetails) {
21         $aPlace = array(
22                    'place_id'=>$aPointDetails['place_id'],
23                   );
24
25         $sOSMType = formatOSMType($aPointDetails['osm_type']);
26         if ($sOSMType) {
27             $aPlace['osm_type'] = $sOSMType;
28             $aPlace['osm_id'] = $aPointDetails['osm_id'];
29         }
30
31         if (isset($aPointDetails['aBoundingBox'])) {
32             $aPlace['boundingbox'] = array(
33                                       $aPointDetails['aBoundingBox'][0],
34                                       $aPointDetails['aBoundingBox'][1],
35                                       $aPointDetails['aBoundingBox'][2],
36                 $aPointDetails['aBoundingBox'][3]
37                                      );
38         }
39
40         if (isset($aPointDetails['zoom'])) {
41             $aPlace['zoom'] = $aPointDetails['zoom'];
42         }
43
44         $aPlace['lat'] = $aPointDetails['lat'];
45         $aPlace['lon'] = $aPointDetails['lon'];
46         $aPlace['display_name'] = $aPointDetails['name'];
47         $aPlace['place_rank'] = $aPointDetails['rank_search'];
48
49         $aPlace['category'] = $aPointDetails['class'];
50         $aPlace['type'] = $aPointDetails['type'];
51
52         $aPlace['importance'] = $aPointDetails['importance'];
53
54         if (isset($aPointDetails['icon'])) {
55             $aPlace['icon'] = $aPointDetails['icon'];
56         }
57
58         if (isset($aPointDetails['address'])) {
59             $aPlace['address'] = $aPointDetails['address']->getAddressNames();
60         }
61
62         if (isset($aPointDetails['asgeojson'])) {
63             $aPlace['geojson'] = json_decode($aPointDetails['asgeojson'], true);
64         }
65
66         if (isset($aPointDetails['assvg'])) {
67             $aPlace['svg'] = $aPointDetails['assvg'];
68         }
69
70         if (isset($aPointDetails['astext'])) {
71             $aPlace['geotext'] = $aPointDetails['astext'];
72         }
73
74         if (isset($aPointDetails['askml'])) {
75             $aPlace['geokml'] = $aPointDetails['askml'];
76         }
77
78         $aFilteredPlaces[] = $aPlace;
79     }
80     $aOutput['batch'][] = $aFilteredPlaces;
81 }
82
83 javascript_renderData($aOutput, array('geojson'));