| type | Guide | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| title | Extension points | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description | The registries plugins extend with layer formats, theme, entry, filter and icon types, panels and dataviews, and how to replace or wrap a MAPP method; use when a plugin adds a type or changes core behaviour. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| resource | ../../apps/mapp/lib/mapp.mjs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tags |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| status | draft | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sources |
|
mapp.mjs assigns the MAPP library to globalThis.mapp, and ui.mjs adds
mapp.ui.1 Core modules call each other through this object, eg.
mapp.layer.formats[layer.format](layer), and look the method up when they
call it. A plugin changes MAPP by assigning to it: a
new key in a registry adds a type, a new value for an existing key replaces
a method. ui.mjs does the same: it replaces mapp.utils.alert,
mapp.utils.confirm and mapp.layer.drawLegend with ui versions.2
A workspace value selects a method from a registry. A plugin adds a value by adding the method; the workspace key then accepts it.
| Registry | Called as | Selected by |
|---|---|---|
mapp.layer.formats |
(layer) |
layer.format3 |
mapp.layer.featureFormats |
(layer, features) |
layer.featureFormat4 |
mapp.layer.themes |
(theme, feature), optional .retain(theme, featuresObject) |
theme.type5 |
mapp.ui.layers.legends |
(layer) |
theme.type6 |
mapp.layer.featureFields.distribution |
(layer) |
theme.distribution7 |
mapp.utils.svgSymbols |
(icon, feature), returns an SVG |
style.icon.type8 |
mapp.ui.locations.entries |
(entry), returns an element |
entry.type9 |
mapp.ui.layers.filters |
(layer, filter) |
entry.filter.type10 |
mapp.ui.layers.panels |
(layer), returns a panel |
a layer key11 |
mapp.ui.utils[name].create |
(dataview) |
dataview.dataview, or chart and table12 |
mapp.layer, mapp.plugins |
(layer) |
a layer key3 |
mapp.plugins |
(config, mapview) |
a locale key; see plugins |
A theme type needs a method in mapp.layer.themes to style features and one
in mapp.ui.layers.legends to draw its legend. A layer with an unknown
layer.format is skipped and a theme with an unknown type is ignored, each
with a warning; an unknown entry type renders nothing.
mapp.layer.featureFormats and mapp.utils.svgSymbols are module
namespaces, which cannot be extended. Replace them with a copy:
mapp.utils.svgSymbols = {
...mapp.utils.svgSymbols,
star: (icon) => `<svg …>`,
};The workspace schemas list the core values of these
keys as examples, not as an enum, so a workspace with a plugin's value
passes the strict schema.
Assign a function to replace a method. To keep the core behaviour, keep a reference to the original and call it:
const decorate = mapp.layer.decorate;
mapp.layer.decorate = async (layer) => {
layer.attribution ??= { 'My data': 'https://example.org' };
return decorate(layer);
};mapp.utils.compose(f, g) returns a function which passes its argument
through f and then g; each function takes and returns one value. Bind
the original to compose it into itself:
mapp.layer.decorate = mapp.utils.compose(mapp.layer.decorate.bind(), logLayer);
logLayer then receives the promise of the decorated layer.13
Plugin modules assign on import. mapp.Mapview imports the URLs in
locale.plugins and layer.plugins before it runs the plugins and before a
view adds layers, so registrations are in place when layers are
decorated.14 A replacement applies to calls made after it:
- A layer keeps the style function
mapp.layer.featureStyle(layer)returned when its format was decorated. ReplacefeatureStylebefore the layers are added, or redecorate the layer. - Methods already called, eg.
mapp.Mapviewitself, stay as they were. - A plugin loads after
mapp.mjsandui.mjsand wins over their methods.
- A registry key is a workspace value: a plugin which adds
mapp.layer.themes.heatmakes"type": "heat"valid in every layer of the view. Choose names which core MAPP does not use and is unlikely to add. - Assigning a key which exists replaces the core method for every layer, location and view on the page.
- A module namespace throws on assignment in a module: replace the object instead of adding a key.
- A method added to
mapp.layerruns for every layer with a key of its name, like a layer plugin. - The workspace keys a plugin reads are not in the knowledge bundle. The strict schema rejects them in documented objects such as a layer; validate a workspace with plugin keys against the open schema, or document the keys where the schema is generated.
Footnotes
-
mapp.mjs ↩
-
ui.mjs ↩
-
layer/decorate.mjs: format check and the layer key loop ↩ ↩2
-
layer/format/vector.mjs load ↩
-
layer/featureStyle.mjs; format/mvt.mjs calls retain ↩
-
ui layers/drawLegend.mjs ↩
-
layer/featureFields.mjs process ↩
-
utils/olStyle.mjs ↩
-
ui locations/infoj.mjs ↩
-
ui layers/filters.mjs ↩
-
ui layers/view.mjs ↩
-
ui Dataview.mjs ↩
-
utils/compose.mjs ↩
-
mapview/_mapview.mjs mapviewPromise ↩