Development
Contents
Developing A New Tool
Setup
New tools are automatically found and included on start.
-
Go to
src/essence/Tools- Create a new directory here with the name of your new tool
- Copy and paste
New Tool Template.jsinto your new directory - Rename the pasted file to
[Your Tool's Name]Tool.js - Add a
config.jsonfile so that MMGIS can find it. Do look at the existing tools’config.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": "essence/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 New Tool Template.js.
- 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
API/Backend- Create a new directory here with the name of your new backend
- Copy and paste
setupTemplate.jsinto your new directory - Rename the pasted file to
setup.js - Edit
setup.jsbased on the development guide below
- Restart the server with
npm start
Developing
Overview
All the code for a backend must stay in its API/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:
- API/Backend/[name]
- models/
- routes/
- setup.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.