-
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
The draw_circle_element plugin adds the circle_from_center method to mapp.ui.elements.drawing. If defined in the layers edit object, a draw circle from center control will be added to the draw panel of a location view. It is possible to define the default unit and value.
"edit": {
"circle_from_center": {
"units": "km",
"radius": 500
}
}
The hide_layers plugin adds a button to the btn column in the default view. The layer.view.style of layers in the mapviews.layers list which are set to display:false
will be set to display:none
. The style layer group views with all containing layers hidden will also be set to display:none
. Deactivating the hide_layers method will reset the style.display properties. The plugin is activated if the hide_layers flag is set in the workspace locale.
"hide_layers": true
The measure_distance plugin adds a button to the btn column in the default view. If activated, a custom interaction allows to draw a line segment, and shows the length of the geometry as a tooltip. The tooltip and units can be configured with the measure_distance
key in the locale.
"measure_distance": {
"tooltip": "length",
"units": "metric"
}