-
Notifications
You must be signed in to change notification settings - Fork 25
Plugins
Plugins can be used to extend the functionality of the mapp and mapp.ui libraries.
Plugins can be defined in the locale object of a workspace.
"plugins": [
"${PLUGINS}/js/plugins/cluster_panel.js",
"${PLUGINS}/js/plugins/measure_distance.js",
"${PLUGINS}/js/plugins/draw_circle_element.js"
]
The loadPlugins util requires an array of plugin locations to be loaded. The script for the default view will load all plugins from the current locale.
The default view script will then check whether any locale keys match plugins methods assigned to mapp.plugins object. Matching plugin methods are executed with the value of the plugin key and the mapview provided as arguments.
await mapp.utils.loadPlugins(locale.plugins);
Object.keys(locale).forEach((key) => {
mapp.plugins[key] && mapp.plugins[key](locale[key], mapview);
});
If a layer object is decorated a check will also be run to check whether custom layer keys match loaded plugins. The layer is provided as argument to the plugin method.
Object.keys(layer).forEach((key) => {
mapp.plugins[key] && mapp.plugins[key](layer);
});
Plugins are modules which export as default an IIFE (Immediately Invoked Function Expression). Plugins maybe methods to be called when a locale is loaded, or a layer is decorated. Plugins may also add custom methods to the mapp.ui library or compose mapp methods from existing methods.
export default (function(){
// This plugin will be called if the locale has the hide_layers key.
mapp.plugins.hide_layers = (options, mapview) => {
// hide_layers script
}
// This plugin will be called if a layer with the compare_locations key is decorated.
mapp.plugins.compare_locations = layer => {
// compare_locations script
}
// A custom panel script will be added to the mapp.ui.layers.panels
mapp.ui.layers.panels.cluster_panel = layer => {
// cluster_panel script
}
})()
The cluster_panel plugin adds the cluster_panel to mapp.ui.layers.panels.
If configured in the layer configuration a panel will be added to the layer view.
"cluster_panel": true