]> git.openstreetmap.org Git - nominatim.git/blob - lib/template/address-geojson.php
search/reverse/lookup with geojson,geocodejson output
[nominatim.git] / lib / 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['aAddress'])) $aFilteredPlaces['properties']['address'] = $aPlace['aAddress'];
37     if (isset($aPlace['sExtraTags'])) $aFilteredPlaces['properties']['extratags'] = $aPlace['sExtraTags'];
38     if (isset($aPlace['sNameDetails'])) $aFilteredPlaces['properties']['namedetails'] = $aPlace['sNameDetails'];
39
40     if (isset($aPlace['aBoundingBox'])) {
41         $aFilteredPlaces['bbox'] = array(
42                                     (float) $aPlace['aBoundingBox'][2], // minlon
43                                     (float) $aPlace['aBoundingBox'][0], // minlat
44                                     (float) $aPlace['aBoundingBox'][3], // maxlon
45                                     (float) $aPlace['aBoundingBox'][1]  // maxlat
46                                    );
47     }
48
49     if (isset($aPlace['asgeojson'])) {
50         $aFilteredPlaces['geometry'] = json_decode($aPlace['asgeojson']);
51     } else {
52         $aFilteredPlaces['geometry'] = array(
53                                         'type' => 'Point',
54                                         'coordinates' => array(
55                                                           (float) $aPlace['lon'],
56                                                           (float) $aPlace['lat']
57                                                          )
58                                        );
59     }
60
61
62     javascript_renderData(array(
63                            'type' => 'FeatureCollection',
64                            'licence' => 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright',
65                            'features' => array($aFilteredPlaces)
66                           ));
67 }