LegendHtml and OpacitySlider

Markup: {{legendhtml}}{{opacityslider}}

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
    • Drag the opacity slider to the left: the geology map fades and the base map shows through.
    • Click an entry in the legend: that class disappears from the map. Click it again to bring it back.
  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
filterLayers[0]For a layer with several maps in name, shows only the legends of these positions (0 is the first map).
reverseLegendtrueLists the legend entries in decreasing order.
preventClicktrueStops users from hiding a class by clicking its legend entry.
value50Starting opacity of the slider, in percent. Used only when the layer has no opacity of its own.
aggressivetrueChanges the opacity while the slider is being dragged, not only when it is released.
inversetrueMakes the slider set transparency instead of opacity: 100 means invisible.

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

Complete example

The query 13 lines · runs as is
// LegendHtml and OpacitySlider: the legend of the layer inside its panel, and a slider
// that controls the layer's opacity.
[
  {
    title: "Geology",
    name: "CSR:geologia",
    source: "calculate",
    opacity: 0.8,
    visibility: true,
    paramsButtonConfig: [{ type: "query", pressed: true }],
    descriptionHtml: "{{label|text=Opacity}}{{opacityslider}}{{legendhtml}}",
  },
];

Customize it

Where they go

Put both tags anywhere in descriptionHtml, in any order, next to your other widgets. Neither one is an input: they never start a recalculation and take no position in inputs. Without {{legendhtml}} the legend is still there, behind the layer’s legend button; the tag puts it right in the panel, where users see it while they work with your widgets.

Starting opacity

The slider starts at the layer’s own opacity (0 to 1). The example sets opacity: 0.8, so the slider starts at 80. The slider’s value counts only when the layer has no opacity. Limit the range with minValue and maxValue (in percent). Add changeVisibility=true to hide the layer when the slider reaches its minimum.

A title above the legend

Set legendTitle on the layer to show a line of text above {{legendhtml}}.

Your own legend entries

On a calculated layer with an expression, you can set the entries yourself in beforeCalc. {{legendhtml}} then shows your entries:

beforeCalc: function () {
  this.setCalculateLegend([
    { color: [0, 0, 255], value: 500, title: "Up to 500 m" },
    { color: [255, 0, 0], value: 3000, title: "Above 500 m" },
  ]);
},

Each value is the highest number that gets that color. Sort the entries by value, lowest first: entries out of order are ignored.

Pitfalls

  • Colors in setCalculateLegend are [R, G, B] arrays. A CSS string such as "#c0392b" breaks the legend with color.join is not a function.
  • filterLayers is a list, even for a single map: write filterLayers=[0], not filterLayers=0.
  • legendId is a parameter of {{legendhtml}}. Written on the layer, it does nothing.
  • complementaryLayer needs a layer object, so you cannot set it in the markup.

Real maps that use it

LegendHTML and OpacitySlider Simple Example

LegendHTML and OpacitySlider Simple Example

LegendHTML and OpacitySlider Simple Example

Amazon on focus - Deforestation and fires by land category

Amazon on focus - Deforestation and fires by la...

AMAZONES - Biodiversity

AMAZONES - Biodiversity

AMAZONES - Hydrologic services

AMAZONES - Hydrologic services

Map publishing customization

Map publishing customization

Panorama of Brazil's Forest Code

Panorama of Brazil's Forest Code

REDD Brazil - Deforestation, emissions and credits

REDD Brazil - Deforestation, emissions and credits

SimAmazoniaINFRA - Deforestation and CO2 scenarios

SimAmazoniaINFRA - Deforestation and CO2 scenarios

X-ray of the CAR - Forest Code balance per property

X-ray of the CAR - Forest Code balance per prop...

AreaCategorical and GetLegend.

AreaCategorical and GetLegend.

AreaIntegral and SummedArea

AreaIntegral and SummedArea

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.

legendhtml · legend of the calculated map

LegendHtml7 entries

Written in a layer's descriptionHtml as {{legendhtml|parameter=value|...}}

Create a tool with the map legends at any place of the query description.
Usage: '{{legendhtml}}'

autoWidth

Boolean= true# Set true (default) to let the legend panel take the width of its container; set false to give it a fixed width.

Set true (default) to let the legend panel take the width of its container; set false to give it a fixed width.

|autoWidth=false|width=250|

filterLayers

Array.<Number>= null# Defines an array of indexes of layers to be included in map legend (from 0 to quantity of layers).

Defines an array of indexes of layers to be included in map legend (from 0 to quantity of layers). If not defined, all layer legends are shown by default. Otherwise, only the listed indexes are included.

Ex: A composed layer with three maps: name: "CSR:estados,CSR:roads,CSR:municipalities", If 'filterLayers=[0,1]' is defined in the layer object only the legends of 'CSR:estatdos' and 'CSR:roads' are shown.

