Notifications and choices

Quick start

The example below, running in the Mappia calculator - click it to run it live. Full-size picture

  1. Run it

    Click the picture: the map opens right here and runs the example. Nothing is saved, and nothing to install.

  2. Try it
    • Press Choose a region, then pick Northeast in the list: the dialog closes at once.
    • Watch the bottom right of the map: a notification says “You picked NE”.
  3. 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.

Key parameters

ParameterExampleWhat it does
confirmChoiceExtjsUtils.ALERTIFY.confirmChoice("Which region?", [{ label: "North", value: "N" }, "South"], onPick)Asks the user to choose. Your function receives (value, index, choice) for the picked option.
logExtjsUtils.ALERTIFY.log("Calculation finished", { delay: 6000 })Shows a short notification at the bottom right. It closes by itself after 4 seconds, or delay milliseconds.
alertExtjsUtils.ALERTIFY.alert("<b>No data</b> for the selected year.")Shows a message with an OK button. Your code keeps running while it is open.
isEnabledExtjsUtils.ALERTIFY.isEnabled()Tells whether the user still allows notifications. When false, log shows nothing unless you pass { force: true }.

Every parameter, with its type and default, is in the reference at the end of this page.

Complete example

The query 28 lines · runs as is
// Notifications and choices: log (a passing message), alert (non-blocking) and
// confirmChoice (a choice between labelled options).
[
  {
    title: "States",
    name: "CSR:estados",
    source: "calculate",
    opacity: 0.6,
    visibility: true,
    paramsButtonConfig: [{ type: "query", pressed: true }],
    descriptionHtml: "{{button|id=ask_user|text=Choose a region|handler=askRegion}}",
    functions: {
      askRegion: function () {
        ExtjsUtils.ALERTIFY.confirmChoice(
          "Which region should the map focus on?",
          [
            { label: "North", value: "N" },
            { label: "Northeast", value: "NE" },
            { label: "Southeast", value: "SE" },
          ],
          function (value) {
            ExtjsUtils.ALERTIFY.log("You picked " + value);
          }
        );
      },
    },
  },
];

Customize it

Choices: how many options, which dialog

choices is a list of strings, or of { label, value } objects. The dialog depends on how many you give:

ChoicesWhat the user sees
1No dialog: your function runs at once with that choice.
2Two buttons, one per choice. There is no Cancel.
3 or moreA list with OK and Cancel. Picking an option confirms it at once.

The list starts on the first option, so picking that one does not close the dialog: the user presses OK instead. The fourth argument, config, changes the rest:

ExtjsUtils.ALERTIFY.confirmChoice("Which year?", ["2000", "2010", "2020"], onYear, {
  autoConfirmOnSelect: false,          // wait for OK instead of closing on pick
  okLabel: "Apply",
  cancelLabel: "Not now",              // default: Cancel, in the page language
  onCancel: function () { ExtjsUtils.ALERTIFY.log("Nothing changed"); },
});

Notification options

log(message, config) takes HTML and these options:

OptionEffect
delayMilliseconds before the notification closes. Default 4000.
forceShow it even if the user turned notifications off.
onlyMsgShow the message alone, without the close button and the “stop notifications” box.
funcFunction called when the user clicks the notification.
spamTimeMilliseconds during which the same text is not shown again. Default 10000.

Pitfalls

  • Only one notification shows at a time. The same text logged again within 10 seconds is dropped.
  • Messages logged while the map is still loading wait until it has loaded, and then only the last one stays on screen.
  • Users can switch notifications off from the notification itself. toggle(true) switches them back on for this browser; use it sparingly.
  • alert and confirmChoice ignore that setting: they always show.

Real maps that use it

FIP Cerrado - Fire monitoring (current map)

Reference: the parameters used here

Generated from the platform source. Every entry, searchable, is in the API reference; the raw data is api.json. Open an entry for its description, parameters and example; # links to it.

ALERTIFY · messages and questions

Alertify5 entries
Messages, alerts and questions for the reader. Usage: ExtjsUtils.ALERTIFY
View the complete Alertify API here.

alert

function(msg)helper# Shows an user non blocking alert.

Written as ExtjsUtils.ALERTIFY.alert

Shows an user non blocking alert.

PS: If layer is loading only the last message will be shown after load end.

msg String
Notification HTML content.

confirmChoice

function(html, choices, onChoice, config)helper# Modal for one or more labeled choices.

Written as ExtjsUtils.ALERTIFY.confirmChoice

Modal for one or more labeled choices.

  • 1 choice: invokes callback immediately (no modal).
  • 2 choices: alertify.confirm with custom ok/cancel labels; both invoke onChoice.
  • 3+ choices: alertify.confirm with a <select>; OK confirms selection;
      Cancel invokes config.onCancel when provided. Selecting an option auto-clicks OK
      when config.autoConfirmOnSelect is not false (default true).
html String
Message HTML.
choices Array.<(String|{label:String, value: *})>
Option labels or {label,value} objects.
onChoice function
function(value, index, choice) for a picked option.
config Object
Optional: okLabel, cancelLabel, onCancel, autoConfirmOnSelect.

isEnabled

function() : Booleanhelper# Tells whether notifications (Alertify.log) are enabled for this browser, i.e. the user has not ticked "stop notifications" (stored under DISABLE_ALERT_NAME).

Written as ExtjsUtils.ALERTIFY.isEnabled

Tells whether notifications (Alertify.log) are enabled for this browser, i.e. the user has not ticked "stop notifications" (stored under DISABLE_ALERT_NAME).

Returns True when notifications are enabled, false when the user disabled them.

if (!ExtjsUtils.ALERTIFY.isEnabled()) ExtjsUtils.ALERTIFY.log("Important!", {force: true});

log

function(msg, config)helper# Shows an user notification (if enabled).

Written as ExtjsUtils.ALERTIFY.log

Shows an user notification (if enabled).

PS: The messages before layer loading are delayed, when it finishes only the last message will be shown.

msg String
The message that will be displayed in the alert. It can be in HTML format.
config Object
Configuration parameters for the message. { force: {Boolean} Force to show notification even when disabled. func: {Callback} Callback function when the notification is clicked. onlyMsg: {Boolean} True to only show message and hide the close and the stop notifications, False otherwise. delay: {Numeric} Amout of time in milisseconds before the message hide. spamTime: {Numeric} Time the same message to be shown again is considered spam. (even with force = true). }

toggle

function(state)helper# Enables or disables the notifications shown by Alertify.log for this browser (the setting is persisted with COOKIE).

Written as ExtjsUtils.ALERTIFY.toggle

Enables or disables the notifications shown by Alertify.log for this browser (the setting is persisted with COOKIE). Without an argument the current state is inverted. Messages logged with {force: true} are still shown when disabled.

state Boolean
True to enable, false to disable; omit to invert.
ExtjsUtils.ALERTIFY.toggle(false); // silence the platform notifications in this query