Development
Contents
Developing A New Tool
Setup
New tools are automatically found and included on start.
-
Go to
plugins/core/tools/- Create a new directory here with the name of your new tool
- Create
[Your Tool's Name]Tool.js(see tool template inplugins/README.md) - Add a
plugin.jsonfile so that MMGIS can find it. Do look at the existing tools’plugin.jsonbut here’s a template:
{ "defaultIcon": "a material design icon https://pictogrammers.com/library/mdi/ identifier", "description": "A quick description of the tool's capabilities.", "descriptionFull": { "title": "A longer description of the tool's capabilities.", "example": { "A example object of the configuration variables the tool accepts": "value" } }, "hasVars": true, "name": "{toolName}", "toolbarPriority": 3, "paths": { "{toolName}Tool": "../plugins/core/tools/{toolName}/{toolName}Tool" }, "expandable": false } -
Restart the server with
npm start -
Use the
/configurepage to enable the tool in your development environment
Developing
Overview
Ideally all the code for a tool will be in its [Tool's Name]Tool.js and built off of the template in plugins/README.md.
- All tools must return an object with
makeanddestroyfunctions.makeis called when the user clicks on the tool’s icon whiledestroyis called when the user clicks on any other tool’s icon.
- Tools should work independently of one another.
- Tools should only change the
#toolsdiv or something in the viewer, map and/or globe. - Use
widthorheightentries to set the tool div’s dimensions.
Developing A New Backend
Setup
New backends are automatically found and included on start.
- Go to
plugins/core/backend/- Create a new directory here with the name of your new backend
- Create
plugin.jswith lifecycle hooks (see backend template inplugins/README.md) - Create a
plugin.jsonwith metadata - Edit
plugin.jsbased on the development guide below
- Restart the server with
npm start
Developing
Overview
All the code for a backend must stay in its plugins/core/backend/[name] directory.
- Backends should work independently of one another.
- Use the existing backends as a reference point.
Template Walkthrough
const router = require("./routes/your_router");
Write scripts within you backend directory and import them. Most backends follow the directory structure:
- plugins/core/backend/[name]
- models/
- routes/
- plugin.json
- plugin.js
let setup = {
//Once the app initializes
onceInit: s => {},
//Once the server starts
onceStarted: s => {},
//Once all tables sync
onceSynced: s => {},
envs: [{ name: "ENV_VAR", description: "", required: false, private: false }]
};
onceInit() is called immediately on npm start onceStarted() is called once the http server starts up onceSynced() is called once all table are created/has their existence verified.
The s parameter is an object containing the app and middleware. A common form to attach an API within a setup.js is to fill onceInit() with:
onceInit: (s) => {
s.app.use(
"/API/example",
s.ensureUser(),
s.checkHeadersCodeInjection,
s.setContentType,
s.stopGuests,
importedRouter
);
};
envs help document which environment values the backend uses and logs errors if required environment variables aren’t set. Variables that end with _HOST are for URLs and upon start up they’ll be pinged and there status will be logged.
Please refer to the existing backend directories for further examples.