|filterLayers = [1,2]|

id

String# Defines the id of the legend panel component (Ext.getCmp(id)), e.g. to show()/hide() it or to find the legend entries inside it.

Defines the id of the legend panel component (Ext.getCmp(id)), e.g. to show()/hide() it or to find the legend entries inside it. Generated when omitted. Other GeoExt.WMSLegend/Ext.Panel configs (cls, style, hidden, useScaleParameter, autoWidth...) are passed through.

|id=main_legend|

legendId

String= null# Defines the legend container id.

Defines the legend container id. You can use this id to toggle each legend filter individually.

|legendId=WIDGET_OBJECT_ID|

preventClick

Boolean= false# Defines if the user can filter the maps categories by clicking on the legend.

Defines if the user can filter the maps categories by clicking on the legend. Set it true to ignore the legend click, false otherwise.

|preventClick = true|

reverseLegend

Boolean= false# Defines if it should sort the legend on the decreasing order.

Defines if it should sort the legend on the decreasing order. Set it true to use the decreasing order, false otherwise.

|reverseLegend = true|

useScaleParameter

Boolean= false# Set true to request a new legend image from the server whenever the map scale changes (GeoServer SCALE parameter), for styles that depend on the scale.

Set true to request a new legend image from the server whenever the map scale changes (GeoServer SCALE parameter), for styles that depend on the scale. Off by default: the legend is generated once and reused, which is faster and keeps the click-to-filter behaviour stable.

|useScaleParameter=true|

opacityslider · layer opacity

OpacitySlider8 entries

Written in a layer's descriptionHtml as {{opacityslider|parameter=value|...}}

Create a slider to change the map opacity.
Usage: '{{opacityslider}}'

aggressive

Boolean= false# Set true to apply the opacity while the thumb is being dragged instead of only when it is released.

Set true to apply the opacity while the thumb is being dragged instead of only when it is released.

|aggressive=true|

changeVisibility

Boolean= false# Set true to let the slider also control the layer visibility: the layer is hidden when the slider reaches minValue and shown again when it leaves it.

Set true to let the slider also control the layer visibility: the layer is hidden when the slider reaches minValue and shown again when it leaves it. The layer must be visible when the slider is created.

|changeVisibility=true|

complementaryLayer

OpenLayers.Layer# A second layer that is hidden when the slider reaches maxValue (GeoExt option to fade between two layers).

A second layer that is hidden when the slider reaches maxValue (GeoExt option to fade between two layers). GeoExt expects a layer object here, which the markup cannot express (a string is not resolved to a layer), so this option is only usable from code; documented for completeness.

id

String# Defines the id of the slider component (Ext.getCmp(id)), e.g. to read getValue() or to hide() it.

Defines the id of the slider component (Ext.getCmp(id)), e.g. to read getValue() or to hide() it. Generated when omitted. Every parameter of the tool is passed to GeoExt.LayerOpacitySlider / Ext.slider.SingleSlider unchanged (width, cls, vertical, hidden...).

|id=opacity|

inverse

Boolean= false# Set true to make the slider work with transparency instead of opacity (100 = fully transparent).

Set true to make the slider work with transparency instead of opacity (100 = fully transparent).

|inverse=true|

maxValue

Number= 100# Defines the maximum value of the slider (opacity percent at the right end).

Defines the maximum value of the slider (opacity percent at the right end).

|maxValue=90|

minValue

Number= 0# Defines the minimum value of the slider (opacity percent at the left end).

Defines the minimum value of the slider (opacity percent at the left end).

|minValue=10|

value

Number= 100# Defines the initial slider value (opacity in percent).

Defines the initial slider value (opacity in percent). It is only used when the layer has no opacity yet (opacity not set on the layer): otherwise the slider starts at the layer's current opacity.

|value=50|

QUERY · setup calls and the running query

QUERY1 entry
ExtjsUtils.QUERY: calls before the list (setQueryGlobalProperties, addRemoteWMSServer, decorate, setMappiaIoCallback) and changes to the running query from your functions (addLayer, removeLayer, postMessage).
View the complete Query API here.

setQueryGlobalProperties

function(globalProperties) : Booleanhelper# Defines globals for the query: every key of globalProperties becomes a window property (a value, an object or a function) that layer definitions, markup widgets (handler=, onMark=...) and …

Written as ExtjsUtils.QUERY.setQueryGlobalProperties

