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