]> git.openstreetmap.org Git - nominatim.git/blob - lib-php/template/address-json.php
close DB connection when waiting for next update cycle
[nominatim.git] / lib-php / template / address-json.php
1 <?php
2 /**
3  * SPDX-License-Identifier: GPL-2.0-only
4  *
5  * This file is part of Nominatim. (https://nominatim.org)
6  *
7  * Copyright (C) 2022 by the Nominatim developer community.
8  * For a full list of authors see the git log.
9  */
10
11 $aFilteredPlaces = array();
12
13 if (empty($aPlace)) {
14     if (isset($sError)) {
15         $aFilteredPlaces['error'] = $sError;
16     } else {
17         $aFilteredPlaces['error'] = 'Unable to geocode';
18     }
19 } else {
20     if (isset($aPlace['place_id'])) {
21         $aFilteredPlaces['place_id'] = $aPlace['place_id'];
22     }
23     $aFilteredPlaces['licence'] = 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright';
24     $sOSMType = formatOSMType($aPlace['osm_type']);
25     if ($sOSMType) {
26         $aFilteredPlaces['osm_type'] = $sOSMType;
27         $aFilteredPlaces['osm_id'] = $aPlace['osm_id'];
28     }
29     if (isset($aPlace['lat'])) {
30         $aFilteredPlaces['lat'] = $aPlace['lat'];
31     }
32     if (isset($aPlace['lon'])) {
33         $aFilteredPlaces['lon'] = $aPlace['lon'];
34     }
35
36     if ($sOutputFormat == 'jsonv2' || $sOutputFormat == 'geojson') {
37         $aFilteredPlaces['place_rank'] = $aPlace['rank_search'];
38
39         $aFilteredPlaces['category'] = $aPlace['class'];
40         $aFilteredPlaces['type'] = $aPlace['type'];
41
42         $aFilteredPlaces['importance'] = $aPlace['importance'];
43
44         $aFilteredPlaces['addresstype'] = strtolower($aPlace['addresstype']);
45
46         $aFilteredPlaces['name'] = $aPlace['placename'];
47     }
48
49     $aFilteredPlaces['display_name'] = $aPlace['langaddress'];
50
51     if (isset($aPlace['address'])) {
52         $aFilteredPlaces['address'] = $aPlace['address']->getAddressNames();
53     }
54     if (isset($aPlace['sExtraTags'])) {
55         $aFilteredPlaces['extratags'] = $aPlace['sExtraTags'];
56     }
57     if (isset($aPlace['sNameDetails'])) {
58         $aFilteredPlaces['namedetails'] = $aPlace['sNameDetails'];
59     }
60
61     if (isset($aPlace['aBoundingBox'])) {
62         $aFilteredPlaces['boundingbox'] = $aPlace['aBoundingBox'];
63     }
64
65     if (isset($aPlace['asgeojson'])) {
66         $aFilteredPlaces['geojson'] = json_decode($aPlace['asgeojson'], true);
67     }
68
69     if (isset($aPlace['assvg'])) {
70         $aFilteredPlaces['svg'] = $aPlace['assvg'];
71     }
72
73     if (isset($aPlace['astext'])) {
74         $aFilteredPlaces['geotext'] = $aPlace['astext'];
75     }
76
77     if (isset($aPlace['askml'])) {
78         $aFilteredPlaces['geokml'] = $aPlace['askml'];
79     }
80 }
81
82 javascript_renderData($aFilteredPlaces);