Development

Contents

Developing A New Tool

Setup

New tools are automatically found and included on start.

  1. Go to plugins/core/tools/

    1. Create a new directory here with the name of your new tool
    2. Create [Your Tool's Name]Tool.js (see tool template in plugins/README.md)
    3. Add a plugin.json file so that MMGIS can find it. Do look at the existing tools’ plugin.json but 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
     }
    
    
  2. Restart the server with npm start

  3. Use the /configure page 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 make and destroy functions.
    • make is called when the user clicks on the tool’s icon while destroy is called when the user clicks on any other tool’s icon.
  • Tools should work independently of one another.
  • Tools should only change the #tools div or something in the viewer, map and/or globe.
  • Use width or height entries to set the tool div’s dimensions.

Developing A New Backend

Setup

New backends are automatically found and included on start.

  1. Go to plugins/core/backend/
    1. Create a new directory here with the name of your new backend
    2. Create plugin.js with lifecycle hooks (see backend template in plugins/README.md)
    3. Create a plugin.json with metadata
    4. Edit plugin.js based on the development guide below
  2. 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.


This site uses Just the Docs, a documentation theme for Jekyll.