Geoportal Extension for OpenLayers
API Reference

Class: SearchEngine

ol.control.SearchEngine

SearchEngine control

new SearchEngine(options)

Controls/SearchEngine/SearchEngine.js, line 166
Name Type Description
options Object

control options

Name Type Default Description
apiKey String optional

API key. The key "calcul" is used by default.

ssl Boolean true optional

use of ssl or not (default true, service requested using https protocol)

collapsed Boolean true optional

collapse mode, true by default

collapsible Boolean true optional

force control to be collapsed or not, true by default.

direction String "start" optional

TODO : position of picto, by default : "start"

placeholder String optional

Placeholder in search bar. Default is "Rechercher un lieu, une adresse".

displayMarker Boolean true optional

set a marker on search result, defaults to true.

markerStyle String "lightOrange" optional

Marker style. Currently possible values are "lightOrange" (default value), "darkOrange", "red" and "turquoiseBlue".

markerUrl String "" optional

Marker url. By default, if not specified, use option markerStyle. Otherwise, you can added a http url or a base64 image.

displayButtonAdvancedSearch Boolean false optional

False to disable advanced search tools (it will not be displayed). Default is false (not displayed)

displayButtonGeolocate Boolean false optional

False to disable advanced search tools (it will not be displayed). Default is false (not displayed)

displayButtonCoordinateSearch Boolean false optional

False to disable advanced search tools (it will not be displayed). Default is false (not displayed)

displayButtonClose Boolean true optional

False to disable advanced search tools (it will not be displayed). Default is true (displayed)

coordinateSearch Object optional

coordinates search options.

Name Type Default Description
target DOMElement null optional

TODO : target location of results window. By default under the search bar.

units Array optional

list of coordinates units, to be displayed in control units list.
Values may be "DEC" (decimal degrees), "DMS" (sexagecimal) for geographical coordinates,
and "M" or "KM" for metric coordinates

systems Array optional

list of projection systems, default are Geographical ("EPSG:4326"), Web Mercator ("EPSG:3857") and Lambert 93 ("EPSG:2154").
Each array element (=system) is an object with following properties :

Name Type Description
crs String optional

Proj4 crs alias (from proj4 defs). e.g. : "EPSG:4326". Required

label String optional

CRS label to be displayed in control. Default is crs code (e.g. "EPSG:4326")

type String optional

CRS units type for coordinates conversion : "Geographical" or "Metric". Default: "Geographical"

advancedSearch Object optional

advanced search options for geocoding (filters). Properties can be found among geocode options.filterOptions (see Gp.Services.geocode)

Name Type Default Description
target DOMElement null optional

TODO : target location of results window. By default under the search bar.

resources Object optional

resources to be used by geocode and autocompletion services :

Name Type Default Description
geocode String "location" optional

resources geocoding, by default : "location"

autocomplete Array optional

resources autocompletion, by default : ["PositionOfInterest", "StreetAddress"]

search Boolean false optional

false to disable search service, by default : "false"

searchOptions Object {} optional

options of search service

Name Type Default Description
addToMap Boolean true optional

add layer automatically to map, defaults to true.

filterServices String optional

filter on a list of search services, each field is separated by a comma. "WMTS,TMS" by default

filterWMTSPriority String optional

filter on priority WMTS layer in search, each field is separated by a comma. "PLAN.IGN,ORTHOIMAGERY.ORTHOPHOTOS" by default

filterLayersPriority Boolean false optional

filter on priority layers in search, false by default

filterVectortiles String optional

filter on list of search layers only on service TMS, each field is separated by a comma. "PLAN.IGN, ..." by default

updateVectortiles Boolean false optional

updating the list of search layers only on service TMS

serviceOptions Object optional

options of search service

Name Type Description
url Sring optional

url of service

index String optional

index of search, "standard" by default

fields String optional

list of search fields, each field is separated by a comma. "title,layer_name" by default

size Number optional

number of response in the service. 1000 by default

maximumResponses Number optional

number of results in the response. 10 by default

geocodeOptions Object {} optional

