Quick start
The example below, running in the Mappia calculator - click it to run it live. Full-size picture
- Run it
Click the picture: the map opens right here and runs the example. Nothing is saved, and nothing to install.
- Try it
- Click Show a message: a notification appears with the layer’s name in bold.
- Make it yours
Copy the query, change it - the key parameters are below - and run it again in the playground, or paste it into the Mappia editor to save it as your map.
- More ways to use it
Key parameters
| Parameter | Example | What it does |
|---|---|---|
handler | sayHello | Function run on each click, with this = the layer. Looked up in functions, then among globals, then run as inline code. |
text | Show a message | The caption on the button. |
id | say_hello | Lets your code find the button: Ext.getCmp('say_hello') to hide, disable or relabel it. |
enableToggle | true | Makes a toggle button that stays pressed until clicked again; toggleHandler then runs on each change. |
toggleHandler | onDetails | Function run as (button, pressed) each time a toggle button changes state. |
pressed | true | Starts a toggle button pressed. |
Every parameter, with its type and default, is in the reference at the end of this page.
Complete example
The query 18 lines · runs as is
// Button: runs a function. A handler named by text is looked up in the layer's functions
// first, then among the globals; this = the layer.
[
{
title: "States",
name: "CSR:estados",
source: "calculate",
opacity: 0.6,
visibility: true,
paramsButtonConfig: [{ type: "query", pressed: true }],
descriptionHtml: "{{button|id=say_hello|text=Show a message|handler=sayHello}}",
functions: {
sayHello: function () {
ExtjsUtils.ALERTIFY.log("Hello from the layer <b>" + this.name + "</b>");
},
},
},
];More examples
Other ways to use Button, each a complete query that runs as is - like the one above.
Toggle another layer
A button that stays pressed shows a second layer of the map and hides it when released - here the state borders over a carbon map.
Click the picture to run it live. Full-size picture
The query 27 lines · runs as is
Customize it
Toggle buttons
With enableToggle=true the button stays pressed until clicked again, and toggleHandler receives the new state. If you give only handler, it is used as the toggle handler.
descriptionHtml:
"{{button|id=details|text=Details|enableToggle=true|pressed=true|toggleHandler=onDetails}}",
functions: {
onDetails: function (button, pressed) {
ExtjsUtils.ALERTIFY.log(pressed ? "Details on" : "Details off");
},
},
Change the calculation from a button
A button is not an input: a click does not recalculate the layer. To drive the calculation, store a value in an InputManager from the handler; setValues recalculates. To rerun the layer with the current inputs, call this.generateNewLegend(). this.getInputs() reads the other widgets of the layer.
Look and behaviour
Every other Ext JS 3.4 button option written in the markup is passed through, for example iconCls, tooltip, cls, width, disabled or scale. See the Ext.Button options. hidden=true creates it hidden; show it later with Ext.getCmp(id).show().
Notifications
ExtjsUtils.ALERTIFY.log(message, config) shows a short HTML message. Useful config keys: delay (milliseconds on screen), force: true (show it even when the user turned notifications off) and func (run when the message is clicked). Messages sent before the layers finish loading are held back, and only the last one is shown. See Notifications.
Pitfalls
- Write handlers as regular
functions, not arrow functions, orthisis not the layer. - A handler name that matches no function is run as code. A typo is not reported when the map opens; it fails on the first click.
- Keep code in
functions, not inline in the markup:|and=have a meaning in the markup and break inline code.