From 50f6e8de6f7f0bdc3527030b4d9049ab45761cd2 Mon Sep 17 00:00:00 2001 From: rmartin Date: Thu, 30 Nov 2023 11:18:37 +0100 Subject: [PATCH] use IGN geoplateforme geocode completion service --- assets/src/legacy/search.js | 80 +++++++++---------------------------- 1 file changed, 18 insertions(+), 62 deletions(-) diff --git a/assets/src/legacy/search.js b/assets/src/legacy/search.js index 9a3d46c19e..efe3b3fa45 100644 --- a/assets/src/legacy/search.js +++ b/assets/src/legacy/search.js @@ -1,3 +1,5 @@ +import {transformExtent} from 'ol/proj.js'; + var lizSearch = function() { // Attributes @@ -195,7 +197,7 @@ var lizSearch = function() { } break; case 'ign': - service = 'https://wxs.ign.fr/essentiels/geoportail/ols?'; + service = 'https://data.geopf.fr/geocodage/completion/'; break; case 'google': if ( google && 'maps' in google && 'Geocoder' in google.maps ){ @@ -248,67 +250,21 @@ var lizSearch = function() { }, 'json'); break; case 'ign': - var xmlIGN = ''; - xmlIGN += ''; - xmlIGN += ''; - xmlIGN += ''; - xmlIGN += ''; - xmlIGN += ''; - - $.get( - encodeURI(service+'xls='+xmlIGN) - ,function(xml) { - var text = ''; - var count = 0; - - $(xml).find("GeocodedAddress").each(function () { - if (count > 9){ - return false; - } - var bbox = $(this).find("Place[type=Bbox]").text().split(';'); - - var number = $(this).find("Building").attr('number'); - var street = $(this).find("Street").text(); - var municipality = $(this).find("Place[type=Municipality]").text(); - var departement = $(this).find("Place[type=Departement]").text(); - - var formatted_address = ''; - - if(number && number !== ''){ - formatted_address += number + ' '; - } - if(street !== ''){ - formatted_address += street + ', '; - } - if(municipality !== ''){ - formatted_address += municipality + ', '; - } - if(departement !== ''){ - formatted_address += departement; - } - - bbox = new OpenLayers.Bounds(bbox); - if ( extent.intersectsBounds(bbox) ) { - var lab = formatted_address.replace(labrex,'$1'); - text += '
  • '+lab+'
  • '; - count++; - } - - }); - if (count == 0 || text == ''){ - text = '
  • '+lizDict['externalsearch.notfound']+'
  • '; - } - updateExternalSearch( '
  • IGN
  • ' ); - }); + let mapExtent4326 = transformExtent(lizMap.mainLizmap.map.getView().calculateExtent(), lizMap.mainLizmap.projection, 'EPSG:4326'); + let queryParam = '?text='+$('#search-query').val()+'&type=StreetAddress&maximumResponses=10&bbox='+mapExtent4326 + $.getJSON(encodeURI(service+queryParam), function(data ) { + let text = ''; + let count = 0; + for( const result of data.results) { + var lab = result.fulltext.replace(labrex,'$1'); + text += '
  • '+lab+'
  • '; + count++; + } + if (count == 0 || text == ''){ + text = '
  • '+lizDict['externalsearch.notfound']+'
  • '; + } + updateExternalSearch( '
  • IGN
  • ' ); + }); break; case 'google': service.geocode( {