diff --git a/package.json b/package.json index 7c8648861..bbdc484b3 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "geoportal-extensions-openlayers", "description": "French Geoportal Extensions for OpenLayers libraries", - "version": "1.0.0-beta.16.29", - "date": "13/05/2024", + "version": "1.0.0-beta.46", + "date": "17/05/2024", "module": "src/index.js", "directories": {}, "engines": { diff --git a/samples-src/pages/tests/SearchEngine/pages-ol-searchengine-modules-options.html b/samples-src/pages/tests/SearchEngine/pages-ol-searchengine-modules-options.html index 9942d191a..0de463507 100644 --- a/samples-src/pages/tests/SearchEngine/pages-ol-searchengine-modules-options.html +++ b/samples-src/pages/tests/SearchEngine/pages-ol-searchengine-modules-options.html @@ -54,6 +54,7 @@

Ajout du moteur de recherche avec les options

var layerSwitcher = new ol.control.LayerSwitcher({}); map.addControl(layerSwitcher); + var bAddToMapAuto = false; // ajout auto d'une couche sur la carte par le service de recherch ! var search = new ol.control.SearchEngine({ collapsed : true, opened : true, @@ -140,6 +141,7 @@

Ajout du moteur de recherche avec les options

} }, searchOptions : { + addToMap : bAddToMapAuto, filterServices : "WMTS,TMS", filterVectortiles : "PLAN.IGN,PCI", updateVectortiles : true, @@ -156,24 +158,28 @@

Ajout du moteur de recherche avec les options

map.addControl(search); search.on("searchengine:search:click", function (e) { console.warn("search", e.suggest, e.error); - var service = e.suggest.service; - var name = e.suggest.name; - var layer = null; - switch (service) { - case "WMTS": - layer = new ol.layer.GeoportalWMTS({ - layer : name - }); - break; - case "TMS": - layer = new ol.layer.GeoportalMapBox({ - layer : name - }); - default: - break; - } - if (layer) { - map.addLayer(layer); + // soit l'exttension ajoute automatiquement la couche + // ou soit on doit le faire mannuellement + if (!bAddToMapAuto) { + var service = e.suggest.service; + var name = e.suggest.name; + var layer = null; + switch (service) { + case "WMTS": + layer = new ol.layer.GeoportalWMTS({ + layer : name + }); + break; + case "TMS": + layer = new ol.layer.GeoportalMapBox({ + layer : name + }); + default: + break; + } + if (layer) { + map.addLayer(layer); + } } }); }; diff --git a/src/packages/Controls/SearchEngine/SearchEngine.js b/src/packages/Controls/SearchEngine/SearchEngine.js index c274f704d..e5060a38f 100644 --- a/src/packages/Controls/SearchEngine/SearchEngine.js +++ b/src/packages/Controls/SearchEngine/SearchEngine.js @@ -22,6 +22,10 @@ import MathUtils from "../../Utils/MathUtils"; import SearchEngineUtils from "../../Utils/SearchEngineUtils"; import GeocodeUtils from "../../Utils/GeocodeUtils"; import CRS from "../../CRS/CRS"; +// import local des layers +import GeoportalWMS from "../../Layers/LayerWMS"; +import GeoportalWMTS from "../../Layers/LayerWMTS"; +import GeoportalMapBox from "../../Layers/LayerMapBox"; // Service import Search from "../../Services/Search"; // DOM @@ -67,6 +71,7 @@ var logger = Logger.getLogger("searchengine"); * @param {Array} [options.resources.autocomplete] - resources autocompletion, by default : ["PositionOfInterest", "StreetAddress"] * @param {Boolean} [options.resources.search = false] - false to disable search service, by default : "false" * @param {Object} [options.searchOptions = {}] - options of search service + * @param {Boolean} [options.searchOptions.addToMap = true] - add layer automatically to map, defaults to true. * @param {String} [options.searchOptions.filterServices] - filter on a list of search services, each field is separated by a comma. "WMTS,TMS" 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 {Boolean} [options.searchOptions.updateVectortiles = false] - updating the list of search layers only on service TMS @@ -263,6 +268,7 @@ var SearchEngine = class SearchEngine extends Control { collapsed : true, opened : false, zoomTo : "", + resources : { geocode : "", autocomplete : [], @@ -275,6 +281,7 @@ var SearchEngine = class SearchEngine extends Control { advancedSearch : {}, coordinateSearch : {}, searchOptions : { + addToMap : true, serviceOptions : {} }, geocodeOptions : { @@ -1818,6 +1825,35 @@ var SearchEngine = class SearchEngine extends Control { suggest : suggest, error : new Error(message) }); + + // Ajout de la couche sur la carte si l'option le permet + if (this.options.searchOptions.addToMap) { + var service = suggest.service; + var name = suggest.name; + var layer = null; + switch (service) { + case "WMS": + layer = new GeoportalWMS({ + layer : name + }); + break; + case "WMTS": + layer = new GeoportalWMTS({ + layer : name + }); + break; + case "TMS": + layer = new GeoportalMapBox({ + layer : name + }); + default: + break; + } + if (layer) { + var map = this.getMap(); + map.addLayer(layer); + } + } } // ################################################################### //