]> git.openstreetmap.org Git - nominatim.git/blob - lib-php/template/search-geojson.php
Merge pull request #2391 from lonvia/fix-sonar-issues
[nominatim.git] / lib-php / template / search-geojson.php
1 <?php
2
3 $aFilteredPlaces = array();
4 foreach ($aSearchResults as $iResNum => $aPointDetails) {
5     $aPlace = array(
6                'type' => 'Feature',
7                'properties' => array(
8                                 'place_id'=>$aPointDetails['place_id'],
9                                )
10               );
11
12     $sOSMType = formatOSMType($aPointDetails['osm_type']);
13     if ($sOSMType) {
14         $aPlace['properties']['osm_type'] = $sOSMType;
15         $aPlace['properties']['osm_id'] = $aPointDetails['osm_id'];
16     }
17
18     if (isset($aPointDetails['aBoundingBox'])) {
19         $aPlace['bbox'] = array(
20                            (float) $aPointDetails['aBoundingBox'][2], // minlon
21                            (float) $aPointDetails['aBoundingBox'][0], // minlat
22                            (float) $aPointDetails['aBoundingBox'][3], // maxlon
23                            (float) $aPointDetails['aBoundingBox'][1]  // maxlat
24                           );
25     }
26
27     if (isset($aPointDetails['zoom'])) {
28         $aPlace['properties']['zoom'] = $aPointDetails['zoom'];
29     }
30
31     $aPlace['properties']['display_name'] = $aPointDetails['name'];
32
33     $aPlace['properties']['place_rank'] = $aPointDetails['rank_search'];
34     $aPlace['properties']['category'] = $aPointDetails['class'];
35
36     $aPlace['properties']['type'] = $aPointDetails['type'];
37
38     $aPlace['properties']['importance'] = $aPointDetails['importance'];
39
40     if (isset($aPointDetails['icon']) && $aPointDetails['icon']) {
41         $aPlace['properties']['icon'] = $aPointDetails['icon'];
42     }
43
44     if (isset($aPointDetails['address'])) {
45         $aPlace['properties']['address'] = $aPointDetails['address']->getAddressNames();
46     }
47
48     if (isset($aPointDetails['asgeojson'])) {
49         $aPlace['geometry'] = json_decode($aPointDetails['asgeojson']);
50     } else {
51         $aPlace['geometry'] = array(
52                                'type' => 'Point',
53                                'coordinates' => array(
54                                                  (float) $aPointDetails['lon'],
55                                                  (float) $aPointDetails['lat']
56                                                 )
57                               );
58     }
59
60
61     if (isset($aPointDetails['sExtraTags'])) {
62         $aPlace['properties']['extratags'] = $aPointDetails['sExtraTags'];
63     }
64     if (isset($aPointDetails['sNameDetails'])) {
65         $aPlace['properties']['namedetails'] = $aPointDetails['sNameDetails'];
66     }
67
68     $aFilteredPlaces[] = $aPlace;
69 }
70
71 javascript_renderData(array(
72                        'type' => 'FeatureCollection',
73                        'licence' => 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright',
74                        'features' => $aFilteredPlaces
75                       ));