Skip to content

Commit

Permalink
Merge pull request #352 from IGNF/feature/filter-layers-search-by-config
Browse files Browse the repository at this point in the history
Feature/filter layers search by config
  • Loading branch information
elias75015 authored Feb 13, 2025
2 parents 4795786 + eca304f commit 7e4f78b
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 18 deletions.
3 changes: 2 additions & 1 deletion DRAFT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ __DATE__
- Export : mise en conformité DSFR du bouton Export (#334)
- LocationSelector : fenêtre transparente en mode classique et pas assez large en mode DSFR (#349)
- LayerImport : fenêtre d'affichage des getCapabilities agrandie (#349)

- Search : ajout wfs fonctionnel et filtre automatique des suggests selon la configuration si liste non spécifiée (#352)

* 🔒 [Security]


Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "geopf-extensions-openlayers",
"description": "French Geoportal Extensions for OpenLayers libraries",
"version": "1.0.0-beta.2-351",
"date": "07/02/2025",
"version": "1.0.0-beta.2-352",
"date": "12/02/2025",
"module": "src/index.js",
"directories": {},
"engines": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,12 @@
<style>
div#map {
width: 100%;
height: 500px;
height: 800px;
}
</style>
{{/content}}

{{#content "body"}}
<h2>Ajout du moteur de recherche avec les options par défaut</h2>
<p>
Liste des couches prioritaires :
<pre>
PLAN.IGN,
GEOGRAPHICALGRIDSYSTEMS.MAPS.BDUNI.J1,
GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2,
CADASTRALPARCELS.PARCELLAIRE_EXPRESS,
ORTHOIMAGERY.ORTHOPHOTOS
</pre>

Ex. si on saisie 'ortho', la couche "photographies aeriennes" devrait sortir en 1ere position.
</p>
<!-- map -->
<div id="map">
</div>
Expand Down Expand Up @@ -78,6 +65,7 @@ <h2>Ajout du moteur de recherche avec les options par défaut</h2>
searchOptions: {
addToMap: true,
filterServices : "WMTS,WMS,TMS,WFS",
// filterLayers : ["GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2"],
filterLayersPriority : "PLAN.IGN,GEOGRAPHICALGRIDSYSTEMS.MAPS.BDUNI.J1,GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2,CADASTRALPARCELS.PARCELLAIRE_EXPRESS,ORTHOIMAGERY.ORTHOPHOTOS",
filterWMTSPriority : true,
serviceOptions: {
Expand Down
43 changes: 42 additions & 1 deletion src/packages/Controls/SearchEngine/SearchEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import CRS from "../../CRS/CRS";
// import local des layers
import GeoportalWMS from "../../Layers/LayerWMS";
import GeoportalWMTS from "../../Layers/LayerWMTS";
import GeoportalWFS from "../../Layers/LayerWFS";
import GeoportalMapBox from "../../Layers/LayerMapBox";
// Service
import Search from "../../Services/Search";
Expand Down Expand Up @@ -82,6 +83,7 @@ var logger = Logger.getLogger("searchengine");
* @param {String} [options.searchOptions.filterWMTSPriority] - filter on priority WMTS layer in search, each field is separated by a comma. "PLAN.IGN,ORTHOIMAGERY.ORTHOPHOTOS" by default
* @param {Boolean} [options.searchOptions.filterLayersPriority = false] - filter on priority layers in search, false by default
* @param {String} [options.searchOptions.filterVectortiles] - filter on list of search layers only on service TMS, each field is separated by a comma. "PLAN.IGN, ..." by default
* @param {String} [options.searchOptions.filterLayers] - filter on list of search layers list. By Default, the layers available in Config.configuration.layers
* @param {Boolean} [options.searchOptions.updateVectortiles = false] - updating the list of search layers only on service TMS
* @param {Object} [options.searchOptions.serviceOptions] - options of search service
* @param {Sring} [options.searchOptions.serviceOptions.url] - url of service
Expand Down Expand Up @@ -387,7 +389,10 @@ var SearchEngine = class SearchEngine extends Control {
// abonnement au service
Search.target.addEventListener("suggest", (e) => {
logger.debug(e);
this._fillSearchedSuggestListContainer(e.detail);
let suggestResults = e.detail;
// filtre des suggestions selon la configuration ou l'option filterLayers
suggestResults = this._filterResultsFromConfigLayers(suggestResults);
this._fillSearchedSuggestListContainer(suggestResults);
});
}

Expand Down Expand Up @@ -1115,6 +1120,37 @@ var SearchEngine = class SearchEngine extends Control {
}
}

/**
* this method is called by this.() (case of success)
* and clean the results of the suggest list from a list of layers
* by default, the Config.layers list.
*
* @param {Array} suggests - Array of suggested corresponding to search results list
* @returns {Array} suggests - Array of suggested corresponding to search results list filtered by Config
* @private
*/
_filterResultsFromConfigLayers (suggests) {
var layerList = [];
if (this.options.searchOptions.filterLayers) {
layerList = this.options.searchOptions.filterLayers;
} else {
var layersObject = window.Gp.Config.layers;
for (let layer in layersObject) {
if (layersObject.hasOwnProperty(layer)) {
layerList.push(layersObject[layer].name);
}
}
}
let i = suggests.length;
while (i--) {
if (!layerList.includes(suggests[i].name)) {
suggests.splice(i, 1);
}
}
Search.setSuggestions(suggests);
return suggests;
}

/**
* this method is called by this.onAutoCompleteSearch()
* and executes a request to the service.
Expand Down Expand Up @@ -1971,6 +2007,11 @@ var SearchEngine = class SearchEngine extends Control {
layer : name
});
break;
case "WFS":
layer = new GeoportalWFS({
layer : name
});
break;
case "TMS":
layer = new GeoportalMapBox({
layer : name
Expand Down
9 changes: 9 additions & 0 deletions src/packages/Services/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,14 @@ const setIndex = (value) => {
const setFields = (value) => {
m_fields = value;
};
/**
* Renseigne la liste des suggestions
* @param {Array} value - liste des suggestions
* @see m_suggestions
*/
const setSuggestions = (value) => {
m_suggestions = value;
};
/**
* Renseigne le nombre de suggestions du service
* @param {Number} value - le nombre de suggestions du service
Expand Down Expand Up @@ -488,6 +496,7 @@ export default {
getTitles,
setIndex,
setFields,
setSuggestions,
setSize,
setUrl,
setMaximumResponses,
Expand Down

0 comments on commit 7e4f78b

Please sign in to comment.