Plugin

Add a constant for the plugin id.

src/plugin/tileserver/index.js
1
2
3
4
5
6
goog.declareModuleId('plugin.tileserver');

/**
 * @type {string}
 */
export const ID = 'tileserver';

Add a basic plugin class.

src/plugin/tileserver/tileserverplugin.js
 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
goog.declareModuleId('plugin.tileserver.TileserverPlugin');

import AbstractPlugin from 'opensphere/src/os/plugin/abstractplugin.js';
import PluginManager from 'opensphere/src/os/plugin/pluginmanager.js';

import {ID} from './index.js';

/**
 * Provides Tileserver support
 */
export default class TileserverPlugin extends AbstractPlugin {
  /**
   * Constructor.
   */
  constructor() {
    super();
    this.id = ID;
    this.errorMessage = null;
  }

  /**
   * @inheritDoc
   */
  init() {
    // our plugin doesn't do anything yet
  }
}

// add the plugin to the application
PluginManager.getInstance().addPlugin(new TileserverPlugin());
Internal Plugins
If creating an internal plugin, ensure that mainctrl.js goog.require’s 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 has goog:plugin.tileserver.TileserverPlugin 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.

test/plugin/tileserver/tileserverplugin.test.js
 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.tileserver.TileserverPlugin');

describe('plugin.tileserver.TileserverPlugin', function() {
  const {default: TileserverPlugin} = goog.module.get('plugin.tileserver.TileserverPlugin');

  it('should have the proper ID', function() {
    expect(new TileserverPlugin().id).toBe('tileserver');
  });

  it('should not throw an error', function() {
    const fn = function() {
      const p = new TileserverPlugin();
      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.