options of geocode service (see Gp.Services.geocode)

Name Type Description
serviceOptions Object optional

options of geocode service

autocompleteOptions Object {} optional

options of autocomplete service (see Gp.Services.autoComplete)

Name Type Default Description
serviceOptions Object optional

options of autocomplete service

triggerGeocode Boolean false optional

trigger a geocoding request if the autocompletion does not return any suggestions, false by default

triggerDelay Number 1000 optional

waiting time before sending the geocoding request, 1000ms by default

zoomTo Sting | Numeric | function optional

zoom to results, by default, current zoom.
Value possible : auto or zoom level.
Possible to overload it with a function :
zoomTo : function (info) {
// do some stuff...
return zoom;
}

TODO
  • option : direction (start|end) de la position du picto (loupe)
  • option : choix du target pour les fenetres geocodage ou recherche par coordonnées
Fires:
  • searchengine:autocomplete:click
  • searchengine:geocode:click
  • searchengine:search:click
  • searchengine:geolocation:click
  • searchengine:coordinates:click
Example
var SearchEngine = ol.control.SearchEngine({
     apiKey : "CLEAPI",
     collapsed : true,
     collapsible : true,
     displayButtonAdvancedSearch : true,
     displayButtonGeolocate : true,
     displayButtonCoordinateSearch : true,
     markerStyle : "lightOrange" // "http://..." or "data/base64..."
     resources : {
         geocode : ["StreetAddress", "PositionOfInterest"],
         autocomplete : ["StreetAddress"],
         search : false
     },
     advancedSearch : {
         target : document.getElementById("dialog"),
         PositionOfInterest : [{name : "municipality", title : "Ville"}],
         StreetAddress : [{...}]
     },
     coordinateSearch : {
         target : null
         systems : [
           {
             "crs" : "EPSG:3857",
             "label" : "Web Mercator",
             "type" : "Metric"
           },
           {
             "crs" : "EPSG:4326",
             "label" : "Géographiques",
             "type" : "Geographical"
           }
         ],
         units : ["DEC", "DMS"]
     },
     geocodeOptions : {},
     autocompleteOptions : {},
     searchOptions : {}
 });

 SearchEngine.on("searchengine:autocomplete:click", function (e) {
   console.warn("autocomplete", e.location);
 });
 SearchEngine.on("searchengine:search:click", function (e) {
   console.warn("search", e.suggest);
 });
 SearchEngine.on("searchengine:geocode:click", function (e) {
   console.warn("geocode", e.location);
 });
 SearchEngine.on("searchengine:geolocation:click", function (e) {
   console.warn("geolocation", e.);
 });
 SearchEngine.on("searchengine:coordinate:click", function (e) {
   console.warn("coordinate", e.);
 });

Extends

  • ol.control.Control

Members

collapsed

{Boolean} specify if searchEngine control is collapsed (true) or not (false)

Methods

_setSystem(system)

Controls/SearchEngine/SearchEngine.js, line 1441

Set additional projection system

Name Type Description
system Object

projection system

Name Type Description
crs String

Proj4 crs alias (from proj4 defs) e.g. "EPSG:4326"

label String optional

CRS label to be displayed in control. Default is system.crs alias

type String optional

CRS units type for coordinates conversion (one of control options.units). Default is "Metric"

getCollapsed(){Boolean}

Controls/SearchEngine/SearchEngine.js, line 242

Returns true if widget is collapsed (minimized), false otherwise

Returns:
- true if widget is collapsed

getContainer(){DOMElement}

Controls/SearchEngine/SearchEngine.js, line 283

Get container

getData(){Object}

Controls/SearchEngine/SearchEngine.js, line 274

Get locations data from geocode service

Returns:
- locations

setCollapsed(collapsed)

Controls/SearchEngine/SearchEngine.js, line 251

Collapse or display widget main container

Name Type Description
collapsed Boolean

True to collapse widget, False to display it

setMap(map)

Controls/SearchEngine/SearchEngine.js, line 213

Overwrite OpenLayers setMap method

Name Type Description
map ol.Map

Map.