JavaScript
Create custom event handlers that add any functionality that you need.
More detailed technical API documentation is available here: JavaScript API
Use our new AI bot Mapy who is now always avialable on MapSVG control panel and ready to answer your code-related questions!
Middlewareβ
What is Middleware?β
It is a function that sits between two parts of a process and allows you to change or handle data before it continues. It acts like a "filter" or "checkpoint" for data, letting you modify or control what happens before it moves on to the next step.
For example, when you use the MapSVG plugin and data is being fetched from a server (like map Regions or Objects), a middleware function allows you to:
- Edit the data before it is displayed on the map
- Validate the data to make sure it's correct
- Log information for debugging
When MapSVG loads data, it goes through a series of steps. Middleware functions are called during these steps to give you control over how the data is handled.
Hereβs an example:
- Data Request: MapSVG requests data (like map Regions) from the server
- Middleware Function: The middleware function checks or modifies the data before it's used
- Data is Loaded: After the middleware, MapSVG loads the processed data onto the map
Consider checking if the map is being displayed in the WordPress admin area
(by verifying map.inBackend
). Typically, you don't want to run this middleware in the backend,
because if you modify the map options there and then click "Save", those modifications
will be saved as default options in the database.
Middleware parametersβ
Every middleware function has 2 parameters:
function(data, ctx){
// ...
data
: the data which is getting passed through middleware, the data you can modifyctx
: context, which may contain parameters such asrequest
,response
,map
, and others.