Defines globals for the query: every key of globalProperties becomes a window property (a value, an object or a function) that layer definitions, markup widgets (handler=, onMark=...) and other query code can reference by name. The names are recorded and the globals are deleted when another query loads. A key that already exists on window and was not created by the query is refused with "Global variable can't be redefined" in the console (the platform's own globals are protected; redefining one of the query's own keys is fine). runNow is the only key the platform itself invokes: right after the globals are registered QUERY.runNow is called once (see that entry). Chain it with && before the layer array so the globals exist when the layers are evaluated; QUERY_DESCRIPTION in the examples stands for that array.

globalProperties Object
Object whose keys become globals; each value may be a value, an object or a function.

Returns Always true, so the call can be chained with && QUERY_DESCRIPTION.

ExtjsUtils.QUERY.setQueryGlobalProperties({
  globalCount: 0,
  onLayerButton: function(btn) { console.log("clicked", btn); },
  runNow: function() { ExtjsUtils.ZOOM.limitZoomLevel(17); }
}) && [
  { name: "CSR:estados", visibility: true, descriptionHtml: "{{button|id=b1|text=Go|handler=onLayerButton}}" }
]

Layer callbacks: functions you write

LayersFunctions1 entry
Functions you write in a layer and the platform calls: expression, afterCalc and legendColor on calculated layers; beforeCalc, onInputsReady, onVisibilityChange and the functions map on calculated and file layers. Inside them this is the layer - except in expression, see Kinds of layer.

beforeCalc

function= nullcallback# This function is executed before any calculation is made in the 'expression()' function.

This function is executed before any calculation is made in the 'expression()' function. It runs on calculated layers (source: 'calculate'), even when there is no 'expression()', and on file layers (source: 'file'), where it runs again whenever an input changes or a resource finishes loading (see VectorLayer.generateNewLegend).

inputs Array
The value of each input defined in the descriptionHtml. The order of the values is the same as the inputs (i.e. the first input in the descriptionHtml is inputs[0], the second is inputs[1] and so on).
[
  {
     title: 'Example of beforeCalc function',
     color: '#FFA500',
     elements: [
        {
           title: 'This beforeCalc function will show a message at the bottom right of the screen',
           name: 'CSR:geologia',
           source: 'calculate',
           visibility: true,
           paramsButtonConfig: [
              {
                 type: 'query',
                 pressed: true
              },
           ],
           descriptionHtml:
              '{{label|text=The beforeCalc function will be called after every user interaction before any calculation}}'
              +
              '{{textfield|fieldLabel=Enter your name|id=textInput|labelStyle=text-align:center;}}',
           beforeCalc: function(inputs) {
              let inputValue = inputs[0];
              ExtjsUtils.ALERTIFY.log('Hello ' + inputValue + '!');
           },
        },
     ],
  },
]

Group properties

GroupProperties8 entries
Keys of a group object, written next to its elements: title or viewTitle, color, openGroup, defaultProperties...

color

String= string.emptyproperty# Defines the Color of the group.

Defines the Color of the group. This is the Color of the Title and some elements inside the sub menu on the top of the screen.

[
   {
      title: 'My orange group',
      color: '#FFA500',
   },
]

customLayerClass

String= string.emptyproperty# Extra CSS class added to the node of a viewTitle group in the Legend Window, so the group title and its rows can be styled with ExtjsUtils.CSS.defineClass or a stylesheet.

Extra CSS class added to the node of a viewTitle group in the Legend Window, so the group title and its rows can be styled with ExtjsUtils.CSS.defineClass or a stylesheet. Only groups with a viewTitle create a node; on a layer the same key styles the layer row instead (ConfigLayer.customLayerClass).

[
  {
     viewTitle: 'Styled group',
     viewColor: '#FFA500',
     title: 'Group 1',
     color: '#666699',
     customLayerClass: 'highlighted-group',
     elements: [
        {
           title: 'Layer 1',
           name: 'CSR:estados',
           source: 'local',
           startListed: true,
        },
     ],
  },
]

defaultProperties

Object= {}property# Specifies properties that apply universally to all layers within a group, including nested subgroups and their respective layers.

Specifies properties that apply universally to all layers within a group, including nested subgroups and their respective layers. Priority is determined by specificity: a property defined at the layer level takes precedence, followed by properties defined in the nearest group, and so forth.

[
  {
     title: 'Example of defaultProperties',
     color: '#FFA500',
     defaultProperties: {
        source: 'local',
        visibility: true,
        opacity: 0.7,
     },
     elements: [
        {
           title: 'Layer 1',
           name: 'CSR:geologia',
        },
        {
           title: 'Layer 2',
           name: 'CSR:rios_principais',
        },
        {
           title: 'Layer 3',
           name: 'CSR:estados',
           // Any internal redefinition will override the defaultProperties
           visibility: false,
        },
     ],
  },
]

elements

Array.<Layers>= Array.emptyproperty# Defines the Layers that will be part of the Group.

