Key parameters
| Parameter | Example | What it does |
|---|---|---|
runOnClick | onRectangle | Name of a function in functions, called after the second click with (layersValues, inputs, bbox, pixel, lastInfo); this is the layer. |
text | Sum a rectangle (two clicks) | Label of the switch in the layer panel. |
id | rectangle_sum | Names the tool: inputs.id["rectangle_sum"] holds the sums of the last rectangle, one per map. |
notify | false | Hide the notification shown when the user switches the tool on. |
Every parameter, with its type and default, is in the reference at the end of this page.
Complete example
The query 23 lines · runs as is
// AreaIntegral: two clicks define a rectangle; the tool sums each map inside it using the
// summed-area ("integral") decoding, so the map must be published with that operation.
[
{
title: "Population density - rectangle sum",
name: "CSR:pop_density_estimate_2015",
styles: "1",
source: "calculate",
operation: "integral",
opacity: 0.7,
visibility: true,
paramsButtonConfig: [{ type: "query", pressed: true }],
descriptionHtml:
"{{areaintegral|id=rectangle_sum|text=Sum a rectangle (two clicks)|runOnClick=onRectangle}}",
functions: {
// bbox = [minLon, minLat, maxLon, maxLat] in EPSG:4326
onRectangle: function (layersValues, inputs, bbox) {
ExtjsUtils.ALERTIFY.log("Sum inside the rectangle: <b>" +
ExtjsUtils.NUMBER.abbreviateNumber(layersValues[0]) + "</b>");
},
},
},
];Customize it
The layer it needs
The tool does not add cells up one by one. It reads the map as a summed-area table, where each cell holds the total of everything above and to the left of it, so four reads at the corners give the sum of any rectangle, however large. That only works when the layer reads a map published with that table: operation: "integral" together with the map’s name and styles, exactly as in the example. Keep those three keys together. With an ordinary map the number means nothing, and with a map that does not offer the operation the layer stays empty and the console shows Operation integral is not defined for layer ....
What the callback receives
layersValues: one sum per map inname, in the same order.bbox: the rectangle as[minLon, minLat, maxLon, maxLat], in degrees.pixel: the{x, y}screen position of the second click.lastInfo:{first, second}, the two clicks as{lon, lat}in degrees.
this is the layer. Sums get large quickly; ExtjsUtils.NUMBER.abbreviateNumber(value) shortens them for display, as the example does.
Use the sums in the calculation
The tool keeps the last sums in inputs.id[ID], but it does not recalculate the layer by itself. When beforeCalc must see the new sums, call Ext.getCmp("rectangle_sum").items.get(0).forceUpdateLayer() at the end of your callback.
Pitfalls
- Both corners must fall on the map’s data. A corner outside it has no value to read, and no sum is reported.
- After the first click the tool shows a short notification (in Portuguese) asking for the second corner.
- The tool switches itself off after every rectangle;
unselectonly changes the message shown when it is switched on. - For a free shape instead of a rectangle, use SummedArea: the user draws a polygon.