]> git.openstreetmap.org Git - nominatim.git/blob - lib/template/search-geocodejson.php
Merge remote-tracking branch 'upstream/master'
[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     if ($aPointDetails['placename'] !== null) {
24         $aPlace['properties']['geocoding']['name'] = $aPointDetails['placename'];
25     }
26
27     if (isset($aPointDetails['address'])) {
28         $aPointDetails['address']->addGeocodeJsonAddressParts(
29             $aPlace['properties']['geocoding']
30         );
31
32         $aPlace['properties']['geocoding']['admin']
33             = $aPointDetails['address']->getAdminLevels();
34     }
35
36     if (isset($aPointDetails['asgeojson'])) {
37         $aPlace['geometry'] = json_decode($aPointDetails['asgeojson']);
38     } else {
39         $aPlace['geometry'] = array(
40                                'type' => 'Point',
41                                'coordinates' => array(
42                                                  (float) $aPointDetails['lon'],
43                                                  (float) $aPointDetails['lat']
44                                                 )
45                               );
46     }
47     $aFilteredPlaces[] = $aPlace;
48 }
49
50
51 javascript_renderData(array(
52                        'type' => 'FeatureCollection',
53                        'geocoding' => array(
54                                        'version' => '0.1.0',
55                                        'attribution' => 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright',
56                                        'licence' => 'ODbL',
57                                        'query' => $sQuery
58                                       ),
59                        'features' => $aFilteredPlaces
60                       ));