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