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