]> git.openstreetmap.org Git - nominatim.git/blob - lib-php/template/address-geojson.php
fix more missing braces on one-liners
[nominatim.git] / lib-php / template / address-geojson.php
1 <?php
2
3 $aFilteredPlaces = array();
4
5 if (empty($aPlace)) {
6     if (isset($sError)) {
7         $aFilteredPlaces['error'] = $sError;
8     } else {
9         $aFilteredPlaces['error'] = 'Unable to geocode';
10     }
11     javascript_renderData($aFilteredPlaces);
12 } else {
13     $aFilteredPlaces = array(
14                         'type' => 'Feature',
15                         'properties' => array()
16                        );
17
18     if (isset($aPlace['place_id'])) {
19         $aFilteredPlaces['properties']['place_id'] = $aPlace['place_id'];
20     }
21     $sOSMType = formatOSMType($aPlace['osm_type']);
22     if ($sOSMType) {
23         $aFilteredPlaces['properties']['osm_type'] = $sOSMType;
24         $aFilteredPlaces['properties']['osm_id'] = $aPlace['osm_id'];
25     }
26
27     $aFilteredPlaces['properties']['place_rank'] = $aPlace['rank_search'];
28
29     $aFilteredPlaces['properties']['category'] = $aPlace['class'];
30     $aFilteredPlaces['properties']['type'] = $aPlace['type'];
31
32     $aFilteredPlaces['properties']['importance'] = $aPlace['importance'];
33
34     $aFilteredPlaces['properties']['addresstype'] = strtolower($aPlace['addresstype']);
35
36     $aFilteredPlaces['properties']['name'] = $aPlace['placename'];
37
38     $aFilteredPlaces['properties']['display_name'] = $aPlace['langaddress'];
39
40     if (isset($aPlace['address'])) {
41         $aFilteredPlaces['properties']['address'] = $aPlace['address']->getAddressNames();
42     }
43     if (isset($aPlace['sExtraTags'])) {
44         $aFilteredPlaces['properties']['extratags'] = $aPlace['sExtraTags'];
45     }
46     if (isset($aPlace['sNameDetails'])) {
47         $aFilteredPlaces['properties']['namedetails'] = $aPlace['sNameDetails'];
48     }
49
50     if (isset($aPlace['aBoundingBox'])) {
51         $aFilteredPlaces['bbox'] = array(
52                                     (float) $aPlace['aBoundingBox'][2], // minlon
53                                     (float) $aPlace['aBoundingBox'][0], // minlat
54                                     (float) $aPlace['aBoundingBox'][3], // maxlon
55                                     (float) $aPlace['aBoundingBox'][1]  // maxlat
56                                    );
57     }
58
59     if (isset($aPlace['asgeojson'])) {
60         $aFilteredPlaces['geometry'] = json_decode($aPlace['asgeojson']);
61     } else {
62         $aFilteredPlaces['geometry'] = array(
63                                         'type' => 'Point',
64                                         'coordinates' => array(
65                                                           (float) $aPlace['lon'],
66                                                           (float) $aPlace['lat']
67                                                          )
68                                        );
69     }
70
71
72     javascript_renderData(array(
73                            'type' => 'FeatureCollection',
74                            'licence' => 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright',
75                            'features' => array($aFilteredPlaces)
76                           ));
77 }