]> git.openstreetmap.org Git - nominatim.git/blob - lib/template/address-geocodejson.php
Merge branch 'deletable-and-polygons-as-json' of https://github.com/mtmail/Nominatim...
[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     if ($aPlace['placename'] !== null) {
34         $aFilteredPlaces['properties']['geocoding']['name'] = $aPlace['placename'];
35     }
36
37     if (isset($aPlace['address'])) {
38         $aPlace['address']->addGeocodeJsonAddressParts(
39             $aFilteredPlaces['properties']['geocoding']
40         );
41
42         $aFilteredPlaces['properties']['geocoding']['admin']
43             = $aPlace['address']->getAdminLevels();
44     }
45
46     if (isset($aPlace['asgeojson'])) {
47         $aFilteredPlaces['geometry'] = json_decode($aPlace['asgeojson']);
48     } else {
49         $aFilteredPlaces['geometry'] = array(
50                                         'type' => 'Point',
51                                         'coordinates' => array(
52                                                           (float) $aPlace['lon'],
53                                                           (float) $aPlace['lat']
54                                                          )
55                                        );
56     }
57
58     javascript_renderData(array(
59                            'type' => 'FeatureCollection',
60                            'geocoding' => array(
61                                            'version' => '0.1.0',
62                                            'attribution' => 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright',
63                                            'licence' => 'ODbL',
64                                            'query' => $sQuery
65                                           ),
66                            'features' => array($aFilteredPlaces)
67                           ));
68 }