Legend#
Set Legend#
To set a legend for a specific plugin, plugins can use the setLegend method in legend object returned by window.minerva.plugins.registerPlugin. This method takes one argument:
- legend: an array containing image urls
Example of setLegend method usage:#
const {
element,
legend: { setLegend },
} = minerva.plugins.registerPlugin({
pluginName,
pluginVersion,
pluginUrl,
});
setLegend([
'https://pdmap.uni.lu/minerva/resources/images/legend_d.png',
'https://pdmap.uni.lu/minerva/resources/images/legend_a.png',
'https://pdmap.uni.lu/minerva/resources/images/legend_b.png',
]);Remove Legend#
To remove a legend associated with a specific plugin, plugins can use the removeLegend method in the legend object returned by window.minerva.plugins.registerPlugin.
Example of removeLegend method usage:#
const {
element,
legend: { removeLegend },
} = minerva.plugins.registerPlugin({
pluginName,
pluginVersion,
pluginUrl,
});
removeLegend();Get Legend#
To read the legend set by the plugin, plugins can use the getLegend method in the legend object returned by window.minerva.plugins.registerPlugin. It returns the array of image urls set with setLegend, or undefined if the plugin has not set a legend or removed it with removeLegend. Only the plugin itself changes the result: MINERVA removes the legend of a plugin only when the plugin is unloaded.
Example of getLegend method usage:#
const {
element,
legend: { getLegend },
} = minerva.plugins.registerPlugin({
pluginName,
pluginVersion,
pluginUrl,
});
getLegend(); // ['https://example.com/legend_a.png'] or undefinedIs Legend Active#
To check whether the user is looking at the legend of the plugin, plugins can use the isLegendActive method in the legend object returned by window.minerva.plugins.registerPlugin. It returns true when the legend is open and the legend tab of the plugin is the one shown, and false when the legend is closed, another tab is selected, or the plugin has no legend. The result is a snapshot at the moment of the call: the user can switch tabs or close the legend at any time.
Example of isLegendActive method usage:#
const {
element,
legend: { isLegendActive },
} = minerva.plugins.registerPlugin({
pluginName,
pluginVersion,
pluginUrl,
});
if (isLegendActive()) {
// the user is looking at the legend of this plugin
}Show and hide the legend#
The legend is an overlay at the bottom of the map, independent of the side panels: it can be open at the same time as any panel, and opening or closing it does not change the result of window.minerva.interface.getOpenedPanel(). Its visibility is controlled with the window.minerva.legend object:
open()- shows the legend; does nothing if it is already openclose()- hides the legend; does nothing if it is already closedisOpen()- returnstrueif the legend is currently visible
Example of legend visibility methods usage:#
window.minerva.legend.open();
window.minerva.legend.isOpen(); // true
window.minerva.legend.close();