diff --git a/action/gis_geocoder_rechercher.php b/action/gis_geocoder_rechercher.php index ad64f56..416fd95 100644 --- a/action/gis_geocoder_rechercher.php +++ b/action/gis_geocoder_rechercher.php @@ -4,8 +4,6 @@ if (!defined('_ECRIRE_INC_VERSION')) { return; } -include_spip('inc/distant'); - /** * Proxy vers le service du geocoder * @@ -16,42 +14,11 @@ include_spip('inc/distant'); */ function action_gis_geocoder_rechercher_dist() { include_spip('inc/modifier'); - - $mode = _request('mode'); - if (!$mode || !in_array($mode, array('search', 'reverse'))) { - return; - } - /* On filtre les arguments à renvoyer à Nomatim (liste blanche) */ $arguments = collecter_requests(array('format', 'q', 'limit', 'addressdetails', 'accept-language', 'lat', 'lon'), array()); - - $geocoder = defined('_GIS_GEOCODER') ? _GIS_GEOCODER : 'photon'; - - if ($geocoder == 'photon') { - unset($arguments['format']); - unset($arguments['addressdetails']); - } - - if (!empty($arguments) && in_array($geocoder, array('photon','nominatim'))) { + include_spip('inc/gis_geocode'); + if ($data = gis_geocode_request(_request('mode'), $arguments)) { header('Content-Type: application/json; charset=UTF-8'); - if ($geocoder == 'photon') { - if (isset($arguments['accept-language'])) { - // ne garder que les deux premiers caractères du code de langue, car les variantes spipiennes comme fr_fem posent problème - $arguments['lang'] = substr($arguments['accept-language'], 0, 2); - unset($arguments['accept-language']); - } - if ($mode == 'search') { - $mode = 'api/'; - } else { - $mode = 'reverse'; - } - $url = 'http://photon.komoot.io/'; - } else { - $url = 'http://nominatim.openstreetmap.org/'; - } - - $url = defined('_GIS_GEOCODER_URL') ? _GIS_GEOCODER_URL : $url; - $data = recuperer_page("{$url}{$mode}?" . http_build_query($arguments)); echo $data; } } diff --git a/gis_pipelines.php b/gis_pipelines.php index 56bcc5b..e5d2890 100755 --- a/gis_pipelines.php +++ b/gis_pipelines.php @@ -139,9 +139,14 @@ function gis_post_edition($flux) { $longitude = round(dms_to_dec($exifs['GPSLongitudeRef'], $intLongDeg, $intLongMin, $intLongSec), 5); } if ($config['geocoder'] == 'on') { - include_spip('inc/distant'); - $url_geocoder = 'http://nominatim.openstreetmap.org/reverse/?format=json&addressdetails=1&accept-language='.urlencode($GLOBALS['meta']['langue_site']).'&lat='.urlencode($latitude).'&lon='.urlencode($longitude); - $json = recuperer_page($url_geocoder); + include_spip('inc/gis_geocode'); + $json = gis_geocode_request('reverse', array( + 'format' => 'json', + 'addressdetails' => 1, + 'accept-language' => $GLOBALS['meta']['langue_site'], + 'lat' => $latitude, + 'lon' => $longitude + )); $geocoder = json_decode($json, true); if (is_array($geocoder)) { $pays = $geocoder['address']['country']; @@ -176,9 +181,14 @@ function gis_post_edition($flux) { $string_recherche .= $iptc['country']; } if (strlen($string_recherche)) { - include_spip('inc/distant'); - $url_geocoder = 'http://nominatim.openstreetmap.org/search/?format=json&addressdetails=1&limit=1&accept-language='.urlencode($GLOBALS['meta']['langue_site']).'&q='.urlencode($string_recherche); - $json = recuperer_page($url_geocoder); + include_spip('inc/gis_geocode'); + $json = gis_geocode_request('search', array( + 'format' => 'json', + 'addressdetails' => 1, + 'limit' => 1, + 'accept-language' => $GLOBALS['meta']['langue_site'], + 'q' => $string_recherche + )); $geocoder = json_decode($json, true); if (is_array($geocoder[0])) { $latitude = $geocoder[0]['lat']; diff --git a/inc/gis_geocode.php b/inc/gis_geocode.php new file mode 100644 index 0000000..27dc314 --- /dev/null +++ b/inc/gis_geocode.php @@ -0,0 +1,53 @@ +