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