]> git.openstreetmap.org Git - nominatim.git/blob - lib-php/template/address-geojson.php
always use brackets on if statements
[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'])) $aFilteredPlaces['properties']['place_id'] = $aPlace['place_id'];
19     $sOSMType = formatOSMType($aPlace['osm_type']);
20     if ($sOSMType) {
21         $aFilteredPlaces['properties']['osm_type'] = $sOSMType;
22         $aFilteredPlaces['properties']['osm_id'] = $aPlace['osm_id'];
23     }
24
25     $aFilteredPlaces['properties']['place_rank'] = $aPlace['rank_search'];
26
27     $aFilteredPlaces['properties']['category'] = $aPlace['class'];
28     $aFilteredPlaces['properties']['type'] = $aPlace['type'];
29
30     $aFilteredPlaces['properties']['importance'] = $aPlace['importance'];
31
32     $aFilteredPlaces['properties']['addresstype'] = strtolower($aPlace['addresstype']);
33
34     $aFilteredPlaces['properties']['name'] = $aPlace['placename'];
35
36     $aFilteredPlaces['properties']['display_name'] = $aPlace['langaddress'];
37
38     if (isset($aPlace['address'])) {
39         $aFilteredPlaces['properties']['address'] = $aPlace['address']->getAddressNames();
40     }
41     if (isset($aPlace['sExtraTags'])) {
42         $aFilteredPlaces['properties']['extratags'] = $aPlace['sExtraTags'];
43     }
44     if (isset($aPlace['sNameDetails'])) {
45         $aFilteredPlaces['properties']['namedetails'] = $aPlace['sNameDetails'];
46     }
47
48     if (isset($aPlace['aBoundingBox'])) {
49         $aFilteredPlaces['bbox'] = array(
50                                     (float) $aPlace['aBoundingBox'][2], // minlon
51                                     (float) $aPlace['aBoundingBox'][0], // minlat
52                                     (float) $aPlace['aBoundingBox'][3], // maxlon
53                                     (float) $aPlace['aBoundingBox'][1]  // maxlat
54                                    );
55     }
56
57     if (isset($aPlace['asgeojson'])) {
58         $aFilteredPlaces['geometry'] = json_decode($aPlace['asgeojson']);
59     } else {
60         $aFilteredPlaces['geometry'] = array(
61                                         'type' => 'Point',
62                                         'coordinates' => array(
63                                                           (float) $aPlace['lon'],
64                                                           (float) $aPlace['lat']
65                                                          )
66                                        );
67     }
68
69
70     javascript_renderData(array(
71                            'type' => 'FeatureCollection',
72                            'licence' => 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright',
73                            'features' => array($aFilteredPlaces)
74                           ));
75 }