Class: module:FeatureButton

module:FeatureButton()

new module:FeatureButton()

A button to act on a specific feature of a specific layer: open its popup or launch its edition, and optionally zoom to it. It can also launch the creation of a new feature in a layer.

Data attributes:

  • data-target-layer-id (required): the QGIS layer ID.
  • data-target-feature-id (required in popup and edit modes): the value of the primary key for the feature. It is also used as the WFS feature ID for zoom and edition. Ignored in create mode.
  • data-target-layer-pk-field (required in popup mode): the primary key field of the layer. It must be the primary key defined for the layer in QGIS, and a single-column key: composite keys and layers without a primary key are not supported.
  • data-mode (optional, default popup): popup to open the feature popup (popup must be enabled for the layer), edit to launch the feature edition (the layer must be editable by the current user, with modification allowed), create to launch the creation of a new feature (the layer must be editable by the current user, with creation allowed).
  • data-target-zoom-to-feature (optional, default false): true to zoom to the feature. Ignored in create mode.
  • data-label (optional): the button text. Defaults to a translated label depending on the mode.
  • data-description (optional): the button tooltip.

The button is disabled if the parameters are not valid; the reason is logged in the console.

Source:
Fires:
Examples

Open the popup of a feature and zoom to it

<lizmap-feature-button
     data-target-layer-id="layer_id"
     data-target-feature-id="42"
     data-target-layer-pk-field="id"
     data-target-zoom-to-feature="true"
     data-description="Open the popup for this feature">
</lizmap-feature-button>

Launch the edition of a feature

<lizmap-feature-button
     data-target-layer-id="layer_id"
     data-target-feature-id="42"
     data-target-layer-pk-field="id"
     data-mode="edit"
     data-label="Edit">
</lizmap-feature-button>

Launch the creation of a new feature

<lizmap-feature-button
     data-target-layer-id="layer_id"
     data-mode="create">
</lizmap-feature-button>

Extends

  • HTMLElement

Methods

_dispatch(type)

Notify listeners through the main event dispatcher

Parameters:
Name Type Description
type string

The event type

Source:
Fires:

_getFeatureGeometry() → {Promise.<(Geometry|null)>}

Get the feature geometry in the map projection

Source:
Returns:

The feature geometry, or null if it cannot be retrieved

Type
Promise.<(Geometry|null)>

_render()

Render the button, disabled if the parameters are not valid

Source:

_zoomTo(geometry) → {Promise.<void>}

Zoom to the geometry and wait for the view to reach its final position

Parameters:
Name Type Description
geometry Geometry

The geometry in the map projection

Source:
Returns:
Type
Promise.<void>

checkParameters() → {boolean}

Check the parameters depending on the mode:

  • common: the mode is known and the layer exists
  • popup and edit: the feature id is defined
  • popup: the primary key field is defined and the popup is enabled for the layer
  • edit: the layer is editable by the current user and its features can be modified
  • create: the layer is editable by the current user and features can be created
Source:
Returns:

True if the parameters are valid, false otherwise

Type
boolean

connectedCallback()

Read the data attributes, check them and render the button when the element is inserted into the DOM

Source:

(async) onClick() → {Promise.<void>}

Zoom to the feature if requested, then display its popup or launch its edition depending on the mode. The button is disabled while the request is running.

Source:
Returns:
Type
Promise.<void>

Events

featureButtonCreationLaunched

When the button action has been performed

Properties:
Name Type Description
type string

featurebutton.popup.displayed, featurebutton.edition.launched or featurebutton.creation.launched

layerId string

The target layer ID

featureId string

The target feature ID (undefined for featurebutton.creation.launched)

Source:
Example
lizMap.mainEventDispatcher.addListener((lizmapEvent) => {
        console.log(`Popup displayed for ${lizmapEvent.layerId} / ${lizmapEvent.featureId}`);
    },
    ['featurebutton.popup.displayed']
);