]> git.openstreetmap.org Git - nominatim.git/blob - lib-php/template/search-geocodejson.php
Merge pull request #2562 from lonvia/copyright-headers
[nominatim.git] / lib-php / template / search-geocodejson.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                                 'geocoding' => array()
17                                )
18               );
19
20     if (isset($aPointDetails['place_id'])) {
21         $aPlace['properties']['geocoding']['place_id'] = $aPointDetails['place_id'];
22     }
23     $sOSMType = formatOSMType($aPointDetails['osm_type']);
24     if ($sOSMType) {
25         $aPlace['properties']['geocoding']['osm_type'] = $sOSMType;
26         $aPlace['properties']['geocoding']['osm_id'] = $aPointDetails['osm_id'];
27     }
28
29     $aPlace['properties']['geocoding']['type'] = $aPointDetails['type'];
30
31     $aPlace['properties']['geocoding']['label'] = $aPointDetails['langaddress'];
32
33     if ($aPointDetails['placename'] !== null) {
34         $aPlace['properties']['geocoding']['name'] = $aPointDetails['placename'];
35     }
36
37     if (isset($aPointDetails['address'])) {
38         $aPointDetails['address']->addGeocodeJsonAddressParts(
39             $aPlace['properties']['geocoding']
40         );
41
42         $aPlace['properties']['geocoding']['admin']
43             = $aPointDetails['address']->getAdminLevels();
44     }
45
46     if (isset($aPointDetails['asgeojson'])) {
47         $aPlace['geometry'] = json_decode($aPointDetails['asgeojson']);
48     } else {
49         $aPlace['geometry'] = array(
50                                'type' => 'Point',
51                                'coordinates' => array(
52                                                  (float) $aPointDetails['lon'],
53                                                  (float) $aPointDetails['lat']
54                                                 )
55                               );
56     }
57     $aFilteredPlaces[] = $aPlace;
58 }
59
60
61 javascript_renderData(array(
62                        'type' => 'FeatureCollection',
63                        'geocoding' => array(
64                                        'version' => '0.1.0',
65                                        'attribution' => 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright',
66                                        'licence' => 'ODbL',
67                                        'query' => $sQuery
68                                       ),
69                        'features' => $aFilteredPlaces
70                       ));