Web components
Principle
Lizmap Web Client provides some web components: custom HTML elements, like <lizmap-features-table>,
which are turned into interactive tools by Lizmap when they are displayed in the page.
Most of them are used internally by the Lizmap interface. This page only documents the components which are designed to be used in your own content:
lizmap-features-table: a compact list of features of a layer, with access to their popup,
lizmap-feature-button: a button to open the popup of a feature, to launch its edition, or to create a new feature.
They can be used:
in a popup, mainly a QGIS HTML Maptip popup, where QGIS expressions can be used to build the attributes values from the feature fields,
in your own JavaScript code, see Adding your own JavaScript, by creating the HTML element and adding it to the page.
Note
The popup content is sanitized before being displayed: only the HTML elements whose name begins with lizmap-
are kept, with the attributes documented below and the data-* attributes.
lizmap-features-table
Since Lizmap Web Client 3.9
Description
This component displays a compact table of the features of a vector layer, filtered with an expression.
The first column displays the display name of each feature, as configured in QGIS: .
Additional columns can be added with
<lizmap-field>child elements.If the popup is activated for the layer in the Lizmap plugin, a click on a line displays the feature popup below the table, with buttons to go to the previous or to the next feature, and to go back to the list.
Tip
In the Lizmap plugin, the option Display table of children (recommended) of a layer popup
automatically adds a lizmap-features-table for each child layer of the feature (see Popup).
You only need to write the element yourself to change its options or to display other features.
Attributes
Attribute |
Required |
Description |
|---|---|---|
|
Yes |
The QGIS layer ID. |
|
Yes |
The field containing a unique value for each feature, usually the primary key. |
|
No |
The title displayed above the table. |
|
No |
A QGIS expression to filter the features, for example |
|
No |
The field used to sort the features. It must be a field of the layer. |
|
No |
|
|
No |
Get the features geometries, needed to highlight them or to center the map on them. The geometries are fetched as soon as the attribute is present, whatever its value. |
|
No |
|
|
No |
|
|
No |
|
|
No |
The maximum number of features to display, |
|
No |
The message displayed when there is no feature to display. |
|
No |
The ID of the feature whose popup is displayed. Set it to display the popup of a feature, set it to an empty value to go back to the list. |
Additional fields
Each <lizmap-field> element adds a column to the table. Its content is a QGIS expression evaluated for each
feature: a field name between double quotes, or a simple expression.
data-alias: the column header. The expression is used if it is not set.data-description: the tooltip of the column header.
For security reasons, the functions which can be used in these expressions are limited to:
area, $area, display_expression, format_date, now, represent_value and round.
If another function is used, the column displays not allowed.
For other needs, create a virtual field in the layer and use it in the <lizmap-field> element.
Example in a popup
In the QGIS HTML Maptip of a districts layer, display the sub-districts of the clicked
district, sorted by name, with two additional columns:
<lizmap-features-table
layerId="sub_districts_24ceec66_e7fe_46a2_b57a_af5c50389649"
layerTitle="Sub-districts"
uniqueField="id"
expressionFilter="district_code = '[% code %]'"
sortingField="name"
sortingOrder="asc"
withGeometry="1"
data-show-highlighted-feature-geometry="true"
data-center-to-highlighted-feature-geometry="true"
>
<lizmap-field data-alias="Code" data-description="Sub-district code">"sub_code"</lizmap-field>
<lizmap-field data-alias="Area (m²)">round($area, 2)</lizmap-field>
</lizmap-features-table>
The QGIS expression [% code %] is replaced by QGIS Server with the value of the field code of the clicked
district, before the popup is sent to the browser.
Usage with JavaScript
The table is reloaded when:
its
expressionFilterattribute is changed,its
updatedattribute is changed, for example with the current time, to refresh the content.
const table = document.querySelector('lizmap-features-table');
// Display other features
table.setAttribute('expressionFilter', `"district_code" = 'MC'`);
// Refresh the content, for example after an edition
table.setAttribute('updated', Date.now());
// Display the popup of the feature 17
table.setAttribute('data-active-item-feature-id', '17');
The component sends some events with the Lizmap events dispatcher:
Event |
Properties |
|---|---|
|
|
|
|
|
|
lizMap.mainEventDispatcher.addListener(
(lizmapEvent) => {
console.log(`Feature ${lizmapEvent.itemFeatureId} of layer ${lizmapEvent.itemLayerId} displayed`);
},
['features.table.item.highlighted']
);