]> git.openstreetmap.org Git - nominatim.git/blob - lib/template/search-geocodejson.php
details html page: no longer use place_id in URLs
[nominatim.git] / lib / template / search-geocodejson.php
1 <?php
2
3 $aFilteredPlaces = array();
4 foreach ($aSearchResults as $iResNum => $aPointDetails) {
5     $aPlace = array(
6                'type' => 'Feature',
7                'properties' => array(
8                                 'geocoding' => array()
9                                )
10               );
11
12     if (isset($aPointDetails['place_id'])) $aPlace['properties']['geocoding']['place_id'] = $aPointDetails['place_id'];
13     $sOSMType = formatOSMType($aPointDetails['osm_type']);
14     if ($sOSMType) {
15         $aPlace['properties']['geocoding']['osm_type'] = $sOSMType;
16         $aPlace['properties']['geocoding']['osm_id'] = $aPointDetails['osm_id'];
17     }
18
19     $aPlace['properties']['geocoding']['type'] = $aPointDetails['type'];
20
21     $aPlace['properties']['geocoding']['label'] = $aPointDetails['langaddress'];
22
23     $aPlace['properties']['geocoding']['name'] = $aPointDetails['placename'];
24
25     if (isset($aPointDetails['address'])) {
26         $aFieldMappings = array(
27                            'house_number' => 'housenumber',
28                            'road' => 'street',
29                            'locality' => 'locality',
30                            'postcode' => 'postcode',
31                            'city' => 'city',
32                            'district' => 'district',
33                            'county' => 'county',
34                            'state' => 'state',
35                            'country' => 'country'
36                           );
37
38         $aAddrNames = $aPointDetails['address']->getAddressNames();
39         foreach ($aFieldMappings as $sFrom => $sTo) {
40             if (isset($aAddrNames[$sFrom])) {
41                 $aPlace['properties']['geocoding'][$sTo] = $aAddrNames[$sFrom];
42             }
43         }
44
45         $aPlace['properties']['geocoding']['admin']
46             = $aPointDetails['address']->getAdminLevels();
47     }
48
49     if (isset($aPointDetails['asgeojson'])) {
50         $aPlace['geometry'] = json_decode($aPointDetails['asgeojson']);
51     } else {
52         $aPlace['geometry'] = array(
53                                'type' => 'Point',
54                                'coordinates' => array(
55                                                  (float) $aPointDetails['lon'],
56                                                  (float) $aPointDetails['lat']
57                                                 )
58                               );
59     }
60     $aFilteredPlaces[] = $aPlace;
61 }
62
63
64 javascript_renderData(array(
65                        'type' => 'FeatureCollection',
66                        'geocoding' => array(
67                                        'version' => '0.1.0',
68                                        'attribution' => 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright',
69                                        'licence' => 'ODbL',
70                                        'query' => $sQuery
71                                       ),
72                        'features' => $aFilteredPlaces
73                       ));