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