From 4adf5dddc57c236f533fcd41d7d32f4f9af624b8 Mon Sep 17 00:00:00 2001 From: Nicolas Boisteault Date: Mon, 7 Oct 2024 15:51:09 +0200 Subject: [PATCH] IGN search string length must be between 3 and 200 chars (#4840) This can be tested here: https://data.geopf.fr/geocodage/completion/?text=fo&type=StreetAddress&maximumResponses=10&bbox=3.875336983791886,43.61120191129432,3.8782264085648497,43.613350750790985 --- assets/src/modules/Search.js | 11 ++++++++--- .../view/locales/en_US/dictionnary.UTF-8.properties | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/assets/src/modules/Search.js b/assets/src/modules/Search.js index b1a6e7b0d6..5e0d95fac8 100644 --- a/assets/src/modules/Search.js +++ b/assets/src/modules/Search.js @@ -185,10 +185,11 @@ export default class Search { // Format answers to highlight searched keywords var labrex = this._getHighlightRegEx(); + const searchQuery = document.getElementById('search-query').value; switch (searchConfig.service) { case 'nominatim': $.get(service - , { "query": $('#search-query').val(), "bbox": extent.toBBOX() } + , { "query": searchQuery, "bbox": extent.toBBOX() } , data => { var text = ''; var count = 0; @@ -220,8 +221,12 @@ export default class Search { }, 'json'); break; case 'ign': + if (searchQuery.length < 3 || searchQuery.length > 200) { + lizMap.addMessage(lizDict['externalsearch.ignlimit'], 'warning', true); + break; + } let mapExtent4326 = transformExtent(mainLizmap.map.getView().calculateExtent(), mainLizmap.projection, 'EPSG:4326'); - let queryParam = '?text=' + $('#search-query').val() + '&type=StreetAddress&maximumResponses=10&bbox=' + mapExtent4326 + let queryParam = '?text=' + searchQuery + '&type=StreetAddress&maximumResponses=10&bbox=' + mapExtent4326 $.getJSON(encodeURI(service + queryParam), data => { let text = ''; let count = 0; @@ -238,7 +243,7 @@ export default class Search { break; case 'google': service.geocode({ - 'address': $('#search-query').val(), + 'address': searchQuery, 'bounds': new google.maps.LatLngBounds( new google.maps.LatLng(extent.top, extent.left), new google.maps.LatLng(extent.bottom, extent.right) diff --git a/lizmap/modules/view/locales/en_US/dictionnary.UTF-8.properties b/lizmap/modules/view/locales/en_US/dictionnary.UTF-8.properties index d2aa9036be..ad6f5f8444 100644 --- a/lizmap/modules/view/locales/en_US/dictionnary.UTF-8.properties +++ b/lizmap/modules/view/locales/en_US/dictionnary.UTF-8.properties @@ -81,6 +81,7 @@ externalsearch.search=Searching externalsearch.notfound=No results externalsearch.mapdata=Map data externalsearch.noquery=Search query is empty +externalsearch.ignlimit=IGN search must contain between 3 and 200 characters timemanager.toolbar.play=Play timemanager.toolbar.pause=Pause