]> git.openstreetmap.org Git - nominatim.git/blob - lib/template/search-geocodejson.php
fix phpcs issues
[nominatim.git] / lib / template / search-geocodejson.php
1 <?php
2
3 $aFilteredPlaces = array();
4 foreach ($aSearchResults as $iResNum => $aPointDetails) {
5     $aPlace = array(
6                'type' => 'Feature',
7                'properties' => array(
8                                 'geocoding' => array()
9                                )
10               );
11
12     if (isset($aPointDetails['place_id'])) $aPlace['properties']['geocoding']['place_id'] = $aPointDetails['place_id'];
13     $sOSMType = formatOSMType($aPointDetails['osm_type']);
14     if ($sOSMType) {
15         $aPlace['properties']['geocoding']['osm_type'] = $sOSMType;
16         $aPlace['properties']['geocoding']['osm_id'] = $aPointDetails['osm_id'];
17     }
18
19     $aPlace['properties']['geocoding']['type'] = $aPointDetails['type'];
20
21     $aPlace['properties']['geocoding']['label'] = $aPointDetails['langaddress'];
22
23     $aPlace['properties']['geocoding']['name'] = $aPointDetails['placename'];
24
25     if (isset($aPointDetails['address'])) {
26         $aPointDetails['address']->addGeocodeJsonAddressParts(
27             $aPlace['properties']['geocoding']
28         );
29
30         $aPlace['properties']['geocoding']['admin']
31             = $aPointDetails['address']->getAdminLevels();
32     }
33
34     if (isset($aPointDetails['asgeojson'])) {
35         $aPlace['geometry'] = json_decode($aPointDetails['asgeojson']);
36     } else {
37         $aPlace['geometry'] = array(
38                                'type' => 'Point',
39                                'coordinates' => array(
40                                                  (float) $aPointDetails['lon'],
41                                                  (float) $aPointDetails['lat']
42                                                 )
43                               );
44     }
45     $aFilteredPlaces[] = $aPlace;
46 }
47
48
49 javascript_renderData(array(
50                        'type' => 'FeatureCollection',
51                        'geocoding' => array(
52                                        'version' => '0.1.0',
53                                        'attribution' => 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright',
54                                        'licence' => 'ODbL',
55                                        'query' => $sQuery
56                                       ),
57                        'features' => $aFilteredPlaces
58                       ));