var widget = new ol.control.Catalog({
collapsed : true,
draggable : false,
titlePrimary : "",
titleSecondary : "Gérer vos couches de données",
layerLabel : "title",
layerThumbnail : true,
search : {
display : true,
label : "Rechercher une donnée",
criteria : [
"name",
"title",
"description"
]
},
addToMap : true,
categories : [
{
title : "Données",
id : "data",
default : true,
search : false,
filter : null
// sous categories
// items : [
// {
// title : "",
// default : true,
// section : true, // avec section (ex. regroupement par themes)
// icon : true, // icone pour les sections (svg ou lien http ou dsfr classe)
// filter : {
// field : "",
// value : ""
// }
// }
// ]
}
],
configuration : {
type : "json",
urls : [ // data:{}
"https://raw.githubusercontent.com/IGNF/cartes.gouv.fr-entree-carto/main/public/data/layers.json",
"https://raw.githubusercontent.com/IGNF/cartes.gouv.fr-entree-carto/main/public/data/edito.json"
]
}
});
widget.on("catalog:loaded", (e) => { console.log(e.data); });
widget.on("catalog:layer:add", (e) => { console.log(e); });
widget.on("catalog:layer:remove", (e) => { console.log(e); });
map.addControl(widget);
specify if control add some stuff auto
specify all categories
[
{
title : "Données", // title of the category
id : "data", // id of the category
default : true, // if true, this category is selected by default
search : false, // if true, a search bar is displayed for this category
cluster : false, // if true, clustering is activated for this category
filter : null, // filter to apply on the category
items : [ // list of subcategories
{
title : "Toutes les données", // title of the subcategory
id : "all", // id of the subcategory
default : true, // if true, this subcategory is selected by default
icon : true, // icon for the subcategory (svg or http link or dsfr class)
iconJson : [], // list of icons (json) for the sections
cluster : false, // if true, clustering is activated for this subcategory
section : false, // if true, this subcategory has a section
sections : [], // list of sections (filled later)
filter : null, // filter to apply on the subcategory
}
]
}
]
specify the current category selected
specify if control is collapsed (true) or not (false)
specify configuration data (configuration service)
ProtecteddisposedThe object has already been disposed.
specify if control is draggable (true) or not (false)
specify some events listeners
specify all list of layers (configuration service)
list of layers added on map by key pair : name/service
ProtectedlistenerActivate a layer
This method activates a layer by its name and service.
It checks if the layer exists in the layersList and if it does, it adds the layer to the map if addToMap is true.
It then dispatches an event indicating that the layer has been added to the catalog.
Layer name.
Layer service.
Activate a layer by its ID
This method activates a layer based on its ID, which is expected to be in the format "name$service".
It splits the ID to extract the layer name and service, then calls the activeLayer method.
Layer ID in the format "name$service".
Key name.
Listener.
Type.
Listener.
Add a layer config This method processes a configuration object containing layer definitions.
conf
ProtectedapplyProtectedApply any properties from another object without triggering events.
The source object.
Disable a layer
This method disables a layer by its name and service.
It checks if the layer exists in the layersList and if it does, it removes the layer from the map if addToMap is true.
It then dispatches an event indicating that the layer has been removed from the catalog.
Layer name.
Layer service.
Disable a layer by its ID
This method disables a layer based on its ID, which is expected to be in the format "name$service".
It splits the ID to extract the layer name and service, then calls the disableLayer method.
Layer ID in the format "name$service".
Dispatches an event and calls all listeners listening for events
of this type. The event parameter can either be a string or an
Object with a type property.
Event object.
false if anyone called preventDefault on the
event object or if any of the listeners returned false.
Clean up.
ProtecteddisposeProtectedExtension point for disposable objects.
Returns true if widget is collapsed (minimized), false otherwise
collapsed - true if widget is collapsed
Get container
container
Get long layer ID
nom de la couche
service de la couche
Get layers by category
This method filters the layers based on the provided category.
It checks if the category has a filter defined and applies it to the layers.
If the filter matches, the layer is added to the layersCategorised object.
It also updates the categories property of each layer to include the category ID.
Category object containing the filter.
Object containing all layers.
Get the listeners for a specified event type. Listeners are returned in the order that they will be called in.
Type.
Listeners.
Get an object of all property names and values.
Object.
Optionaltype: stringType. If not provided,
true will be returned if this event target has any listeners.
Has listeners.
The object has properties.
Key name.
Old value.
ProtectedonceProtectedonKey name.
Listener.
Type.
Listener.
Collapse or display widget main container
True to collapse widget, False to display it
Overwrite OpenLayers setMap method This method sets the map for the Catalog control. It initializes event listeners for the map and sets up the control's draggable and collapsed states. It also checks for existing layers on the map and updates the control accordingly.
Map instance to set for the control.
This function is used to set a target element for the control. It has no
effect if it is called after the control has been added to the map (i.e.
after setMap is called on the control). If no target is set in the
options passed to the control constructor and if setTarget is not called
then the control is added to the map's overlay container.
Target.
ProtectedunProtectedUnlisten for a certain type of event.
Type.
Listener.
event triggered when layer is added
catalog:layer:add
event triggered when data is loaded
catalog:loaded
event triggered when layer is removed
catalog:layer:remove
options for function call.