Extensions
Dernière mise à jour
Dernière mise à jour
K2 Geospatial 2024
Extensions are plug-ins for JMap NG App that extend its functionalities. With the JMap NG API, you can develop your own extensions.
Extensions can add their own UI, typically an icon and a side panel. It is possible to have extensions with a different UI and even with no UI at all.
NG Extensions are javascript objects that respect an interface (either JCoreExtension or JAppExtension) and that are loaded by NG at application startup or project load, depending on the type of the extension. Every extension must have a unique id
property, a initFn
implementation, if implementing JCoreExtension, and a onPanelCreation
implementation if implementing JAppExtension.
Extension life cycle
Extensions are being "registered" by NG in 2 different ways:
if included in the JMap NG startup options, they will be automatically registered by NG.
If loaded from a javascript <script>
tag or via a project load, the extension must register itself. This is typically done in the extension "entry point" by calling the JMap.Extension.register method, for a Core extension, or JMap.Application.Extension.register method, for an Application extension.
The registering process most importantly includes incorporating your extension's redux reducers, if provided, your translation bundle, if provided, and the extension service to expose, if provided.
When NG registers your extension, it automatically calls your extension's initFn
and onPanelCreation
methods. In your initFn
or onPanelCreation
method, you can handle all your extension's initializing process. Once the initFn
method is called, you can start calling NG's API to communicate with it.
Extension unique ID
The Extension Unique ID serves a dual purpose for NG: it used by NG to identifiy and manage the loading process of extensions, while also establishing a connection with a server-side extension. This connection can link your extension to specific JMap projects, optionally allowing for the transmission of configuration data to your extension during project loading. The nature of your unique id thus depends on your way of deploying it.
How to deploy your extension
Once your extension is ready to deploy, you can compile it and host it on any CDN of your choice. If your extension is loaded via a project, the URL of your CDN will be configured in the server-side part of your extension. If you include your extension as a <script>
tag in an HTML page, you will be able to use the CDN's url. In all cases, this url should always be accessible from the location where NG will run.
You can see a full extension example here.