Plugin¶
Add a basic plugin class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | goog.declareModuleId('plugin.georss.GeoRSSPlugin');
import AbstractPlugin from 'opensphere/src/os/plugin/abstractplugin.js';
import PluginManager from 'opensphere/src/os/plugin/pluginmanager.js';
import {ID} from './georss.js';
/**
* Provides support for the GeoRSS format.
*/
export default class GeoRSSPlugin extends AbstractPlugin {
/**
* Constructor.
*/
constructor() {
super();
this.id = ID;
this.errorMessage = null;
}
/**
* @inheritDoc
*/
init() {
// plugin does not do anything yet
}
}
// add the plugin to the application
PluginManager.getInstance().addPlugin(new GeoRSSPlugin());
|
- Internal Plugins
- If creating an internal plugin, ensure that
mainctrl.js
imports your plugin, or optionally, the external plugin method will also work. - External Plugins
- If creating an external plugin, ensure that
package.json
build.gcc.entry_point
hasgoog:plugin.georss.GeoRSSPlugin
in its list.
Run yarn build
in OpenSphere (not in your plugin if it is external). It should build just fine but it does not do anything yet.
Just for good measure, let’s test it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | // os.mock sets up a bunch of basic opensphere APIs, like settings, which is
// used in our example plugin
goog.require('os.mock');
goog.require('plugin.georss.GeoRSSPlugin');
describe('plugin.georss.GeoRSSPlugin', function() {
const {default: GeoRSSPlugin} = goog.module.get('plugin.georss.GeoRSSPlugin');
it('should have the proper ID', function() {
expect(new GeoRSSPlugin().id).toBe('georss');
});
it('should not throw an error', function() {
var fn = function() {
var p = new GeoRSSPlugin();
p.init();
};
expect(fn).not.toThrow();
});
});
|
Run yarn test
in your plugin project if it is external (not in OpenSphere) to run its tests. For internal plugins, no directory change is necessary.