Skip to content

Commit

Permalink
feat(SearchEngine): Ajout d'une couche sur la carte sur une sélection…
Browse files Browse the repository at this point in the history
… du service de recherche (#46)
  • Loading branch information
lowzonenose authored May 17, 2024
1 parent 4425bad commit f96d65c
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 20 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ <h2>Ajout du moteur de recherche avec les options</h2>
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,
Expand Down Expand Up @@ -140,6 +141,7 @@ <h2>Ajout du moteur de recherche avec les options</h2>
}
},
searchOptions : {
addToMap : bAddToMapAuto,
filterServices : "WMTS,TMS",
filterVectortiles : "PLAN.IGN,PCI",
updateVectortiles : true,
Expand All @@ -156,24 +158,28 @@ <h2>Ajout du moteur de recherche avec les options</h2>
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);
}
}
});
};
Expand Down
36 changes: 36 additions & 0 deletions src/packages/Controls/SearchEngine/SearchEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -263,6 +268,7 @@ var SearchEngine = class SearchEngine extends Control {
collapsed : true,
opened : false,
zoomTo : "",

resources : {
geocode : "",
autocomplete : [],
Expand All @@ -275,6 +281,7 @@ var SearchEngine = class SearchEngine extends Control {
advancedSearch : {},
coordinateSearch : {},
searchOptions : {
addToMap : true,
serviceOptions : {}
},
geocodeOptions : {
Expand Down Expand Up @@ -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);
}
}
}

// ################################################################### //
Expand Down

0 comments on commit f96d65c

Please sign in to comment.