# Extensions

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.

<figure><img src="/files/lFwweLDdHL4gfLMlAWSC" alt=""><figcaption></figcaption></figure>

NG Extensions are javascript objects that respect an interface (either [JCoreExtension](https://k2geospatial.github.io/jmapcloud-ng-types/latest/interfaces/JCoreExtension.html) or [JAppExtension](https://k2geospatial.github.io/jmapcloud-ng-types/latest/interfaces/JAppExtension.html)) 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](https://k2geospatial.github.io/jmapcloud-ng-types/latest/interfaces/JCoreExtension.html), and a `onPanelCreation` implementation if implementing [JAppExtension](https://k2geospatial.github.io/jmapcloud-ng-types/latest/interfaces/JAppExtension.html).

**Extension life cycle**

Extensions are being "registered" by NG in 2 different ways:

* if included in the JMap NG [startup options](https://docs-jmapserver-lima.k2geospatial.com/v/e/developer/jmap-ng-developer-manual/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](https://k2geospatial.github.io/jmapcloud-ng-types/latest/functions/JMap.Extension.register.html) method, for a Core extension, or [JMap.Application.Extension.register](https://k2geospatial.github.io/jmapcloud-ng-types/latest/functions/JMap.Application.Extension.register.html) 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](/en/jmap-ng/jmap-ng-developer-documentation/examples/add-a-jmap-ng-app-extension.md).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.jmapcloud.io/en/jmap-ng/jmap-ng-developer-documentation/extensions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