Defines the Layers that will be part of the Group. Each Layer can have multiple maps inside it. All maps inside a Layer will be shown together when that Layer is enabled. Besides that, all information about those maps can be used to calculate a new one using custom functions that can be writen in JavaScript.

[
  {
     title: 'A group with Layers!',
     color: '#FFA500',
     elements: [
        // Define your Layers here
     ],
  },
]

See also To learn more about Layers and it’s properties, check their documentation at: Layer Section.

global

Objectproperty# A second way to declare query globals: an object whose properties become temporary globals, passed to ExtjsUtils.QUERY.setQueryGlobalProperties while the group is interpreted (before its layers).

A second way to declare query globals: an object whose properties become temporary globals, passed to ExtjsUtils.QUERY.setQueryGlobalProperties while the group is interpreted (before its layers). The usual form is the ExtjsUtils.QUERY.setQueryGlobalProperties({...}) && [...] chain at the top of the query; the production survey found no query using this key (zero users).

[
  {
     title: 'Group with its own globals',
     global: {
        formatArea: function(value) { return ExtjsUtils.NUMBER.abbreviateNumber(value) + ' ha'; }
     },
     elements: [
        { title: 'Layer 1', name: 'CSR:estados', source: 'local', visibility: true }
     ]
  }
]

openGroup

Boolean= falseproperty# Defines if the 'viewTitle' should start opening or collapse.

Defines if the 'viewTitle' should start opening or collapse. Set it to 'true' for the 'viewTitle' start open or 'false' for it to start closed. This property only applies to a group that has the 'viewTitle' property defined. If the Group View has any visible Layers or any Layer has the 'openGroup' property set to 'true', the Group View will start open. It works at both levels: on the viewTitle group it makes the group start expanded, on a layer it expands every viewTitle ancestor of that layer.

[
  {
     viewTitle: 'This Group View will start opened',
     viewColor: '#FFFFFF',
     title: 'Group 1',
     color: '#666699',
     openGroup: true,
     elements: [
        {
           title: 'Layer 1',
           name: 'CSR:estados',
           source: 'calculate',
           startListed: true,
        },
     ],
  },
  {
     viewTitle: 'This Group View will start closed',
     viewColor: '#FFFFFF',
     title: 'Group 2',
     color: '#666699',
     elements: [
        {
           title: 'Layer 2',
           name: 'CSR:rios_principais',
           source: 'calculate',
           startListed: true,
        },
     ],
  },
]

title

String= string.emptyproperty# Defines the Title of the group.

Defines the Title of the group. The Title is shown at the sub menu on the top of the screen.

[
   {
     title: 'My new group!',
   },
]

viewTitle

String= string.emptyproperty# Define the Title of the View that will gather together the elements inside it (Groups or other Views).

Define the Title of the View that will gather together the elements inside it (Groups or other Views). If an external View has in its elements another definition of a 'viewTitle', subviews will be created, like in the second example.

// Exemple 1: View with a Layers inside it
[
  {
     viewTitle: 'This View has a Group 3 Layers',
     title: 'This is a Group with 3 Layers',
     color: '#5BA300',
     elements: [
        {
           title: 'Layer 1',
           name: 'CSR:estados',
           source: 'local',
           opacity: 0.5,
           visibility: true,
        },
        {
           title: 'Layer 2',
           name: 'CSR:rios_principais',
           source: 'local',
           opacity: 0.5,
           visibility: true,
        },
        {
           title: 'Layer 3',
           name: 'CSR:geologia',
           source: 'local',
           opacity: 0.65,
           visibility: true,
        },
     ],
  },
]
// Exemple 2: View with others 'viewTitle' defined inside it
[
  {
     // This is the definition of the View
     viewTitle: 'This External View has 2 others Inner Views inside it, each with 1 Group that has 1 Layer',
     title: 'This View has 2 Groups, each with 1 Layer',
     color: '#0073E6',
     elements: [
        {
           title: 'Group 1',
           // This 'viewTitle' will create a division in the menu that shows when the mouse hovers the navigation bar option 'This View has 2 Groups, each with 1 Layer' 
           viewTitle: 'Inner View with Group 1',
           color: '#E6308A',
           elements: [
              {
                 title: 'Group 1 - Layer 1',
                 name: 'CSR:altimetria',
                 source: 'local',
                 visibility: true,
              },
           ],
        },
        {
           title: 'Group 2',
           // This 'viewTitle' will create a division in the menu that shows when the mouse hovers the navigation bar option 'This View has 2 Groups, each with 1 Layer'
           viewTitle: 'Inner View with Group 2',
           color: '#B51963',
           elements: [
              {
                 title: 'Group 2 - Layer 1',
                 name: 'CSR:batimetria',
                 source: 'local',
                 visibility: true,
              },
           ],
        },
     ],
  },
]