Data Provider¶
In OpenSphere, the Add Data window (in its default Source view) shows a tree that is essentially Data Providers (root nodes) and Data Descriptors (leaf nodes). We want to add a Data Provider for our GeoRSS file type.
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | goog.declareModuleId('plugin.georss.GeoRSSProvider');
import FileProvider from 'opensphere/src/os/data/fileprovider.js';
import {ID} from './georss.js';
/**
* GeoRSS file provider.
*/
export default class GeoRSSProvider extends FileProvider {
/**
* Constructor.
*/
constructor() {
super();
}
/**
* @inheritDoc
*/
configure(config) {
super.configure(config);
this.setId(ID);
this.setLabel('GeoRSS Files');
}
/**
* Get the global instance.
* @return {!GeoRSSProvider}
* @export
*/
static getInstance() {
if (!instance) {
instance = new GeoRSSProvider();
}
return instance;
}
}
/**
* Global instance.
* @type {GeoRSSProvider|undefined}
*/
let instance;
|
Here is a quick test for it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | goog.require('plugin.georss.GeoRSSProvider');
describe('plugin.georss.GeoRSSProvider', function() {
const {default: GeoRSSProvider} = goog.module.get('plugin.georss.GeoRSSProvider');
it('should configure properly', function() {
const p = new GeoRSSProvider();
p.configure({
type: 'georss'
});
expect(p.getId()).toBe('georss');
expect(p.getLabel()).toBe('GeoRSS Files');
});
});
|
Run yarn test
to ensure that works. Now let’s register it in the plugin.
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | goog.declareModuleId('plugin.georss.GeoRSSPlugin');
import DataManager from 'opensphere/src/os/data/datamanager.js';
import ProviderEntry from 'opensphere/src/os/data/providerentry.js';
import LayerConfigManager from 'opensphere/src/os/layer/config/layerconfigmanager.js';
import AbstractPlugin from 'opensphere/src/os/plugin/abstractplugin.js';
import PluginManager from 'opensphere/src/os/plugin/pluginmanager.js';
import ImportManager from 'opensphere/src/os/ui/im/importmanager.js';
import {ID} from './georss.js';
import GeoRSSImportUI from './georssimportui.js';
import GeoRSSLayerConfig from './georsslayerconfig.js';
import GeoRSSProvider from './georssprovider.js';
import {TYPE} from './mime.js';
/**
* Provides support for the GeoRSS format.
*/
export default class GeoRSSPlugin extends AbstractPlugin {
/**
* Constructor.
*/
constructor() {
super();
this.id = ID;
this.errorMessage = null;
}
/**
* @inheritDoc
*/
init() {
const lcm = LayerConfigManager.getInstance();
lcm.registerLayerConfig(ID, GeoRSSLayerConfig);
const im = ImportManager.getInstance();
im.registerImportDetails('GeoRSS', true);
im.registerImportUI(TYPE, new GeoRSSImportUI());
// register georss provider type
const dm = DataManager.getInstance();
const title = 'GeoRSS Layers';
dm.registerProviderType(new ProviderEntry(
ID, // the type
GeoRSSProvider, // the class
title, // the title
title // the description
));
}
}
// add the plugin to the application
PluginManager.getInstance().addPlugin(new GeoRSSPlugin());
|
That registers it, but providers are only instantiated if they exist in config (added by either the admin or user in Settings > Data Servers). Let’s add some default config. This file is found by looking at package.json
build.config
’s values. In OpenSphere it happens to be config/settings.json
, however, your project could define a different one (or several config files).
This blurb needs to be in your config.
{
"admin": {
"providers": {
"georss": {
"type": "georss"
}
}
}
}
Similarly to layer configs, providers are instantiated by type. Pull up the debug instance of OpenSphere and drop this in the console to ensure the new provider is there.
const {default: DataManager} = goog.module.get('os.data.DataManager');
const {default: GeoRSSProvider} = goog.module.get('plugin.georss.GeoRSSProvider');
DataManager.getInstance().getProviderRoot().getChildren().filter(
p => p instanceof GeoRSSProvider)
If it is not there, you may have a cache issue with your settings file. You can either navigate to the settings file directly and give it a hard refresh (ctrl/cmd+shift+r in Chrome), clear your full cache, or use the Dev Tools to disable the cache.