Skip to content

Authoring ​

A plugin is a function in mapp.plugins. A workspace turns it on with a key of the same name; the key's value is the plugin's configuration. The configuration keys are documented in locale plugins.

Kinds of plugin ​

  • Locale plugins run once per mapview, as plugin(locale[key], mapview), for every locale key which names a plugin.[1] They add buttons to mapview.mapButton, panels, or behaviour.
  • Layer plugins run as plugin(layer) in mapp.layer.decorate for every layer key which names a plugin.[2] The layer view does not exist yet.
  • Extensions are not in mapp.plugins. A module adds a method to a registry, eg. a layer format to mapp.layer.formats or an entry type to mapp.ui.locations.entries, or replaces a MAPP method; the tabulator and chartjs plugins add dataview renderers to mapp.ui.utils. See extension points for every registry.

Built in are consent, layer_order and svg_templates from apps/mapp/lib/plugins,[3] and the ui plugins, eg. zoomBtn, login, fullscreen, which ui.js adds to mapp.plugins.[4]

Loading and running ​

mapp.Mapview loads and runs plugins only when locale.syncPlugins is not empty or the locale has svgTemplates.[1:1] Then:

  1. layer.plugins URLs are merged into locale.plugins, without duplicates.
  2. With the mapview option loadPlugins: true (or an array of endings), mapp.utils.loadPlugins(locale.plugins) imports each URL.[5]
  3. The syncPlugins keys run one after another, in order, even without a locale key; their configuration is then undefined.
  4. All other locale keys which name a plugin run in parallel.

loadPlugins imports only URLs ending in .js or .mjs. A URL without http is resolved against the page origin, not mapp.host. A module which fails to load is logged and skipped; the promise always resolves. A plugin which throws is logged and does not stop the mapview. The XYZ API replaces ${NAME} in locale.plugins with the SRC_NAME variable.

Authoring a plugin ​

A plugin module assigns its method on import; loadPlugins does not register exports. A minimal locale plugin which adds a button:

js
// home_button.js
mapp.utils.versionCheck('5.1') || console.warn('home_button needs MAPP v5.1');

mapp.plugins.home_button = (config = {}, mapview) => {
  if (!mapview.mapButton) return;

  mapview.mapButton.append(mapp.utils.html.node`
    <button title=${config.title || mapp.dictionary.home || 'Home'}
      onclick=${() => mapview.Map.getView().setZoom(config.z || 2)}>
      <span class="notranslate material-symbols-outlined">home`);
};
json
"plugins": ["${PLUGINS}/home_button.js"],
"home_button": { "title": "Back to start", "z": 6 }
  • mapp.utils.versionCheck(v) is true when mapp.version is v or newer.[6]
  • Import third party modules with mapp.utils.esmImport('name@version') from esm.sh, not at the top of the plugin.[7]
  • Read texts from mapp.dictionary. Store per user state with mapp.utils.userIndexedDB.
  • A plugin which needs another one first, eg. posthog after consent, is listed after it in syncPlugins.

Plugin repositories ​

GEOLYTIX/mapp/plugins is the public home of shared plugins, eg. tabulator, chartjs, the isoline and routing plugins, and measure_distance.[8] Many were written for earlier MAPP versions; check a plugin against the MAPP version of the deployment before using it.

Serve plugins from a path which names the MAPP version they were written for, eg. v5.0.0/, so a workspace pins the version its deployment runs.

Pitfalls ​

  • A key which names a plugin runs it, whether meant or not. A layer key and a locale key with the same name call the plugin with different arguments.
  • mapp.layer methods with the layer key's name run too, before the plugin.
  • A URL with a query string, eg. plugin.js?v=2, is not loaded.
  • A plugin URL runs in every user's browser; list only sources the deployment controls.

  1. mapview/_mapview.mjs mapviewPromise and executePlugin ↩︎ ↩︎

  2. layer/decorate.mjs ↩︎

  3. plugins/_plugins.mjs ↩︎

  4. ui plugins/_plugins.mjs and ui.mjs ↩︎

  5. utils/loadPlugins.mjs ↩︎

  6. utils/versionCheck.mjs ↩︎

  7. utils/esmImport.mjs ↩︎

  8. GEOLYTIX/mapp plugins directory ↩︎

XYZ v5.1.0. Generated from knowledge/ at dd7a6fa27736502733499c1bf485f15659b10338. Concepts marked draft are not reviewed.